如何使用c#将图像加载到图像对象

如何使用c#将图像加载到图像对象

问题描述:

这是我的代码无法正常工作,找不到显示文件,任何人都可以帮助我



This is my code its not working, its showing file not found any one can help me please

string myImagePath = @&quoTempImage\TempImage.jpg";
           TempImage = Image.FromFile(myImagePath);
           pictureBox2.Image = TempImage;

好尝试使用完整路径。如果那个工作,你的可执行文件运行在这个相对路径对文件无效的地方。请注意你的代码被编译为 bin\debug bin \ release
Well, try with full path. If that one works, your executable runs somewhere where this relative path is not valid to the file. Be aware that your code is compiled to bin\debug or bin\release.


您是否正确使用了代码。

以下代码有语法错误。

string myImagePath = @& quoTempImage\TempImage.jpg;

如果你想使用相对路径,你需要将图像添加到项目解决方案中。

以下是在Pi中加载图像的代码cture Box。

Have you past code properly.
Following code have syntax error.
string myImagePath = @&quoTempImage\TempImage.jpg";
If you want to use relative path you need to add image in to you project solution.
Following is the code to load image in Picture Box.
var image = Image.FromFile(realtiveImagePath);
          pictureBox1.Image = image;