Simplified Image Processing in GDI+ - Sample Two-Clipping and Scaling Images
(Page 4 of 6 )
Now, let us shift our attention to another application of the image process supported by GDI+-clipping and scaling images. There is still nothing peculiar here; all functions still rest on the DrawImage() method. As usual, let us first look at the running-time snapshot, as is shown in Figure 2.
Figure 2-the running-time snapshot for sample 2

The following gives the short coding in this sample:
Graphics graphics=this.CreateGraphics();
graphics.Clear(Color.White);
//load the image
Bitmap image=new Bitmap("nemo.bmp");
int width = image.Width;
int height = image.Height;
//enlarge the target area by 1.4 times of the source image
RectangleF destinationRect=new RectangleF(
width+10, 0.0f, 1.4f* width, 1.4f* height);
//first render the source image
graphics.DrawImage(image, 0, 0);
//then draw the bitmap onto the target area
graphics.DrawImage(
image,
destinationRect,
new RectangleF(0, 0, //upper left corner of the source image
0.65f*width, // only render 65% of the width of the source image
0.65f * height), // only render 65% of the height of the source image
GraphicsUnit.Pixel);
Here, we first enlarge the target area 1.4 times and then in the DrawImage() function we shrink the rendering area to 65% of the original image, by which both the clipping and scaling effects are achieved. As is shown is Figure 2, you may find the body of the goldfish becomes bigger, while the mouth of the goldfish is still invisible, which is just the effect accomplished by clipping and scaling. In addition, you will find that in the enlarged image appears some blurring effect, which will be covered in the next topic.
Next: Sample Three-Use Interpolation to Output >>
More Windows Scripting Articles
More By Xianzhong Zhu