Looking for happy medium with thumbnails

ss7thirty

Well-known member
Joined
Jun 14, 2005
Messages
455
Location
New Jersey, US
Programming Experience
5-10
I have a custom thumbnailContainerControl which is a flow layout panel, status bar, and a few other doo dads and a custom thumbnailControl which is basically a panel with a picturebox and a label on it. With this control we are loading many TIF and JPG files into the picture box of the thumbnail control within the flow layout panel.

I am looking for the fastest way to do this without losing quality. I am looking for all possible ways to do this. I have added threads, while using the getThumbnailImage method in the built in Image object. I have also tried using this graphics object but this seems to be slower and a bit buggy.

I am looking for suggestions on how to generate thumbnails as quickly and at the highest quality possible. If you know anything at all on this subject drop me a line. It seems like everything I try causes other problems. If i get it faster I lose quality and if I get the quality it gets slower and so on.

I see other applications that have the thumbnail option and I ponder how they get them to load so fast and keep them from skipping when you scroll. I was wondering if anyone knew how these retailed programs do this so well.


steve
 
I am just going to hazard a guess here, but think they use some form of BitBlt'ing. It's an API that i've heard is short for 'bit blast'. It's a very fast API for putting images onto the screen. This may be a long shot but you could look into it. Google for 'vb.net - bitblt' there will be a lot of articles about it on there.
 
I have researched some on this, it took a while since I haven't used these old methods for some years, not since VB6 days, and they are not very easy to handle compared to VB.Net graphics.

API blitting is not faster with my tests, it is actually slower than GDI+. Bitblt is equal in functionality to DrawImageUnscaled (or DrawImage if you don't actually scale), but for thumbnails you have to try StretchBlt API - I usually lost 1 second (of 12 seconds total) on this with 600 image operations in a batch. (When testing same 600 unscaled, DrawImage beat Bitblt by 4 seconds!) The original images were about 350x350 and thumbs 200x200, so there were only about 1.5 millisecond difference per image operation.

When testing larger source images 1600x1200 the differences increased dramatically, but the choice of method the same, blitting is slow, GetThumbnailImage fast, DrawImage in between and adjustable by quality setting. Difference was 90ms per image between fastest and slowest.

I would say go for DrawImage and the worst quality setting tolerable for thumbnails. And watch out for too large source images, downsize sources if they don't need to be 1600x1200 but rather 800x600 would be sufficient for instance.

Tests was done with VS2005 .Net 2.0, I also read somewhere that GDI+ has been optimized in .Net 2.0 since .Net 1.0.
 
I'm sorry but BitBlt'ing is most definately not slower than using GDI+, in terms of pure language it's a lower level programming and therefore has a performance advantage from the start. Here's an article from the code project that goes into BB.

http://www.codeproject.com/vb/net/Bitblt_wrapper_class.asp
 
I've seen that before, it is using a visible Picturebox, visible on screen graphics operations are always slower than those that are only performed in memory. To do blitting in pure memory you have use SelectObject and DeleteObject, which could be where the crossover managed to unmanaged code looses compared to the managed-optimized GDI+ library.
 
I must admit after reading your post that i considered the possibility that it was the marshalling that would cause the performance loss. The answer to the original question is that it is most likely that the retail applications that handle thumbnails and multiple images are not using managed code. In all languages graphics is an expensive operation. If you look deep into the system.drawing namespace there is a double buffer class in there that is used when the setstyle(controlstyles.doublebuffer,true) is called. It may be possible to use this class to solve your problem though i havent tried it myself.
 
Back
Top