Loading thumbnails in listview.....faster way?
-
I have windows forms application, where user can select images to be loaded from FileDialog. It creates thumbnails of those and displayes them in listview...its taking longer then expected. Users generally select 30-35 200DPI .jpeg images. I am using Imagelist & Listview combination....I think problem is of windows painting(invalidate or refresh)...I do beginUpdate,endUpdate before and after adding items. How can i boost performance of this task? Any help will greatly be appriciated.. Regards, MaulikCE
-
I have windows forms application, where user can select images to be loaded from FileDialog. It creates thumbnails of those and displayes them in listview...its taking longer then expected. Users generally select 30-35 200DPI .jpeg images. I am using Imagelist & Listview combination....I think problem is of windows painting(invalidate or refresh)...I do beginUpdate,endUpdate before and after adding items. How can i boost performance of this task? Any help will greatly be appriciated.. Regards, MaulikCE
1. Make sure all your images already contain an embedded Thumbnail image 2. Only load those images in the visible area (in other words, don't load them all, only what the user can see on the screen) 3. Thread it so the loading process doesn't "tag" your window
-
I have windows forms application, where user can select images to be loaded from FileDialog. It creates thumbnails of those and displayes them in listview...its taking longer then expected. Users generally select 30-35 200DPI .jpeg images. I am using Imagelist & Listview combination....I think problem is of windows painting(invalidate or refresh)...I do beginUpdate,endUpdate before and after adding items. How can i boost performance of this task? Any help will greatly be appriciated.. Regards, MaulikCE
You have to save your thumbnail images and just load them next time except shrinking the original images again and again. Thumbnails can be stored in some pre-defined directory with hashed filenames. I have developed such very standard system of storing thumbnails based on MD5 hashing. It works this way: 1. Check if the image is small enough (no need to create thumbnail => return) 2. Create MD5 hash from image's FULL path (C:\My Documents\Pictures\ ...) 3. Look to your Thumbnails directory, if there is a thumbnail created 3.1 Yes, load thumbnail 3.2 No, create thumbnail and save it in Thumbnails directory This is my method for generating MD5 from path string (it returns MD5 in hex format):
using System.Security.Cryptography; using System.Text; ... // generate MD5 path protected string HashPath(string path) { ASCIIEncoding enc = new ASCIIEncoding(); MD5 md5 = MD5CryptoServiceProvider.Create(); byte[] buffer = md5.ComputeHash(enc.GetBytes(path)); string hashPath = ""; for (int i = 0; i < buffer.Length; i++) hashPath = hashPath + String.Format("{0:X2}", buffer[i]).ToLower(); return parentPanel.hashDirectory + hashPath + ".jpg"; }
...and of course, optimize your code of thumbnail creation. Use fast GDI+ filters for resampling images and put it all on background separate thread. Hope this helps :-D