melculetz
melculetz

Reputation: 1971

How can I convert a 24-bit image to a 16-bit rgb565 bitmap?

I have an application in which the user usually loads 24-bit bitmaps. I need to save the images in a 16-bit rgb565 format. How can I do that in C#?

Upvotes: 2

Views: 5231

Answers (1)

dumbledad
dumbledad

Reputation: 17527

The thread on go4answers does not include authors details on each answer and it is identical to an MSDN forum thread so I suspect that it is a blatant copy of this MSDN thread: 24 bit bmp to rGB565 file conversion. The MSDN thread also has more answers and more discussion, so I'd use it in preference to the go4answers one Liviu M recommends in his answer. I have no idea why Google prefers the go4answers copy over the MSDN original, hopefully that'll change.

Just to summarise a few of the points covered in the MSDN thread.

  1. Try the FormatConvertedBitmap class. It uses the PixelFormats class to specify the format of the resulting conversion. One of the predefined pixel formats defined by the PixelFormats class is BGR565
  2. You'll notice that "BGR" != "RGB" and the thread includes discussion of the swapped colors. So another answer there recommends the classic System.Drawing.Imaging namespace and its PixelFormat enumeration which includes the member Format16bppRgb565

The discussion of the red/blue swap is fairly lengthy (useful bug, by design, problem, not a problem, ...) and seems to reach the conclusion that PixelFormats.Bgr565 is in fact in RGB565.

Upvotes: 3

Related Questions