C#中的PNG图像问题
在Visual Studio 2008中工作.我正在尝试绘制PNG图像并再次保存该图像.
我做了以下事情: private Image img = Image.FromFile("file.png"); private Graphics newGraphics; 在构造函数中: newGraphics = Graphics.FromImage(img); 构建解决方案不会产生错误.当我尝试运行它时,我得到了这个:
我在C#中使用图像的经验不多.这是什么意思,我该如何解决这个问题? 编辑:通过调试,Visual Studio告诉我该图像具有format8bppindexed Pixel Format. 所以如果我不能使用Graphics类,我该怎么用? 编辑2:阅读this之后,我认为可以安全地假设我在使用GDI时更好地坚持使用JPG文件,不是吗? EDIT3:我的使用陈述: using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; 解决方法
如果没有更好的支持索引PNG的PNG库,那么你试图绘制到该图像是不合时宜的,因为显然GDI图形对象不支持索引图像.
如果您不需要使用索引的PNG,则可以捕获该错误并使用第三方实用程序将输入转换为常规RGB PNG. 编辑: 我确实找到了这个链接http://fci-h.blogspot.com/2008/02/c-indexed-pixel-problem.html,它提供了一种方法来绘制你的图像,但它不会影响原始,只是你可以保存()如果你需要. 如果链接断开: Bitmap bm = (Bitmap) System.Drawing.Image.FromFile("Fci-h.jpg",true); Bitmap tmp=new Bitmap (bm.Width,bm.Height ); Graphics grPhoto = Graphics.FromImage(tmp); grPhoto.DrawImage(bm,new Rectangle(0,tmp.Width,tmp.Height ),tmp.Height,GraphicsUnit.Pixel); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |