Possible Duplicate:
Convert a image to a monochrome byte array
I have a monochrome bitmap image. I load the image like this:
Image image = Image.FromFile("myMonoChromeImage.bmp");
How can I get a binary array, where 1s represent white pixels and 0s represent black pixels, or vice versa? (The first bit in the array is the top-left pixel and the last bit in array is the bottom-right pixel)
If possible, an efficient approach would be appreciated.
You can use LockBits to get access to the bitmap data and copy the values directly from the bitmap array. GetPixel essentially locks and unlocks the bitmap each time so it’s not efficient.
You can extract the data to a byte array and then check the RGBA values to see if they are white (255,255,255,255) or black (0,0,0,255)
The BitmapData class sample shows how to do this. In your case the code would be something like this: