Graphics.DrawImageUnscaledAndClipped(Image, Rectangle) 方法

定义

在不进行缩放的情况下绘制指定的图像,并在需要时剪辑该图像以适合指定的矩形。

C#
public void DrawImageUnscaledAndClipped (System.Drawing.Image image, System.Drawing.Rectangle rect);

参数

image
Image

要绘制的 Image

rect
Rectangle

要在其中绘制图像的 Rectangle

例外

imagenull

示例

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

C#
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));
}

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9