Search code examples
delphiimagethumbnailsfilestream

What is the fastest way of loading and re-sizing an image?


I need to display thumbnails of images in a given directory. I use TFileStream to read the image file before loading the image into an image component. The bitmap is then resized to the thumbnail size, and assigned to a TImage component on a TScrollBox.

It seems to work ok, but slows down quite a lot with larger images.

Is there a faster way of loading (image) files from disk and resizing them?

Thanks, Pieter


Solution

  • Not really. What you can do is resize them in a background thread, and use a "place holder" image until the resizing is done. I would then save these resized images to some sort of cache file for later processing (windows does this, and calls the cache thumbs.db in the current directory).

    You have several options on the thread architecture itself. A single thread that does all images, or a thread pool where a thread only knows how to process a single image. The AsyncCalls library is even another way and can keep things fairly simple.