从C#中的图片框中的项目文件夹加载图像 [英] Load images from project folder in picturebox in C#

查看:364
本文介绍了从C#中的图片框中的项目文件夹加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用此代码时,它会在图片框中加载图片:

 pictureBox1.Image = Image.FromFile( @  C:\ Users \ Admin \ source \ _repos \New folder \ TE \ SOFTware of TE \Images \的软件 + str); 



但是当我使用此代码时图片加载成功:

 pictureBox1 .Image = Image.FromFile( @  C:/ Users / Admin / source / repos / TE / Software of Software of TE / images / Washer.Jpg); 



所以请给我解决方案来加载文件夹中的所有图像。



我尝试了什么:



当我使用此代码时,它会在图片框中加载图像:

 pictureBox1.Image = Image.FromFile( @  C :\Users\Admin\source\repos\新文件夹\ TE TE软件软件\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ :

 pictureBox1.Image = Image.FromFile( @  C:/ Users / Admin / source / repos / TE软件/ TE / images / Washer.Jpg软件); 



所以请给加载来自文件夹的所有图像的解决方案。

解决方案

使用调试器:查看变量 str 并检查它是否包含文本Washer.Jpg - 如果没有,或者它包含额外信息,那么您需要找出原因。如果是,请检查您是否可以访问文件usigmn Windows资源管理器。



然后尝试以两种不同的方式组装路径:

  string  path1 =  @  C:\ Users \Admin \ source \ times \ new文件夹\ TE \ SOFTware of TE \Images \ + str 
string path2 = Path.Combine( @ C:\ Users \ Admin \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\每个字符串的确切内容并注意任何差异。


It faild to load image in picturebox when i m using this code:

pictureBox1.Image = Image.FromFile(@"C:\Users\Admin\source\repos\New folder\Software of TE\Software of TE\Images\"+ str);


But When i m using this code Image load Successfully:

pictureBox1.Image = Image.FromFile(@"C: /Users/Admin/source/repos/Software of TE/Software of TE/images/Washer.Jpg");


So please give me the solution to load all images from folder.

What I have tried:

It faild to load image in picturebox when i m using this code:

pictureBox1.Image = Image.FromFile(@"C:\Users\Admin\source\repos\New folder\Software of TE\Software of TE\Images\"+ str);


But When i m using this code Image load Successfully:

pictureBox1.Image = Image.FromFile(@"C: /Users/Admin/source/repos/Software of TE/Software of TE/images/Washer.Jpg");


So please give me the solution to load all images from folder.

解决方案

Use the debugger: look at exactly what is in the variable str and check that it contains the text "Washer.Jpg" - if it doesn't, or it contains extra information then you need to find out why. If it does, then check that you can access the file usigmn Windows Explorer.

Then try assembling the path in two different ways:

string path1 = @"C:\Users\Admin\source\repos\New folder\Software of TE\Software of TE\Images\"+ str
string path2 = Path.Combine(@"C:\Users\Admin\source\repos\New folder\Software of TE\Software of TE\Images\", str);

Again, use the debugger to look at the exact contents of each string and note any differences.


这篇关于从C#中的图片框中的项目文件夹加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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