0

I need to get the byte array from my ColorConvertedBitmap representing the bitmap. I was trying to use CopyPixels method but with no success.

How to complete this task and what is the best approach?

Thank you in advance for the replies and hints!

Timwi
  • 65,159
  • 33
  • 165
  • 230
Jamie
  • 1,092
  • 3
  • 22
  • 44
  • possible duplicate of [How to manipulate images at pixel level in C#?](http://stackoverflow.com/questions/190385/how-to-manipulate-images-at-pixel-level-in-c) – Adrian Grigore Aug 28 '10 at 12:56
  • Not a duplicate of that at all. – Timwi Aug 28 '10 at 14:10
  • What do you need it for? Are you sure you want a byte array of the raw data and not an array of Colors, representing the pixels? –  Aug 28 '10 at 14:10
  • since you specified the class and method you were using, please 1) show the code you were using and 2) give more details than 'with no success' - does it throw an exception? not give you what you were looking for? (and if so, what are you looking for). Please be more detailed so we can better help you :) – James Manning Aug 28 '10 at 16:13

1 Answers1

1
public static byte[] BitmapToBytes(ColorConvertedBitmap ccb)
{
    byte[] bytes = new byte[ccb.PixelWidth * ccb.PixelHeight * ccb.Format.BitsPerPixel / 8];
    ccb.CopyPixels(bytes, ccb.PixelWidth * ccb.Format.BitsPerPixel / 8, 0);
    return bytes;
}
Timwi
  • 65,159
  • 33
  • 165
  • 230