My task is to create an array of thumbnails of images from a folder in a C# Windows Forms control. The number of images is unknown, so I use an instance of FlowLoayoutPanel
to arrange them. Then I create a number of instances of PictureBox
and assign the thumbnails of all the images to them, like in the following code (obvious action omitted):
FlowLayoutPanel flp = new FlowLayoutPanel();
foreach (string fileName in fileNames)
{
PictureBox pb = new PictureBox();
pb.Image = Image.FromFile(fileName).GetThumbnailImage(pb.Height, pb.Width, null, new IntPtr());
flp.Controls.Add(pb);
}
This code functions, but very slowly: it takes many seconds to display a hundred images or so, even in Release mode. I also tried to assign the images themselves, instead of creating thumbnails, but it is still very slow.
Is there any possibility to accelerate the creation of thumbnails or to achieve the desired result (an album-like collection of thumbnails) in a different way (e.g. in an external C routine to add via Interop)?