将32位bmp转换为24位 [英] Converting 32 bit bmp to 24 bit
本文介绍了将32位bmp转换为24位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个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?
推荐答案
试用此代码:
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;
}
这篇关于将32位bmp转换为24位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文