从文件夹获取图像 [英] Get image from Folder
问题描述
我只想通过提供Folder路径就可以从Folder中检索任何一张图像.
我该怎么办?
I would like to retrieve any one image from Folder, just by giving the Folder path.
How can I do it?
推荐答案
根据您对JSOP的回答的评论:try
Based on your comment to JSOP''s answer: try
string[] filenames = Directory.GetFiles(path);
Image image = Image.FromFile(filenames[0]);
您可能需要先对返回的列表进行排序,因为获取文件的顺序是不确定的,或者是以复杂的方式定义的,这基本上意味着您不能依赖明智的顺序.
You might want to sort the returned list first, as the order in which you get files is either undefined or defined in a complicated way that basically means you can''t rely on a sensible order.
string[] files = Directory.GetFiles(folderPath, "*.jpg", SearchOption.AllDirectories);
string[] files = Directory.GetFiles(@"D:\LeadImage\Pending\", "*.jpg", SearchOption.AllDirectories);
您的情况下,您正在寻找文件夹中的文件
''C:\ Program Files \ Common Files \ Microsoft Shared \ DevServer \ 10.0 \ LeadImage \ Pending''
是吗?
您可以在字符串行之前使用符号@.这为您提供了像
这样的字符串
in your case you are looking for files in folder
''C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\LeadImage\Pending''
Is it right?
and you can use symbol @ before string row. This provide you string like
"D:\sdfs\sdfsd"
您还可以检查当前文件夹是否存在:
also you can check does current folder Exist:
if (Directory.Exist(@"d:\Myimage\"))
{
}
这篇关于从文件夹获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!