Draws the picture at the specified location. The picture can be shown at full size, cropped, or scaled. All units are pixels.
X and Y are the distances from the top-left corner of the control or window from which the 0,0 point of the image will be drawn. The optional parameters are used to copy a portion of the picture (cropping) and for scaling the picture.
If you are cropping, then DestWidth and DestHeight are also required. If you are doing scaling, then all of the optional parameters are required. You scale an image by making the destination width and height different from the source width and height.
The parameters SourceX, SourceY, SourceWidth, and SourceHeight describe the portion of the image that will be scaled. DestWidth and DestHeight are used to change the scaling of the picture when SourceWidth and SourceHeight are provided. SourceX and SourceY default to 0 and are used to determine the upper-left coordinate you wish to copy from.
|NOTE: Negative values for DestWidth, DestHeight, SourceWidth and SourceHeight are not supported so the behavior is undefined.|
The following example scales an image by 50%. The image, MyImage, has been added to the project. Its size is 600 x 915. Note that the destination width and height are half the original width and height. The code is in the Paint event of a Canvas. A call to DrawRect adds a black border around the Canvas.
g.DrawRect(0, 0, Me.Width, Me.Height)
Dim scale As Double = 0.50
g.DrawPicture(MyImage, 0, 0, MyImage.Width * scale, MyImage.Height * scale, 0, 0, MyImage.Width, MyImage.Height)
The following code crops the image. It copies only the top 150 pixels of the original image at full size:
The following code crops and scales the image. The top half of the image is retained and the DestWidth and DestHeight parameters specify a 50% reduction.
If you don't want to scale or crop the image, you can leave off the last six parameters. In this case, it will appear full-size.