ListView - Caching Thumbnails?

D

Dale Atkin

I'm using the listview control to display thumbnails for a number of
relatively large images (~4MB each).

I was thinking, it would speed things up if I could cache a thumbnail for
each image, and display that, rather than the actual image. I'm not really
totally sure how to do that...

I've been looking in to the Image.GetThumbNailImage function, but it doesn't
seem to be working as expected.

If I use this, does the main image still get loaded if a cached thumbnail
exists?

Is there a better way of doing this?

It seems to be running quite slowly, and I'm not sure why.

Dale
 
N

nak

Hi Dale,
I'm using the listview control to display thumbnails for a number of
relatively large images (~4MB each).

I was thinking, it would speed things up if I could cache a thumbnail for
each image, and display that, rather than the actual image. I'm not really
totally sure how to do that...

Basically what you would want to do is create a Dictionary...

Dim myimagecache as new Dictionary(Of String, Bitmap)

myimagecache .Add(filename, bitmapobject) << Adding

myimagecache .Item(filename) << Retreiving
I've been looking in to the Image.GetThumbNailImage function, but it
doesn't seem to be working as expected.

To be honest I wouldn't use this feature, not only is it slow but it can
also return embedded thumbnails in images which don't always match the
actual image. Also the quality returned isn't as great as it can be.
If I use this, does the main image still get loaded if a cached thumbnail
exists?

Yup, you need to perform any caching yourself. One thing to remember
though is when you want to remove images from your cache, dispose of them
first....

Dim myimage as Bitmap = myimagecache .Item(filename)
myimagecache.Remove(filename)
Call myimage.Dispose()

Of course if you are clearing the entire cache you will need to do this
for each individual bitmap. It won't take long but will make sure your app
runs smoothly and you don't run out of resources.
Is there a better way of doing this?

One thing I have done in the past to get lightning fast thumbnails was
to use this,

http://www.vbaccelerator.com/home/net/code/libraries/shell_projects/Thumbnail_Extraction/article.asp

It's a hell of allot faster than using GetThumbnailImage or even
creating the thumbnail yourself.


Nick.
 
N

nak

Hi Dale,
I'm using the listview control to display thumbnails for a number of
relatively large images (~4MB each).

I was thinking, it would speed things up if I could cache a thumbnail for
each image, and display that, rather than the actual image. I'm not really
totally sure how to do that...

Basically what you would want to do is create a Dictionary...

Dim myimagecache as new Dictionary(Of String, Bitmap)

myimagecache .Add(filename, bitmapobject) << Adding

myimagecache .Item(filename) << Retreiving
I've been looking in to the Image.GetThumbNailImage function, but it
doesn't seem to be working as expected.

To be honest I wouldn't use this feature, not only is it slow but it can
also return embedded thumbnails in images which don't always match the
actual image. Also the quality returned isn't as great as it can be.
If I use this, does the main image still get loaded if a cached thumbnail
exists?

Yup, you need to perform any caching yourself. One thing to remember
though is when you want to remove images from your cache, dispose of them
first....

Dim myimage as Bitmap = myimagecache .Item(filename)
myimagecache.Remove(filename)
Call myimage.Dispose()

Of course if you are clearing the entire cache you will need to do this
for each individual bitmap. It won't take long but will make sure your app
runs smoothly and you don't run out of resources.
Is there a better way of doing this?

One thing I have done in the past to get lightning fast thumbnails was
to use this,

http://www.vbaccelerator.com/home/net/code/libraries/shell_projects/Thumbnail_Extraction/article.asp

It's a hell of allot faster than using GetThumbnailImage or even
creating the thumbnail yourself.


Nick.
 
D

Dale Atkin

One thing I have done in the past to get lightning fast thumbnails was
to use this,


http://www.vbaccelerator.com/home/net/code/libraries/shell_projects/Thumbnail_Extraction/article.asp

It's a hell of allot faster than using GetThumbnailImage or even
creating the thumbnail yourself.

This looks very interesting, and should suit my needs. I'll have to take a
closer look at it.

Do you happen know off the top of your head if it is relying on the file
extension to determine the file type? Or does it look at the actual file?
One thing I've done, to try to discourage novice users from monkeying with
the underlying data outside my program, is to strip off the file extensions.
Looking at how this is working would tend to make me believe that the file
extensions might be important for this to work properly.

Dale
 
D

Dale Atkin

One thing I have done in the past to get lightning fast thumbnails was
to use this,


http://www.vbaccelerator.com/home/net/code/libraries/shell_projects/Thumbnail_Extraction/article.asp

It's a hell of allot faster than using GetThumbnailImage or even
creating the thumbnail yourself.

This looks very interesting, and should suit my needs. I'll have to take a
closer look at it.

Do you happen know off the top of your head if it is relying on the file
extension to determine the file type? Or does it look at the actual file?
One thing I've done, to try to discourage novice users from monkeying with
the underlying data outside my program, is to strip off the file extensions.
Looking at how this is working would tend to make me believe that the file
extensions might be important for this to work properly.

Dale
 
N

nak

Hi Dale,

Umm, well as it's using Explorer, my understanding is that the file
extension will play a big part. The best thing to do would be to have a try
tbh, but I think if Explorer treats the image differently after changing the
extension then so will this method.

Out of interest are you thumbnailing images that are packed with the
application, or images that are created by the application at runtime? If
the latter, one thing you could do, is create an index file that holds the
file type of each file and then just associate it by a key of some kind.

<CacheIndex>
<CacheItem>
<Key>key goes in here</Key>
<OriginalType>original file extension goes in
here</OriginalType>
<MD5Hash>hash of file data goes in here</MD5Hash>
</CacheItem>
<CacheItem>
<Key>key goes in here</Key>
<OriginalType>original file extension goes in
here</OriginalType>
<MD5Hash>hash of file data goes in here</MD5Hash>
</CacheItem>
...
</CacheIndex>

I wrote "MD5Hash" there too as if you don't want the user to change the
files in any way, you could also hash them and compare the hash with the
actual file data upon retrieval, if it differs then you know it's been
tampered with.

Nick.
 
N

nak

Hi Dale,

Umm, well as it's using Explorer, my understanding is that the file
extension will play a big part. The best thing to do would be to have a try
tbh, but I think if Explorer treats the image differently after changing the
extension then so will this method.

Out of interest are you thumbnailing images that are packed with the
application, or images that are created by the application at runtime? If
the latter, one thing you could do, is create an index file that holds the
file type of each file and then just associate it by a key of some kind.

<CacheIndex>
<CacheItem>
<Key>key goes in here</Key>
<OriginalType>original file extension goes in
here</OriginalType>
<MD5Hash>hash of file data goes in here</MD5Hash>
</CacheItem>
<CacheItem>
<Key>key goes in here</Key>
<OriginalType>original file extension goes in
here</OriginalType>
<MD5Hash>hash of file data goes in here</MD5Hash>
</CacheItem>
...
</CacheIndex>

I wrote "MD5Hash" there too as if you don't want the user to change the
files in any way, you could also hash them and compare the hash with the
actual file data upon retrieval, if it differs then you know it's been
tampered with.

Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top