Board index » delphi » Images to thumbnails - TCanvas of a TImage?

Images to thumbnails - TCanvas of a TImage?

I'm writing a little "match-two-pictures" game that uses thumbnails of
pictures from a given folder on the user's hard disk.

I currently just load the image (e.g. foobar.bmp) into a TImage control and
auto-shrink it down to 100x100 pixels (using the Stretch property).

The problem is, if I have 12 (or 24, or 48) images, that's going to chew up
memory quick if the images are large (e.g. an 800x600 BMP file).

What I really want is to just load the image, generate a thumbnail, then just
use the thumbnail (100x100), because they're never going to see the full-size
image.

What's the easiest way for me to grab the thumbnail bitmap?

Can I just load the full-size image, then somehow grab the TCanvas and use it
to replace the full-size image?

I'm assuming that the full-size image is the TImage.Picture property, and the
TCanvas is the actual image rendered on the screen after sizing, stretching,
etc.  Is this correct? How do I get at the TCanvas's rendered image?

Thanks for any help!

--

| Dave O'Brien - dobr...@NoSpam.bigfoot.com - ICQ 3265164
| http://www.cgl.uwaterloo.ca/~gmgrimsh/dobrien.html
+--------------------------------------------------------
| Author of these Windows BeerWare titles:
| - Smoke'em Poker: 5-card draw vs. computer players
| - Battle Board: Internet fantasy-combat board game

 

Re:Images to thumbnails - TCanvas of a TImage?


Dave,

Load the bitmap file into a temporary TBitmap, and use the TImage
Canvas.StretchDraw() to draw the bitmap onto the TImage.

Ken
--
Ken White

Clipper Functions for Delphi
http://members.aol.com/clipfunc

Quote
Dave O'Brien wrote:

> I'm writing a little "match-two-pictures" game that uses thumbnails of
> pictures from a given folder on the user's hard disk.

> I currently just load the image (e.g. foobar.bmp) into a TImage control and
> auto-shrink it down to 100x100 pixels (using the Stretch property).

> The problem is, if I have 12 (or 24, or 48) images, that's going to chew up
> memory quick if the images are large (e.g. an 800x600 BMP file).

> What I really want is to just load the image, generate a thumbnail, then just
> use the thumbnail (100x100), because they're never going to see the full-size
> image.

> What's the easiest way for me to grab the thumbnail bitmap?

> Can I just load the full-size image, then somehow grab the TCanvas and use it
> to replace the full-size image?

> I'm assuming that the full-size image is the TImage.Picture property, and the
> TCanvas is the actual image rendered on the screen after sizing, stretching,
> etc.  Is this correct? How do I get at the TCanvas's rendered image?

> Thanks for any help!

> --

> | Dave O'Brien - dobr...@NoSpam.bigfoot.com - ICQ 3265164
> | http://www.cgl.uwaterloo.ca/~gmgrimsh/dobrien.html
> +--------------------------------------------------------
> | Author of these Windows BeerWare titles:
> | - Smoke'em Poker: 5-card draw vs. computer players
> | - Battle Board: Internet fantasy-combat board game

Re:Images to thumbnails - TCanvas of a TImage?


Quote
>Load the bitmap file into a temporary TBitmap, and use the TImage
>Canvas.StretchDraw() to draw the bitmap onto the TImage.

Thanks, Ken, that did the trick.

For a while there I was confused about bitmaps vs. canvases and copying
between the two, but StretchDraw does exactly what I wanted.

--

| Dave O'Brien - dobr...@NoSpam.bigfoot.com - ICQ 3265164
| http://www.cgl.uwaterloo.ca/~gmgrimsh/dobrien.html
+--------------------------------------------------------
| Author of these Windows BeerWare titles:
| - Smoke'em Poker: 5-card draw vs. computer players
| - Battle Board: Internet fantasy-combat board game

Other Threads