Jamie
Jamie

Reputation: 1092

Convert ColorConvertedBitmap to byte array in C#

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!

Upvotes: 0

Views: 786

Answers (1)

Timwi
Timwi

Reputation: 66573

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;
}

Upvotes: 1

Related Questions