在C#中打开多个图像 [英] Open several images in C#
本文介绍了在C#中打开多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从一个文件夹中打开几张图像,每张图像都需要将其转换为二进制格式.如何在folder \ sub文件夹中自动打开几个文件?
现在,我可以通过手动选择openFileDialog一次打开一个文件.
I need to open several images from a folder and with every image I need to convert it to binary format. How can I open several files automatically within folder\sub folders?
Right Now I am able to open 1 file at a time by manually choosing form the openFileDialog.
openFileDialog1.FileName = "";
openFileDialog1.Title = "Images";
openFileDialog1.Filter = "Png Images| *.png";
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName.ToString() != "")
{
Image.ImageLocation = openFileDialog1.FileName.ToString();
img = new Bitmap(openFileDialog1.FileName.ToString());
}
推荐答案
如果仔细查看OpenFileDialog类,您会发现它具有 ^ ]-将其设置为true
,它将允许用户选择一个以上的文件时间.然后,您可以使用Filenames属性以循环方式打开每个图像.
但是请注意,完成操作后应处置位图对象,不要只是让它们超出范围,否则以后会引起问题.
顺便说一句:您不必在字符串对象(例如OpenFileDialog.FileName)上调用ToString.
If you look closely at the OpenFileDialog class, you will see it has a Multiselect property[^] - set that totrue
and it will allow the user to select more than one file at a time. You can then use the Filenames property to open each image in a loop.
Do be aware however, that you should Dispose of Bitmap objects when you are finished with, don''t just let them go out of scope or it will cause problems later.
BTW: You do not have to call ToString on string objects such as OpenFileDialog.FileName.
这篇关于在C#中打开多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文