![](/img/trans.png)
[英]How to convert pixel formats? From 32bppRGB to 16bpp grayscale in C#
[英]Convert bitmap from 16bpp to 8bpp in C#
我有一个16bpp的位图。 我想将图像转换为8bpp图像的ASP.NET端。
我尝试了很多在Internet上找到的选项,但对我没有任何帮助。
我也尝试过这种方式: C#将32bpp图像转换为8bpp
但是,如果要保存文件,则会出现以下错误:
异常详细信息:System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误。
Line 278: System.Drawing.Image img2 = Convert(bm_resize);//byteArrayToImage(gray);
Line 279:
Line 280: img2.Save(helper+"grey2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Line 281: }
Line 282:
有什么正确的方法可以解决我的问题吗?
完整代码:
System.Drawing.Image img2 = Convert(bm_resize);
img2.Save(path+"test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
public static System.Drawing.Image Convert(Bitmap oldbmp)
{
using (MemoryStream ms = new MemoryStream())
{
oldbmp.Save(ms, ImageFormat.Gif);
ms.Position = 0;
return System.Drawing.Image.FromStream(ms);
}
}
我使用一些辅助功能在.NET中创建1 bpp单色位图。 看看这个链接,它也非常适合8 bpp
http://www.wischik.com/lu/programmer/1bpp.html
希望这会有所帮助!
AForge.Net拥有大量免费的例程(根据Lesser GPL License),可以进行此类更改以及更多其他更改。 16bpp到8bpp的转换就这么简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.