Use Bitmap.ConvertFormat in C# (PixelFormat from 24 bits to 16 bits RGB555 with dithering)

3.1k views Asked by At

Any easy way? I am trying to convert the PixelFormat from 24 bits image to 16 bits RGB555 with dithering (for a portable device). I tested already a lot of approaches:

They all work poorly. http://msdn.microsoft.com/en-us/library/windows/desktop/ms536306(v=vs.85).aspx

I found a GDI+ wrapper, but this function is missing.

Thanks!

1

There are 1 answers

3
DayTimeCoder On

You can convert the image by using Bitmap class in the constructor pass the parameters for the conversion format and it will render the image with the PixelFormat you have mentioned.

Some code:

    public static Bitmap ConvertTo16bpp(Image img) {
    //you can also use Image.FromFile(fileName);//fileName can be absolute path of the image.
    var bmp = new Bitmap(img.Width, img.Height,System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
    using (var gr = Graphics.FromImage(bmp))
    gr.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
    return bmp;
   }

Suggestions

If you have some simple requirements you would not probably need AForge.NET (An excellent library for image processing) and you may go with a simple solution,but that's your decision to make.

Links