Graphics.DrawImageUnscaledAndClipped(Image, Rectangle) 方法

定义

在不进行缩放的情况下绘制指定的图像,并在需要时剪辑该图像以适合指定的矩形。Draws the specified image without scaling and clips it, if necessary, to fit in the specified rectangle.

public:
 void DrawImageUnscaledAndClipped(System::Drawing::Image ^ image, System::Drawing::Rectangle rect);
public void DrawImageUnscaledAndClipped (System.Drawing.Image image, System.Drawing.Rectangle rect);
member this.DrawImageUnscaledAndClipped : System.Drawing.Image * System.Drawing.Rectangle -> unit
Public Sub DrawImageUnscaledAndClipped (image As Image, rect As Rectangle)

参数

image
Image

要绘制的 ImageThe Image to draw.

rect
Rectangle

要在其中绘制图像的 RectangleThe Rectangle in which to draw the image.

例外

imagenullimage is null.

示例

下面的示例演示如何使用 DrawImageUnscaledAndClipped 方法。The following example demonstrates how to use the DrawImageUnscaledAndClipped method. 若要运行此示例,请将其粘贴到 Windows 窗体中。To run this example, paste it into a Windows Form. 处理窗体的 Paint 事件,并 DrawImageUnscaledPaint 事件处理方法调用方法,并将 e 作为传递 PaintEventArgsHandle the form's Paint event and call the DrawImageUnscaled method from the Paint event-handling method, passing e as PaintEventArgs.

private void DrawImageUnscaled(PaintEventArgs e)
{
    string filepath = @"C:\Documents and Settings\All Users\Documents\" + 
        @"My Pictures\Sample Pictures\Water Lilies.jpg";
    Bitmap bitmap1 = new Bitmap(filepath);
    e.Graphics.DrawImageUnscaledAndClipped(bitmap1, new Rectangle(10,10,250,250));
}
Private Sub DrawImageUnscaled(ByVal e As PaintEventArgs) 
    Dim filepath As String = "C:\Documents and Settings\All Users\Documents\" _
        & "My Pictures\Sample Pictures\Water Lilies.jpg"
    Dim bitmap1 As New Bitmap(filepath)
    e.Graphics.DrawImageUnscaledAndClipped(bitmap1, _
        New Rectangle(10, 10, 250, 250))
End Sub

适用于