I copied the code into a new project and everything is quick as a fox to me.
Try it out! =)
If you want more freedom with what you do, (e.g. the max imagesize on an
imagelist is 256 pixels.), you may want to try out creating your own custom
thumbnail view from a PictureBox, and a label. =)
If this code doesn't work, you may want to look at your image size.
I'm curious - How big are the images you're dealing with? (These are itty
bitty jpegs after all)
On the Form, we have:
A ListView named listView1.
An ImageList named imageList1.
A button named button1.
A FolderBrowserDialog named folderBrowserDialog1.
private void button1_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
DirectoryInfo targetDirectory = new
DirectoryInfo(folderBrowserDialog1.SelectedPath);
listView1.BeginUpdate(); // don't update the listview state
as we change things
listView1.AutoArrange = false;
listView1.Items.Clear(); // reset the listview, let's start
loading images from scratch
imageList1.Images.Clear(); // reset the imagelist, let's
start loading images from scratch
imageList1.ColorDepth = ColorDepth.Depth32Bit; // 4 - 32
color depth
imageList1.ImageSize = new Size(100, 100); // this can vary
from 1 - 256 inclusive
int countPaths = 0; // index into the number of images we've
added so far
//
Go through all the files in a directory
foreach (FileInfo file in targetDirectory.GetFiles()) // Not
a performance hit since the JIT does performance optimizations.
{
if (file.Extension == ".jpg") // Apparently, jpegs are
important to us. ((file.Extension == ".jpg") || (file.Extension == ".gif"))
to add gif support
{
imageList1.Images.Add(Image.FromFile(folderBrowserDialog1.SelectedPath +
@"\" + file.Name));
listView1.Items.Add(file.Name, countPaths);
listView1.Items[countPaths].Tag =
folderBrowserDialog1.SelectedPath + @"\" + file.Name;
countPaths++;
}
}
listView1.View = View.LargeIcon; // Display images for each
item in the listview
listView1.LargeImageList = imageList1; // Bind the
ImageList to the listView. (*Important*)
listView1.EndUpdate(); // Start rendering the listview
again.
}
}
Cheers!
David J. Smith
Visual C# MVP
smith...@msu.edu
_____
From: GLUGnet@googlegroups.com [mailto:GLUGnet@googlegroups.com] On Behalf
Of David Smith
Sent: Tuesday, September 27, 2005 1:50 PM
To: GLUGnet@googlegroups.com
Subject: GLUGnet :: performance woes
Hi guys,
This code seems to be running pretty slow (about 1 second / image)
dlgOpen.ShowDialog()
ListView1.BeginUpdate()
ListView1.AutoArrange = False
ImageList1.Images.Clear()
ListView1.Items.Clear()
Dim fileSys As System.IO.Directory
Dim intCountPaths As Integer = 0
For Each path As String In fileSys.GetFiles(dlgOpen.SelectedPath)
Dim fileProps As New System.IO.FileInfo(path)
If LCase(fileProps.Name).EndsWith(".jpg") Then
ImageList1.Images.Add(System.Drawing.Image.FromFile(dlgOpen.SelectedPath &
"\" & fileProps.Name))
ListView1.Items.Add(fileProps.Name, intCountPaths)
ListView1.Items(intCountPaths).Tag = dlgOpen.SelectedPath &
"\" & fileProps.Name
intCountPaths += 1
End If
Next path
ListView1.EndUpdate()
Any ideas on how to speed things up?
Thanks!
--dave
_________________
David Smith
(517) 944-1872
smith...@msu.edu
614 Theo
Lansing MI 48917