Answered by:
Multiple image thumbnail viewer

Question
-
I am trying to create a simple winform application in c# that can load multiple images from a file dialog into the application screen. I am using ListView control to contain those images as picture box control wasn't going to serve my needs as I want to be able to select loaded thumbnails and do many other things based on the selection.
The problem I am having is to do with thumbnail image quality. Once they get loaded in the application window panel, the image quality is very poor. I want them to look just like how Windows operating system displays preview/thumbnails of images in large icon with a decent image quality.
I've tried adding this
listView1.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
as suggested by other people but it won't even let the application load images.Here is the code done so far.
using (OpenFileDialog open = new OpenFileDialog()) { open.Title = "Open Image"; open.Filter = "JPEG Files (*.jpg)|*.jpg;*.jpeg|All Files (*.*)|*.*"; open.Multiselect = true; if (open.ShowDialog() == DialogResult.OK) { ImageList picList = new ImageList(); listView1.View = View.LargeIcon; picList.ImageSize = new Size(200, 130); foreach (String file in open.FileNames) { Image i = Image.FromFile(file); Image pic = i.GetThumbnailImage(200, 130, null, new IntPtr()); picList.Images.Add(pic); } listView1.LargeImageList = picList; listView1.LargeImageList.ColorDepth = ColorDepth.Depth32Bit; for (int i = 0; i < picList.Images.Count; i++) { ListViewItem item = new ListViewItem(); item.ImageIndex = i; listView1.Items.Add(item); } }
Does anyone have any suggestions as to make it perform just as good as Windows' default thumbnail viewer
where you have good quality thumbnail images and being able to select multiple of them.Thursday, April 4, 2013 9:54 PM
Answers
-
It could have something to do with your aspect ratio changing when you resize the image. Here is a link with several ways to maintain aspect ratios.
Thursday, April 4, 2013 10:34 PM -
Hi,
you need to resize the images yourself to get a better quality. Means to load the image, create a resized thumbnail from it and display this. I recommend to store the thumbnails in some kind of a database to increase the loading speed (so that not all thumbs have to created each time you browse that folder), just check if the files are in the DBtable and if the filespecs are still the same (not modified) and load those from the db and only create the others anew.
Regards,
Thorsten
- Edited by Thorsten Gudera Friday, April 5, 2013 9:24 AM
- Proposed as answer by Bob Wu-MT Tuesday, April 9, 2013 8:10 AM
- Marked as answer by Mike Feng Sunday, May 5, 2013 6:00 AM
Friday, April 5, 2013 9:24 AM
All replies
-
It could have something to do with your aspect ratio changing when you resize the image. Here is a link with several ways to maintain aspect ratios.
Thursday, April 4, 2013 10:34 PM -
Hi,
you need to resize the images yourself to get a better quality. Means to load the image, create a resized thumbnail from it and display this. I recommend to store the thumbnails in some kind of a database to increase the loading speed (so that not all thumbs have to created each time you browse that folder), just check if the files are in the DBtable and if the filespecs are still the same (not modified) and load those from the db and only create the others anew.
Regards,
Thorsten
- Edited by Thorsten Gudera Friday, April 5, 2013 9:24 AM
- Proposed as answer by Bob Wu-MT Tuesday, April 9, 2013 8:10 AM
- Marked as answer by Mike Feng Sunday, May 5, 2013 6:00 AM
Friday, April 5, 2013 9:24 AM