【发布时间】:2014-07-25 19:28:38
【问题描述】:
我创建了一个简单的程序,将 Listbox1 中选定项目的图像显示到图片框1。它工作正常,但显示下一张图像大约需要 200 毫秒。我的电脑使用的是 Intel i7 处理器和 Windows 7 64 位。请告诉我如何加快这个过程。以下是我的代码。谢谢!
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
folderBrowserDlg.SelectedPath = folderpath;
this.folderBrowserDlg.ShowNewFolderButton = false; //Disable New Folder button
DialogResult result = this.folderBrowserDlg.ShowDialog();
if (result == DialogResult.OK)
{
folderpath = this.folderBrowserDlg.SelectedPath;
string ImagePath = folderpath.Substring(0, folderpath.LastIndexOf(("\\")));
folderName = folderpath.Substring(folderpath.LastIndexOf(("\\")) + 1);
PathLength = ImagePath.Length; //Use for Substring later
txtBrowse.Text = folderpath; //Get folder path and display to textbox
var filearray = Directory.EnumerateFiles(folderpath, "*.*", SearchOption.AllDirectories).Where(a => a.EndsWith(".tif") || a.EndsWith(".tiff"));
array = filearray.ToArray();
var filenames = Directory.EnumerateFiles(folderpath, "*.*", SearchOption.AllDirectories).Where(a => a.EndsWith(".tif") || a.EndsWith(".tiff")).Select(Path.GetFileName); // Get all image file names
foreach (string fn in filenames)
{
listBox1.Items.Add(fn); // Add all image file names to listbox
}
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter) //Go to next image after press Enter key
{
if (listBox1.SelectedIndex != listBox1.Items.Count - 1)
{
listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
}
e.SuppressKeyPress = true;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Index = listBox1.SelectedIndex; //Get selected item from listbox
pictureBox1.Image = Image.FromFile(array[Index].ToString()); // display image to picturebox
}
【问题讨论】:
-
原始图像有多大(以字节为单位)?
-
200 毫秒?用户会睡着的!
-
@Erno de Weerd:每个文件夹大约有 1000 张图像。每张图片的分辨率为 300 dpi。
-
抱歉,我们需要以 Kb 为单位的大小和大小(像素!)而不是 DPI
-
大小在100KB到300KKb之间,尺寸为3184x4208
标签: c# image listbox picturebox