不能键入“System.Drawing.Image对象'隐式转换为”System.Drawing.Bitmap'` [英] Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'`

查看:1618
本文介绍了不能键入“System.Drawing.Image对象'隐式转换为”System.Drawing.Bitmap'`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

宣布为位图这是

 私人位图IMG1 = NULL;
私人位图IMG2 = NULL;
 

图片将从打开文件对话框选择它后推。
选定的图像被放置在阵列中。

  imgName = openFD.FileNames;
 

然后Button1以显示这些图像。

  pictureBox1.Image = Image.FromFile(imgName [0]);
pictureBox2.Image = Image.FromFile(imgName [1]);
 

我取代了按钮1 code本

  IMG1 = Image.FromFile(imgName [0]);
IMG2 = Image.FromFile(imgName [1]);
 

但出现错误

  

无法隐式转换类型为System.Drawing.Image'到'System.Drawing.Bitmap

我会想办法改变code到 IMG1 = Bitmap.FromFile(imgName [0]); 。但仍然有同样的错误。
任何建议如何纠正或做到这一点吧?

解决方案

  IMG1 =新位图(imgName [0]);
IMG2 =新位图(imgName [1]);
 

Declared a bitmap which was

private Bitmap img1 = null;  
private Bitmap img2 = null;  

the image will be putted after selecting it from openFileDialog.
the selected images were placed in an array.

imgName = openFD.FileNames;

then button1 to display these image.

pictureBox1.Image = Image.FromFile(imgName[0]);  
pictureBox2.Image = Image.FromFile(imgName[1]);

i replaced the button1 code with this

img1 = Image.FromFile(imgName[0]);  
img2 = Image.FromFile(imgName[1]);

but an error occurs

Cannot implicitly convert type 'System.Drawing.Image' to 'System.Drawing.Bitmap'

I'd try to change the code to img1 = Bitmap.FromFile(imgName[0]);. but still has the same error.
Any suggestion how to correct or do this right?

解决方案

img1 = new Bitmap(imgName[0]);
img2 = new Bitmap(imgName[1]);

这篇关于不能键入“System.Drawing.Image对象'隐式转换为”System.Drawing.Bitmap'`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆