在 C# 中使用 Bitmap.ConvertFormat(PixelFormat 从 24 位到 16 位 RGB55



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

  • AForge.NET
  • 免费图片
  • http://www.codeproject.com/Articles/66341/A-Simple-Yet-Quite-Powerful-Palette-Quantizer-in-C

他们都工作得很差。http://msdn.microsoft.com/en-us/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(一个优秀的图像处理库),你可以选择一个简单的解决方案,但这是你的决定。

链接

  • 系统.绘图.成像
  • 系统.绘图.成像.像素格式
  • 将 24 位 bmp 转换为 16 位(解决方案采用自)

最新更新