将32位bmp转换为24位(Converting 32 bit bmp to 24 bit)
我有一个System.Drawing.Image截图文件。 我把它转换为bmp,但问题是它产生32位bmp,而我需要一个24位bmp。 如何将其转换为24?
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?
原文:https://stackoverflow.com/questions/12572352
更新时间:2019-09-17 16:23
最满意答案
试试这段代码:
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;
}
try this code:
public static Bitmap ConvertTo24bpp(Image img) {
var bmp = new Bitmap(img.Width, img.Height, System.Drawi