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!

4
  • possible duplicate of How to manipulate images at pixel level in C#? Commented Aug 28, 2010 at 12:56
  • Not a duplicate of that at all. Commented Aug 28, 2010 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? Commented Aug 28, 2010 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 :) Commented Aug 28, 2010 at 16:13

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.