关于无法从带INDEX格式的GIF图片创建Graphics的解决方案
2006-07-03 21:25
429 查看
有位网友询问这样一个问题:
Stream upImageStream = ImageUpload.InputStream;//上传文件流
System.Drawing.Image orgImg = System.Drawing.Image.FromStream(upImageStream);//通过文件流获取原始图片
Bitmap zoomImg = new Bitmap(orgImg.Width, orgImg.Height, orgImg.PixelFormat);//创建图片(位图)//Format32bppArgb
Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
在最后一句出现问题,老提示:A Graphics object cannot be created from an image that has an indexed pixel format.请问如何解决,谢谢!!
--------------------------------------------
产生这种错误的原因参见:
http://msdn2.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx中的相关说明。
Remarks
If the image has an indexed pixel format, this method throws an exception with the message, "A Graphics object cannot be created from an image that has an indexed pixel format." The indexed pixel formats are shown in the following list.
Format1bppIndexed
Format4bppIndexed
Format8bppIndexed
This method also throws an exception if the image has any of the following pixel formats.
Undefined
DontCare
Format16bppArgb1555
Format16bppGrayScale
解决方法:
你可以试试这样做:
Bitmap bm = new (Bitmap)Image.FromFile("YourFileName.gif");
Bitmap tmp = new Bitmap(bm.Width,bm.Height);
Graphics g = Graphics.FromImage(tmp);
g.DrawImage(bm, new Rectangle(0,0,tmp.Width,tmp.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixe
l);
g.DrawEllipse(Pens.Red,10,10,100,120); // 进行你的绘图操作
如果你想保存为新的图片格式,可以使用tmp.Save("你的文件名",你的格式参数)。
如果你想保存为原来的索引格式,你必须使用LockBits命令锁定Bitmap图片,然后进行你的图片绘制操作。
Stream upImageStream = ImageUpload.InputStream;//上传文件流
System.Drawing.Image orgImg = System.Drawing.Image.FromStream(upImageStream);//通过文件流获取原始图片
Bitmap zoomImg = new Bitmap(orgImg.Width, orgImg.Height, orgImg.PixelFormat);//创建图片(位图)//Format32bppArgb
Graphics myImg = Graphics.FromImage(zoomImg);//创建Graphics
在最后一句出现问题,老提示:A Graphics object cannot be created from an image that has an indexed pixel format.请问如何解决,谢谢!!
--------------------------------------------
产生这种错误的原因参见:
http://msdn2.microsoft.com/en-us/library/system.drawing.graphics.fromimage.aspx中的相关说明。
Remarks
If the image has an indexed pixel format, this method throws an exception with the message, "A Graphics object cannot be created from an image that has an indexed pixel format." The indexed pixel formats are shown in the following list.
Format1bppIndexed
Format4bppIndexed
Format8bppIndexed
This method also throws an exception if the image has any of the following pixel formats.
Undefined
DontCare
Format16bppArgb1555
Format16bppGrayScale
解决方法:
你可以试试这样做:
Bitmap bm = new (Bitmap)Image.FromFile("YourFileName.gif");
Bitmap tmp = new Bitmap(bm.Width,bm.Height);
Graphics g = Graphics.FromImage(tmp);
g.DrawImage(bm, new Rectangle(0,0,tmp.Width,tmp.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixe
l);
g.DrawEllipse(Pens.Red,10,10,100,120); // 进行你的绘图操作
如果你想保存为新的图片格式,可以使用tmp.Save("你的文件名",你的格式参数)。
如果你想保存为原来的索引格式,你必须使用LockBits命令锁定Bitmap图片,然后进行你的图片绘制操作。
相关文章推荐
- 给图片添加水印,解决GIF添加水印的问题(无法从带有索引像素格式的图像创建 Graphics 对象)
- 生成水印图片是出现这个问题!(无法从带有索引像素格式的图像创建 Graphics 对象。)
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- 关于SQL2008 “不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了‘阻止保存要求重新创建表的更改’” 解决方案
- [转] 关于ASP.NET中由于无法创建应用程序域,因此未能执行请求解决方案
- 关于SQL2008 “不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了‘阻止保存要求重新创建表的更改’” 解决方案
- (转载)无法从带有索引像素格式的图像创建graphics对象|A Graphics object cannot be created from an image that has an indexed pixel format
- 绘图操作时报错“无法从带有索引像素格式的图像创建 Graphics 对象”
- 关于无法加载已创建的布局文件的问题的解决方案以及已布局在对应的R文件中未生成相应ID的问题的解决
- 关于处理java从服务器读取图片然后上传替换后无法更新缓存的解决方案
- 关于出现错误:_tkinter.TclError: couldn't open "E:\Python系列\Python程序\Python安装.gif"tkinter中不能打开GIF格式图片的解决办法
- 无法从带有索引像素格式的图像创建graphics对象|A Graphics object cannot be created from an image that has an indexed pixel format
- 关于AE渲染高清GIF图片的解决方案
- 关于设置了LayoutAlgorithm.SINGLE_COLUMN后,某些手机的webview仍然无法适配图片的解决方案
- 无法从带有索引像素格式的图像创建graphics对象(转)
- 【已解决】关于SQL2008 “不允许保存更改。您所做的更改要求删除并重新创建以下表。您对无法重新创建的标进行了更改或者启用了‘阻止保存要求重新创建表的更改’” 解决方案
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象