I was trying to generate thumbnails using Bitmap.GetThumbnailImage() function for 20+ images in a folder. I could see huge memory spike by the application when it does the following procedure (about 600,000K in Task Manager mem usage).
foreach (var image in ListOfImages)
{
var thumbnailFolder = @"\thumb";
var thumbnailFile = thumbnailFolder + "\\" + image.Name;
if (!Directory.Exists(thumbnailFolder))
{
Directory.CreateDirectory(thumbnailFolder);
}
if (!File.Exists(thumbnailFile))
{
using (FileStream fs = new FileStream(image.FullName, FileMode.Open, FileAccess.Read))
{
Image origImage = Image.FromStream(fs);
var thumbnail = origImage.GetThumbnailImage(90, 120, null, IntPtr.Zero);
thumbnail.Save(thumbnailFile);
thumbnail.Dispose();
origImage.Dispose();
}
}
}
Is there any way to reduce this much memory usage for thumbnail generation?