System.Drawing.Graphics.DrawImage Method

Draws a portion of an image at a specified location.

Syntax

public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)

Parameters

image
System.Drawing.Image to draw.
x
The x-coordinate of the upper-left corner of the drawn image.
y
The y-coordinate of the upper-left corner of the drawn image.
srcRect
System.Drawing.Rectangle structure that specifies the portion of the image object to draw.
srcUnit
Member of the System.Drawing.GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

Remarks

An System.Drawing.Image stores a value for pixel width and a value for horizontal resolution (dots per inch). The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. For example, an image with a pixel width of 360 and a horizontal resolution of 72 dots per inch has a physical width of 5 inches. Similar remarks apply to pixel height and physical height.

This method draws a portion of an image using its physical size, so the image portion will have its correct size in inches regardless of the resolution (dots per inch) of the display device. For example, suppose an image portion has a pixel width of 216 and a horizontal resolution of 72 dots per inch. If you call this method to draw that image portion on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image portion will be (216/72)*96 = 288.

Requirements

Namespace: System.Drawing
Assembly: System.Drawing (in System.Drawing.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0