将32位bmp转换为24位

问题描述 投票:4回答:2

我有一个System.Drawing.Image屏幕快照文件。我将其转换为bmp,但问题是它制作了32位的bmp,​​而我需要24位的bmp。如何将其转换为24?

c# .net image bmp
2个回答
10
投票

尝试此代码:

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

0
投票

答案是thx,但我该如何使用代码?

© www.soinside.com 2019 - 2024. All rights reserved.