Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改资源中的默认图像_C#_Image_Resources_Default - Fatal编程技术网

C# 更改资源中的默认图像

C# 更改资源中的默认图像,c#,image,resources,default,C#,Image,Resources,Default,我有这样的编辑表单的代码 if (image == "" ) { pictureBoxImage.Image = Properties.Resources.noimage; } else{ pictureBoxImage.ImageLocation = Path.Combine(Global.myPictureLocation, image); pictureBoxImage.BringToFront(); } if (image == Properties.Resource

我有这样的编辑表单的代码

if (image == "" ) {
   pictureBoxImage.Image = Properties.Resources.noimage;
}
else{
   pictureBoxImage.ImageLocation = Path.Combine(Global.myPictureLocation, image);
   pictureBoxImage.BringToFront();
}
if (image == Properties.Resources.noimage ) {
   pictureBoxImage.Image = Properties.Resources.noimage;
}
else{
   pictureBoxImage.ImageLocation = Path.Combine(Global.myPictureLocation, image);
   pictureBoxImage.BringToFront();
}
在我从资源文件夹设置默认图像之前,这一切都很正常。若我从资源文件夹中设置了图像,但并没有浏览图像,那个么代码会出错。。。。 我试着这样修改它

if (image == "" ) {
   pictureBoxImage.Image = Properties.Resources.noimage;
}
else{
   pictureBoxImage.ImageLocation = Path.Combine(Global.myPictureLocation, image);
   pictureBoxImage.BringToFront();
}
if (image == Properties.Resources.noimage ) {
   pictureBoxImage.Image = Properties.Resources.noimage;
}
else{
   pictureBoxImage.ImageLocation = Path.Combine(Global.myPictureLocation, image);
   pictureBoxImage.BringToFront();
}
但这是错误的

运算符“==”不能应用于“string”和“System.Drawing.Bitmap”类型的操作数

如何正确地检测它是否是来自资源的图像

图像是一个字符串,您无法将其与图像文件进行比较

你可以试试类似的东西

if (Image.FromFile(image) == Properties.Resources.noimage))
或者更好

if (Image.Equals(Image.FromFile(image), Properties.Resources.noimage))

@user3184196您可以将图像文件本身进行比较,也可以使用图像标记SI get error此路径与第一个和第二个代码不合法,…我不知道为什么已经解决了它…只需要分配图像=;然后一切如我所愿…谢谢你的帮助,这激励了我