在C#中打开多个图像 [英] Open several images in C#

查看:110
本文介绍了在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类,您会发现它具有
If you look closely at the OpenFileDialog class, you will see it has a Multiselect property[^] - set that to true 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屋!

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