I have an HTML5 canvas element which I would like to save to the server as a monochrome bmp. I have seen examples online of saving it as a color bmp, but because of size and colorspace restrictions my application has I need it to be a small monochrome bmp. Does anyone know of a simple solution for this (or am I going to have to write a class to create a bmp file from scratch?)
Share
I found a good solution by working off of this example code: rephrase.net/box/bitmap The author helped me implement a function that could turn a pixel array into a monochrome bitmap. From there I was able to take canvas data and iterate through it and parse it into a pixel array that I could convert into a monochrome bmp.
I created this function to facilitate converting canvas data based on alpha values (since the canvas data is also monochrome in my application) to a pixel array which can be used by the jsbmp script:
And here is the code for bmp_mono: