Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting 32 bit bmp to 24 bit

Tags:

c#

.net

image

bmp

I have a System.Drawing.Image screenshot file. I cast it to bmp, but the problem is that it makes a 32 bit bmp, while I need a 24 bit one. How can I convert it to 24?

like image 668
Tyler Durden Avatar asked Sep 24 '12 20:09

Tyler Durden


1 Answers

try this code:

public static Bitmap ConvertTo24bpp(Image img) {
  var bmp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
  using (var gr = Graphics.FromImage(bmp))
    gr.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height));
  return bmp;
}
like image 96
MUG4N Avatar answered Nov 10 '22 10:11

MUG4N