繁体   English   中英

在C#中使用Bitmap.ConvertFormat(带有抖动的PixelFormat从24位变为16位RGB555)

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

有什么简单的方法吗? 我正在尝试通过抖动(对于便携式设备)将PixelFormat从24位图像转换为16位RGB555。 我已经测试了很多方法:

他们都工作不好。 http://msdn.microsoft.com/zh-CN/library/windows/desktop/ms536306(v=vs.85).aspx

我找到了一个GDI +包装器,但是缺少此功能。

谢谢!

您可以通过在构造函数中使用Bitmap类来传递图像,并传递转​​换格式的参数,它将使用您提到的PixelFormat呈现图像。

一些代码:

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

意见建议

如果您有一些简单的要求,则可能不需要AForge.NET(一个出色的图像处理库),并且可以选择一个简单的解决方案,但这是您的决定。

链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM