More Examples of Simplified Image Processing in GDI+ - Sample Six-Working with Thumbnail Images
(Page 2 of 4 )
In the commonly used picture viewer applications, such as AcdSee, Windows Explorer, a thumbnail gives an outline of a real image. Using GDI+, you can easily achieve the purpose of rendering a thumbnail of an image.
The following shows the signature of the GetThumbnailImage() method:
// Summary:
// Returns a thumbnail for this System.Drawing.Image.
// Parameters:
// thumbWidth:
// The width, in pixels, of the requested thumbnail image.
// thumbHeight:
// The height, in pixels, of the requested thumbnail image.
// callback:
// A System.Drawing.Image.GetThumbnailImageAbort delegate. In GDI+ version 1.0,
// the delegate is not used. Even so, you must create a delegate and pass a
// reference to that delegate in this parameter.
// callbackData:
// Must be System.IntPtr.Zero.
// Returns:
// An System.Drawing.Image that represents the thumbnail.
public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData);
As shown from the above definition, a thumbnail is based upon a whole image; it is in fact only a copy of the original image. In addition, the user can specify the size of a thumbnail of an image-maybe even larger than the original. Next, let us take a close look at a related sample application.
Graphics graphics=this.CreateGraphics();
graphics.Clear(Color.White);
//set up the interpolation mode-HighQualityBicubic
graphics.InterpolationMode=InterpolationMode.HighQualityBicubic;
//load the image to be shown as thumbnails
Bitmap image=new Bitmap("flower.bmp");
//obtain the size of the current window
Rectangle client=new Rectangle(0,0,
this.ClientSize.Width,this.ClientSize.Height);
float width=image.Width;
float height=image.Height;
//get a thumbnail of specified size
Image.GetThumbnailImageAbort myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image pThumbnail = image.GetThumbnailImage(40,40, myCallback ,IntPtr.Zero);
//use the thumbnail as a brush
TextureBrush picBrush=new TextureBrush(pThumbnail);
//fill in the window
graphics.FillEllipse(picBrush,client);
Since there are already enough comments in the code, we will not dwell on it. Figure 7 gives the associated running-time snapshot.
Figure 7-the associated running-time snapshot of the thumbnail effect
_html_m5da559fd.png)
Next: Sample Seven-Cloning an Image >>
More Windows Scripting Articles
More By Xianzhong Zhu