绘图操作时报错“无法从带有索引像素格式的图像创建 Graphics 对象”
来源:互联网 发布:网易闪电邮 for mac 编辑:程序博客网 时间:2024/06/05 22:32
如下代码会出现“无法从带有索引像素格式的图像创建 Graphics 对象”异常
Bitmap bitmap = new Bitmap(fileName);
Graphics graphics = Graphics.FromImage(bitmap);
解决方法为DrawImage到一个空的图片。
OpenFileDialog dialog = new OpenFileDialog { Filter = "Image|*.bmp;*.png;*.jpg;*.jpeg", FilterIndex = 1 }; if (dialog.ShowDialog() == DialogResult.OK) { string fileName = dialog.FileName; Bitmap bitmap = new Bitmap(dialog.FileName); Bitmap image = new Bitmap(bitmap.Width, bitmap.Height);// 将原图片DrawImage到新图片image,然后在image上进行绘图操作 using (Graphics graphics = Graphics.FromImage(image)) { Rectangle destRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); Rectangle srcRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height); graphics.DrawImage(bitmap, destRect, srcRect, GraphicsUnit.Pixel); graphics.Dispose(); } Graphics graphicsNew = Graphics.FromImage(image); Pen pen = new Pen(Color.Red); graphicsNew.DrawRectangle(pen, 0, 0, image.Width - 3,image.Height - 3);// 在图片上绘制矩形框 this.pictureBox1.Image = image; }
阅读全文
0 0
- 绘图操作时报错“无法从带有索引像素格式的图像创建 Graphics 对象”
- 无法从带有索引像素格式的图像创建 Graphics 对象
- 无法从带有索引像素格式的图像创建 Graphics 对象。
- "无法从带有索引像素格式的图像创建graphics对象"
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- Bitmap添加水印提示【无法从带有索引像素格式的图像创建Graphics对象】
- 无法从带有索引像素格式的图像创建graphics对象
- 无法从带有索引像素格式的图像创建graphics对象
- .net下灰度模式图像在创建Graphics时出现:无法从带有索引像素格式的图像创建graphics对象 问题的解决方案。
- Graphics 不能建立有索引像素格式的对象
- Android游戏Graphics绘图之图像像素操作
- Android游戏Graphics绘图之图像像素操作
- 关于无法从带INDEX格式的GIF图片创建Graphics的解决方案
- c#_具有索引像素格式的图像不支持 SetPixel
- System.Drawing.Graphics读取带有索引的图片及思考
- 图像的像素点操作
- https流程
- HTML5 autofocus属性
- The requested URL /api/v1 was not found on this server
- 类成员函数和函数返回值的结合使用探究
- 优于AAC的音频编码格式opus
- 绘图操作时报错“无法从带有索引像素格式的图像创建 Graphics 对象”
- C语言作业题(1)
- VB基礎
- Linux执行可执行文件提示No such file or directory
- PHP 结合 apidoc生成文档树
- Spring数据源配置
- Python strip()方法:移除头尾字符
- Android ListView与RecyclerView对比浅析--缓存机制
- GT--记录android app消耗的cpu/内存/流量 /电量