Graphics.DrawImageUnscaledAndClipped(Image, 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

要绘制的 Image

rect
Rectangle

要在其中绘制图像的 Rectangle

例外

imagenull

示例

下面的示例演示如何使用 DrawImageUnscaledAndClipped 方法。 若要运行此示例,请将其粘贴到 Windows 窗体中。 处理窗体的 Paint 事件,并从Paint事件处理方法调用 DrawImageUnscaled 方法,作为 ePaintEventArgs传递。

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

适用于