Recipe 10.11. Creating Thumbnails


Problem

You want to create good-quality thumbnail JPEG images from larger images. These smaller versions of larger pictures are handy for web pages.

Solution

The CompressJPEG class presented in Recipe 10.9 provides an ideal solution for creating smaller thumbnail versions of large JPEG pictures.

Discussion

Instead of setting the CompressJPEG object's SizePercent property to shrink the pictures to some unknown smaller size, set the Height property to 100 to force the creation of compressed files exactly 100 pixels high. The width of each output thumbnail picture will be automatically adjusted to retain the proportions of the original image. The default QualityPercent value of 85 works just fine for these thumbnails:

 Dim imageThumb As New CompressJPEG imageThumb.Height = 100 imageThumb.Load("sample.jpg") imageThumb.Save("sampleThumb.jpg") 

The picture shown in Figure 10-13 is a 100-pixel-high copy of an original, and much larger, JPEG picture of a mountain in the Grand Tetons.




Visual Basic 2005 Cookbook(c) Solutions for VB 2005 Programmers
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))
ISBN: 0596101775
EAN: 2147483647
Year: 2006
Pages: 400

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net