Directory.GetAllImageFiles 我应该怎么做?
我想用目录中找到的所有图像填充一个字符串数组。
到目前为止,我使用以下方法获取所有 jpg 格式的图像
Dim List() as string = Directory.GetFiles(Path, "*.jpg")
现在我想扩展它并获取所有图像格式。
我可以将directory.GetFiles 与“ImageFormat
枚举”结合使用吗?
I would like to get fill a String array with all the images found within a directory.
Till now i use the following to get all the images with jpg format
Dim List() as string = Directory.GetFiles(Path, "*.jpg")
Now i would like to extend it and get all the image formats.
Could i use the directory.GetFiles combined with an "ImageFormat
enumeration"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您好,您可以使用我在 http://msdn.microsoft 找到的社区内容.com/en-us/library/wz42302f.aspx.:
使用延迟计算的替代方案(仅限.Net 4.0):
您可以像
GetFiles("dir", "*.jpg| *.gif|*.jpeg|*.bmp|*.png")
。它本质上只是对每个过滤器的搜索,因此它没有尽可能高效。最终版本是(仅限.Net 4.0,但至少可以制成2.0解决方案):
我相信最后一个版本是最快的,因为它只循环一次。但这取决于
Directory
中模式搜索的实现方式以及操作系统的搜索方式。需要进行性能测试,但我还没有做过。Hi you can use this which I found as community content at http://msdn.microsoft.com/en-us/library/wz42302f.aspx.:
an alternative which uses lazy evaluation (.Net 4.0 only):
You can use it like
GetFiles("dir", "*.jpg|*.gif|*.jpeg|*.bmp|*.png")
. It is essentially just a search for each filter, so it is not as efficient as it can get.A final version is (is .Net 4.0 only, but can be made to a 2.0 solution at least):
I believe the last one is the fastest because it only loops once. But this depends on how the pattern search is implemented in
Directory
and how the OS searches. A performance test is needed which I haven't done.这是 2.0 .net 解决方案。
我在 C# 中做了类似的事情。该解决方案使用文件夹作为要处理的图像的下落点。在所有情况下,将每种类型的文件作为图像加载并不是正确的解决方案,但我想将每个文件验证为可加载图像。
原来我忘记了一块...
在处理文件之前,我确实使用了一个函数来限制正在处理的文件:
This is 2.0 .net solution.
I did something similar in C#. This solution used an folder as a drop off point for images to be processed. Loading each type of file as an image is not correct solution in all cases but I wanted to validate each file as a loadable image.
Turns out I forgot a piece...
Before I process the files, I did use a function to limit files being processed: