![](/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.