[英]How to load and store a folder of Images
我正在執行一個團隊程序,我的任務是增加加載單個圖像或(更可能是)圖像文件夾的功能,並將其保存,以便程序的其他方面也可以訪問它們。
這是我的實際問題:
Open File
或“ Open Folder
對話框的示例。 注意:我最終需要顯示這些圖像,但是在程序的另一部分將根據顏色對其重新排序之后。
這樣的事情可能是:
Dictionary<string, Bitmap> images = new Dictionary<string, Bitmap>();
string[] extensions = new string[]{".BMP",".JPG",".GIF",".PNG"};
var fd = new System.Windows.Forms.FolderBrowserDialog();
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (var file in Directory.GetFiles(fd.SelectedPath).Where(f => extensions.Contains(Path.GetExtension(f).ToUpper())))
{
images.Add(Path.GetFileNameWithoutExtension(file), new Bitmap(file));
}
}
或打開文件:
var fd = new System.Windows.Forms.OpenFileDialog();
fd.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG";
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
images.Add(Path.GetFileNameWithoutExtension(fd.FileName,new Bitmap(fd.FileName));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.