Graphics.DrawImage 方法

定义

在指定位置并且按原始大小绘制指定的 Image

重载

DrawImage(Image, Single, Single, RectangleF, GraphicsUnit)

在指定的位置绘制图像的一部分。

DrawImage(Image, Effect, RectangleF, Matrix, GraphicsUnit, ImageAttributes)
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Int32, Int32, Int32, Int32)

在指定位置并且按指定大小绘制指定的 Image

DrawImage(Image, Single, Single, Single, Single)

在指定位置并且按指定大小绘制指定的 Image

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Effect)
DrawImage(Image, Point)

在指定的位置使用原始物理大小绘制指定的 Image

DrawImage(Image, Point[])

在指定位置并且按指定形状和大小绘制指定的 Image

DrawImage(Image, PointF)

在指定的位置使用原始物理大小绘制指定的 Image

DrawImage(Image, PointF[])

在指定位置并且按指定形状和大小绘制指定的 Image

DrawImage(Image, Rectangle)

在指定位置并且按指定大小绘制指定的 Image

DrawImage(Image, RectangleF)

在指定位置并且按指定大小绘制指定的 Image

DrawImage(Image, Int32, Int32, Rectangle, GraphicsUnit)

在指定的位置绘制图像的一部分。

DrawImage(Image, Single, Single)

在指定的位置使用原始物理大小绘制指定的 Image

DrawImage(Image, Point[], Rectangle, GraphicsUnit)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, PointF[], RectangleF, GraphicsUnit)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

DrawImage(Image, Int32, Int32)

在由坐标对指定的位置,使用图像的原始物理大小绘制指定的图像。

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)

在指定位置绘制指定的 Image 的指定部分。

DrawImage(Image, Single, Single, RectangleF, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定的位置绘制图像的一部分。

public:
 void DrawImage(System::Drawing::Image ^ image, float x, float y, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, float x, float y, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * single * single * System.Drawing.RectangleF * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, x As Single, y As Single, srcRect As RectangleF, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

x
Single

所绘制图像的左上角的 x 坐标。

y
Single

所绘制图像的左上角的 y 坐标。

srcRect
RectangleF

RectangleF 结构,它指定 Image 中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建绘制图像左上角的坐标。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

源矩形的大小决定了未缩放的原始图像的哪一部分将绘制到屏幕上。

public:
   void DrawImage2FloatRectF( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create coordinates for upper-left corner of image.
      float x = 100.0F;
      float y = 100.0F;

      // Create rectangle for source image.
      RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, x, y, srcRect, units );
   }
public void DrawImage2FloatRectF(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create coordinates for upper-left corner of image.
    float x = 100.0F;
    float y = 100.0F;
             
    // Create rectangle for source image.
    RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, srcRect, units);
}
Public Sub DrawImage2FloatRectF(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create coordinates for upper-left corner of image.
    Dim x As Single = 100.0F
    Dim y As Single = 100.0F

    ' Create rectangle for source image.
    Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, srcRect, units)
End Sub

注解

Image存储像素宽度的值和水平分辨率的值 (每英寸点) 。 图像的物理宽度(以英寸为单位)是像素宽度除以水平分辨率。 例如,像素宽度为 360、水平分辨率为每英寸 72 点的图像的物理宽度为 5 英寸。 类似的备注适用于像素高度和物理高度。

此方法使用图像的物理大小绘制图像的一部分,因此,无论显示设备) 分辨率 (每英寸点数如何,图像部分都将具有正确的英寸大小。 例如,假设图像部分的像素宽度为 216,水平分辨率为每英寸 72 点。 如果调用此方法在分辨率为每英寸 96 点的设备上绘制该图像部分,则呈现的图像部分的像素宽度将 (216/72) *96 = 288。

另请参阅

适用于

DrawImage(Image, Effect, RectangleF, Matrix, GraphicsUnit, ImageAttributes)

Source:
Graphics.cs
public void DrawImage (System.Drawing.Image image, System.Drawing.Imaging.Effects.Effect effect, System.Drawing.RectangleF srcRect = default, System.Drawing.Drawing2D.Matrix? transform = default, System.Drawing.GraphicsUnit srcUnit = System.Drawing.GraphicsUnit.Pixel, System.Drawing.Imaging.ImageAttributes? imageAttr = default);
member this.DrawImage : System.Drawing.Image * System.Drawing.Imaging.Effects.Effect * System.Drawing.RectangleF * System.Drawing.Drawing2D.Matrix * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, effect As Effect, Optional srcRect As RectangleF = Nothing, Optional transform As Matrix = Nothing, Optional srcUnit As GraphicsUnit = System.Drawing.GraphicsUnit.Pixel, Optional imageAttr As ImageAttributes = Nothing)

参数

image
Image
effect
Effect
srcRect
RectangleF
transform
Matrix
srcUnit
GraphicsUnit
imageAttr
ImageAttributes

适用于

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort)

参数

image
Image

要绘制的 Image

destPoints
Point[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
Rectangle

Rectangle 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法的执行。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;定义很简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 示例main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例:

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建用于定义绘制图像的平行四边形的点。

  • 创建一个矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建用于绘制调整图像的附加平行四边形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始的、未调整的平行四边形,位置将定位在屏幕上的图像,矩形的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

由于此示例使用不传递参数的 callBackData 重载,因此 Graphics.DrawImageAbort 回调返回 true,这会导致 DrawImage 方法结束,并且示例中包含的异常处理代码将输出异常文本,而不是绘制图像。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback1( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageParaRectAttribAbort( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback1 );

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing original image.
      Point ulCorner = Point(100,100);
      Point urCorner = Point(550,100);
      Point llCorner = Point(150,250);
      array<Point>^ destPara1 = {ulCorner,urCorner,llCorner};

      // Create rectangle for source image.
      Rectangle srcRect = Rectangle(50,50,150,150);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destPara1, srcRect, units );

      // Create parallelogram for drawing adjusted image.
      Point ulCorner2 = Point(325,100);
      Point urCorner2 = Point(550,100);
      Point llCorner2 = Point(375,250);
      array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2};

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw image to screen.
         e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback1(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageParaRectAttribAbort(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback1);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing original image.
    Point ulCorner = new Point(100, 100);
    Point urCorner = new Point(550, 100);
    Point llCorner = new Point(150, 250);
    Point[] destPara1 = {ulCorner, urCorner, llCorner};
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create parallelogram for drawing adjusted image.
    Point ulCorner2 = new Point(325, 100);
    Point urCorner2 = new Point(550, 100);
    Point llCorner2 = new Point(375, 250);
    Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw image to screen.
            e.Graphics.DrawImage(
                newImage,
                destPara2,
                srcRect,
                units,
                imageAttr,
                imageCallback);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback1(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageParaRectAttribAbort(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback1)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing original image.
    Dim ulCorner As New Point(100, 100)
    Dim urCorner As New Point(550, 100)
    Dim llCorner As New Point(150, 250)
    Dim destPara1 As Point() = {ulCorner, urCorner, llCorner}

    ' Create rectangle for source image.
    Dim srcRect As New Rectangle(50, 50, 150, 150)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units)

    ' Create parallelogram for drawing adjusted image.
    Dim ulCorner2 As New Point(325, 100)
    Dim urCorner2 As New Point(550, 100)
    Dim llCorner2 As New Point(375, 250)
    Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2}

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw image to screen.
        e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
        imageAttr, imageCallback)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应 参数指定的 destPoints 平行四边形。

使用 callback 参数的此重载提供了在根据应用程序确定的条件启动图像后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘制。

另请参阅

适用于

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort)

参数

image
Image

要绘制的 Image

destPoints
PointF[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
RectangleF

RectangleF 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法的执行。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;定义很简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 示例main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建用于定义绘制图像的平行四边形的点。

  • 创建一个矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建用于绘制调整图像的附加平行四边形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始的、未调整的平行四边形,位置将定位在屏幕上的图像,矩形的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

由于此示例使用不传递参数的 callBackData 重载,因此 Graphics.DrawImageAbort 回调返回 true,这会导致 DrawImage 方法结束,并且示例中包含的异常处理代码将输出异常文本,而不是绘制图像。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback3( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageParaFRectAttribAbort( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback3 );

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing original image.
      PointF ulCorner1 = PointF(100.0F,100.0F);
      PointF urCorner1 = PointF(325.0F,100.0F);
      PointF llCorner1 = PointF(150.0F,250.0F);
      array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1};

      // Create rectangle for source image.
      RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Create parallelogram for drawing adjusted image.
      PointF ulCorner2 = PointF(325.0F,100.0F);
      PointF urCorner2 = PointF(550.0F,100.0F);
      PointF llCorner2 = PointF(375.0F,250.0F);
      array<PointF>^ destPara2 = {ulCorner2,urCorner2,llCorner2};

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destPara1, srcRect, units );

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback3(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageParaFRectAttribAbort(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback3);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing original image.
    PointF ulCorner1 = new PointF(100.0F, 100.0F);
    PointF urCorner1 = new PointF(325.0F, 100.0F);
    PointF llCorner1 = new PointF(150.0F, 250.0F);
    PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1};
             
    // Create rectangle for source image.
    RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Create parallelogram for drawing adjusted image.
    PointF ulCorner2 = new PointF(325.0F, 100.0F);
    PointF urCorner2 = new PointF(550.0F, 100.0F);
    PointF llCorner2 = new PointF(375.0F, 250.0F);
    PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destPara2,
                srcRect,
                units,
                imageAttr,
                imageCallback);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback3(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageParaFRectAttribAbort(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback3)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing original image.
    Dim ulCorner1 As New PointF(100.0F, 100.0F)
    Dim urCorner1 As New PointF(325.0F, 100.0F)
    Dim llCorner1 As New PointF(150.0F, 250.0F)
    Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1}

    ' Create rectangle for source image.
    Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Create parallelogram for drawing adjusted image.
    Dim ulCorner2 As New PointF(325.0F, 100.0F)
    Dim urCorner2 As New PointF(550.0F, 100.0F)
    Dim llCorner2 As New PointF(375.0F, 250.0F)
    Dim destPara2 As PointF() = {ulCorner2, urCorner2, llCorner2}

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
        imageAttr, imageCallback)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应 参数指定的 destPoints 平行四边形。

使用 callback 参数的此重载提供了在根据应用程序确定的条件启动图像后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘制。

另请参阅

适用于

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback, int callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * int -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As Integer)

参数

image
Image

要绘制的 Image

destPoints
Point[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
Rectangle

Rectangle 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法的执行。

callbackData
Int32

一个值,它为 Graphics.DrawImageAbort 委托指定在检查是否停止执行 DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法时要使用的附加数据。

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;定义很简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 示例main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建用于定义绘制图像的平行四边形的点。

  • 创建一个矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建用于绘制调整图像的附加平行四边形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始的、未调整的平行四边形,位置将定位在屏幕上的图像,矩形的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

由于此示例使用传递 callBackData 参数的重载, Graphics.DrawImageAbort 因此回调返回 false,这会导致 DrawImage 方法继续,并且该示例将调整后的图像绘制到屏幕上。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback2( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageParaRectAttribAbortData( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback2 );
      int imageCallbackData = 1;

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing original image.
      Point ulCorner = Point(100,100);
      Point urCorner = Point(550,100);
      Point llCorner = Point(150,250);
      array<Point>^ destPara1 = {ulCorner,urCorner,llCorner};

      // Create rectangle for source image.
      Rectangle srcRect = Rectangle(50,50,150,150);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destPara1, srcRect, units );

      // Create parallelogram for drawing adjusted image.
      Point ulCorner2 = Point(325,100);
      Point urCorner2 = Point(550,100);
      Point llCorner2 = Point(375,250);
      array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2};

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw image to screen.
         e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback2(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageParaRectAttribAbortData(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback2);
    int imageCallbackData = 1;
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing original image.
    Point ulCorner = new Point(100, 100);
    Point urCorner = new Point(550, 100);
    Point llCorner = new Point(150, 250);
    Point[] destPara1 = {ulCorner, urCorner, llCorner};
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create parallelogram for drawing adjusted image.
    Point ulCorner2 = new Point(325, 100);
    Point urCorner2 = new Point(550, 100);
    Point llCorner2 = new Point(375, 250);
    Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw image to screen.
            e.Graphics.DrawImage(
                newImage,
                destPara2,
                srcRect,
                units,
                imageAttr,
                imageCallback,
                imageCallbackData);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback2(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageParaRectAttribAbortData(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback2)
    Dim imageCallbackData As Integer = 1

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing original image.
    Dim ulCorner As New Point(100, 100)
    Dim urCorner As New Point(550, 100)
    Dim llCorner As New Point(150, 250)
    Dim destPara1 As Point() = {ulCorner, urCorner, llCorner}

    ' Create rectangle for source image.
    Dim srcRect As New Rectangle(50, 50, 150, 150)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units)

    ' Create parallelogram for drawing adjusted image.
    Dim ulCorner2 As New Point(325, 100)
    Dim urCorner2 As New Point(550, 100)
    Dim llCorner2 As New Point(375, 250)
    Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2}

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw image to screen.
        e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
        imageAttr, imageCallback, imageCallbackData)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应 参数指定的 destPoints 平行四边形。

使用 callbackcallbackData 参数的此重载提供了在图像根据应用程序确定的条件和数据启动后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘制。

另请参阅

适用于

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback, int callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * int -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As Integer)

参数

image
Image

要绘制的 Image

destPoints
PointF[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
RectangleF

RectangleF 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法的执行。

callbackData
Int32

一个值,它为 Graphics.DrawImageAbort 委托指定在检查是否停止执行 DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法时要使用的附加数据。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要PaintEventArgse作为 事件处理程序的参数PaPaint。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;定义很简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 示例main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建用于定义绘制图像的平行四边形的点。

  • 创建一个矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建用于绘制调整图像的附加平行四边形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始的、未调整的平行四边形,位置将定位在屏幕上的图像,矩形的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

由于此示例使用传递 callBackData 参数的重载, Graphics.DrawImageAbort 因此回调返回 false,这会导致 DrawImage 方法继续,并且该示例将调整后的图像绘制到屏幕上。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback4( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageParaFRectAttribAbortData( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback4 );
      int imageCallbackData = 1;

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing original image.
      PointF ulCorner1 = PointF(100.0F,100.0F);
      PointF urCorner1 = PointF(325.0F,100.0F);
      PointF llCorner1 = PointF(150.0F,250.0F);
      array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1};

      // Create rectangle for source image.
      RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Create parallelogram for drawing adjusted image.
      PointF ulCorner2 = PointF(325.0F,100.0F);
      PointF urCorner2 = PointF(550.0F,100.0F);
      PointF llCorner2 = PointF(375.0F,250.0F);
      array<PointF>^ destPara2 = {ulCorner2,urCorner2,llCorner2};

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destPara1, srcRect, units );

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback4(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageParaFRectAttribAbortData(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback4);
    int imageCallbackData = 1;
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing original image.
    PointF ulCorner1 = new PointF(100.0F, 100.0F);
    PointF urCorner1 = new PointF(325.0F, 100.0F);
    PointF llCorner1 = new PointF(150.0F, 250.0F);
    PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1};
             
    // Create rectangle for source image.
    RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Create parallelogram for drawing adjusted image.
    PointF ulCorner2 = new PointF(325.0F, 100.0F);
    PointF urCorner2 = new PointF(550.0F, 100.0F);
    PointF llCorner2 = new PointF(375.0F, 250.0F);
    PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destPara2,
                srcRect,
                units,
                imageAttr,
                imageCallback,
                imageCallbackData);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback4(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageParaFRectAttribAbortData(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback4)
    Dim imageCallbackData As Integer = 1

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing original image.
    Dim ulCorner1 As New PointF(100.0F, 100.0F)
    Dim urCorner1 As New PointF(325.0F, 100.0F)
    Dim llCorner1 As New PointF(150.0F, 250.0F)
    Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1}

    ' Create rectangle for source image.
    Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Create parallelogram for drawing adjusted image.
    Dim ulCorner2 As New PointF(325.0F, 100.0F)
    Dim urCorner2 As New PointF(550.0F, 100.0F)
    Dim llCorner2 As New PointF(375.0F, 250.0F)
    Dim destPara2 As PointF() = {ulCorner2, urCorner2, llCorner2}

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
        imageAttr, imageCallback, imageCallbackData)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应 参数指定的 destPoints 平行四边形。

使用 callbackcallbackData 参数的此重载提供了在图像根据应用程序确定的条件和数据启动后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘制。

另请参阅

适用于

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Int32

要绘制的源图像部分的左上角的 x 坐标。

srcY
Int32

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Int32

要绘制的源图像部分的宽度。

srcHeight
Int32

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建要在其中绘制图像的目标矩形。

  • 创建源矩形的坐标,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

目标矩形的位置在屏幕上定位图像,源矩形和目标矩形的大小决定了所绘制图像的缩放比例,源矩形的大小决定了原始图像的哪一部分将绘制到屏幕上。

void DrawImageRect4Int( PaintEventArgs^ e )
{
   // Create image.
   Image^ newImage = Image::FromFile( "SampImag.jpg" );

   // Create rectangle for displaying image.
   Rectangle destRect = Rectangle(100,100,450,150);

   // Create coordinates of rectangle for source image.
   int x = 50;
   int y = 50;
   int width = 150;
   int height = 150;
   GraphicsUnit units = GraphicsUnit::Pixel;

   // Draw image to screen.
   e->Graphics->DrawImage( newImage, destRect, x, y, width, height, units );
}
private void DrawImageRect4Int(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying image.
    Rectangle destRect = new Rectangle(100, 100, 450, 150);
             
    // Create coordinates of rectangle for source image.
    int x = 50;
    int y = 50;
    int width = 150;
    int height = 150;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units);
}
Private Sub DrawImageRect4Int(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim destRect As New Rectangle(100, 100, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Integer = 50
    Dim y As Integer = 50
    Dim width As Integer = 150
    Dim height As Integer = 150
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, x, y, width, height, _
    units)
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的image对象的矩形部分。 矩形相对于源图像的左上角。 此部分将缩放为适合 参数 destRect 指定的矩形。

另请参阅

适用于

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit, imageAttr As ImageAttributes)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Int32

要绘制的源图像部分的左上角的 x 坐标。

srcY
Int32

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Int32

要绘制的源图像部分的宽度。

srcHeight
Int32

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建要在其中绘制图像的目标矩形。

  • 创建源矩形的坐标,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建一个用于绘制调整图像的附加矩形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始、未调整的目标矩形,位置将定位到屏幕上的图像,源矩形和目标矩形的大小决定所绘制图像的缩放比例,源矩形的大小确定原始图像的哪一部分将绘制到屏幕。

void DrawImageRect4IntAtrrib( PaintEventArgs^ e )
{
   // Create image.
   Image^ newImage = Image::FromFile( "SampImag.jpg" );

   // Create rectangle for displaying original image.
   Rectangle destRect1 = Rectangle(100,25,450,150);

   // Create coordinates of rectangle for source image.
   int x = 50;
   int y = 50;
   int width = 150;
   int height = 150;
   GraphicsUnit units = GraphicsUnit::Pixel;

   // Draw original image to screen.
   e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

   // Create rectangle for adjusted image.
   Rectangle destRect2 = Rectangle(100,175,450,150);

   // Create image attributes and set large gamma.
   ImageAttributes^ imageAttr = gcnew ImageAttributes;
   imageAttr->SetGamma( 4.0F );

   // Draw adjusted image to screen.
   e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr );
}
private void DrawImageRect4IntAtrrib(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    int x = 50;
    int y = 50;
    int width = 150;
    int height = 150;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr);
}
Private Sub DrawImageRect4IntAtrrib(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Integer = 50
    Dim y As Integer = 50
    Dim width As Integer = 150
    Dim height As Integer = 150
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, _
    units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)

    ' Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, _
    units, imageAttr)
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的image对象的矩形部分。 矩形相对于源图像的左上角。 此部分将缩放为适合 参数 destRect 指定的矩形。

另请参阅

适用于

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Single, srcY As Single, srcWidth As Single, srcHeight As Single, srcUnit As GraphicsUnit, imageAttrs As ImageAttributes)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Single

要绘制的源图像部分的左上角的 x 坐标。

srcY
Single

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Single

要绘制的源图像部分的宽度。

srcHeight
Single

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

imageAttrs
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建要在其中绘制图像的目标矩形。

  • 创建源矩形的坐标,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建一个用于绘制调整图像的附加矩形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始、未调整的目标矩形,位置将定位到屏幕上的图像,源矩形和目标矩形的大小决定所绘制图像的缩放比例,源矩形的大小确定原始图像的哪一部分将绘制到屏幕。

private:
   void DrawImageRect4FloatAttrib( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying original image.
      Rectangle destRect1 = Rectangle(100,25,450,150);

      // Create coordinates of rectangle for source image.
      float x = 50.0F;
      float y = 50.0F;
      float width = 150.0F;
      float height = 150.0F;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

      // Create rectangle for adjusted image.
      Rectangle destRect2 = Rectangle(100,175,450,150);

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );

      // Draw adjusted image to screen.
      e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr );
   }
private void DrawImageRect4FloatAttrib(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    float x = 50.0F;
    float y = 50.0F;
    float width = 150.0F;
    float height = 150.0F;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr);
}
Private Sub DrawImageRect4FloatAttrib(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Single = 50.0F
    Dim y As Single = 50.0F
    Dim width As Single = 150.0F
    Dim height As Single = 150.0F
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, _
    height, units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)

    ' Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, _
    units, imageAttr)
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的image对象的矩形部分。 矩形相对于源图像的左上角。 此部分将缩放为适合 参数 destRect 指定的矩形。

另请参阅

适用于

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Int32

要绘制的源图像部分的左上角的 x 坐标。

srcY
Int32

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Int32

要绘制的源图像部分的宽度。

srcHeight
Int32

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法的执行。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;定义很简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 示例main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建定义要在其中绘制图像的目标矩形的点。

  • 创建源矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建一个用于绘制调整图像的附加目标矩形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始的、未调整的目标矩形,位置将定位到屏幕上的图像,源矩形的大小以及目标矩形的大小和形状决定了所绘制图像的缩放比例。

由于此示例使用不传递 callBackData 参数的重载, Graphics.DrawImageAbort 因此回调返回 true,这会导致 DrawImage 方法结束,而示例中包含的异常处理代码打印异常文本,而不是绘制图像。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback5( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageRect4IntAtrribAbort( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback5 );

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying original image.
      Rectangle destRect1 = Rectangle(100,25,450,150);

      // Create coordinates of rectangle for source image.
      int x = 50;
      int y = 50;
      int width = 150;
      int height = 150;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

      // Create rectangle for adjusted image.
      Rectangle destRect2 = Rectangle(100,175,450,150);

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback5(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageRect4IntAtrribAbort(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback5);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    int x = 50;
    int y = 50;
    int width = 150;
    int height = 150;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destRect2,
                x, y,
                width, height,
                units,
                imageAttr,
                imageCallback);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback5(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageRect4IntAtrribAbort(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback5)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Integer = 50
    Dim y As Integer = 50
    Dim width As Integer = 150
    Dim height As Integer = 150
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, _
    units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
        height, units, imageAttr, imageCallback)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的 image 对象的矩形部分。 矩形相对于源图像的左上角。 此部分经过缩放以适应对象指定的 destRect 矩形。

使用 callback 参数的此重载提供了在图像根据应用程序确定的条件启动后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘图。

另请参阅

适用于

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Single, srcY As Single, srcWidth As Single, srcHeight As Single, srcUnit As GraphicsUnit, imageAttrs As ImageAttributes, callback As Graphics.DrawImageAbort)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Single

要绘制的源图像部分的左上角的 x 坐标。

srcY
Single

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Single

要绘制的源图像部分的宽度。

srcHeight
Single

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

imageAttrs
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法的执行。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;该定义非常简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 该示例的main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义要在其中绘制图像的目标矩形的点。

  • 创建源矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建一个用于绘制调整后图像的附加目标矩形。

  • 创建并设置调整后图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕上。

对于原始、未调整的目标矩形,该位置将定位在屏幕上的图像,源矩形的大小以及目标矩形的大小和形状决定了绘制的图像的缩放比例。

由于此示例使用不传递 callBackData 参数的重载, Graphics.DrawImageAbort 因此回调返回 true,这会导致 DrawImage 方法结束,而示例中包含的异常处理代码打印异常文本,而不是绘制图像。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback7( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageRect4FloatAttribAbort( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback7 );

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying original image.
      Rectangle destRect1 = Rectangle(100,25,450,150);

      // Create coordinates of rectangle for source image.
      float x = 50.0F;
      float y = 50.0F;
      float width = 150.0F;
      float height = 150.0F;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

      // Create rectangle for adjusted image.
      Rectangle destRect2 = Rectangle(100,175,450,150);

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback7(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageRect4FloatAttribAbort(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback7);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    float x = 50.0F;
    float y = 50.0F;
    float width = 150.0F;
    float height = 150.0F;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destRect2,
                x, y,
                width, height,
                units,
                imageAttr,
                imageCallback);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback7(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageRect4FloatAttribAbort(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback7)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Single = 50.0F
    Dim y As Single = 50.0F
    Dim width As Single = 150.0F
    Dim height As Single = 150.0F
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, _
    height, units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
        height, units, imageAttr, imageCallback)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的 image 对象的矩形部分。 矩形相对于源图像的左上角。 此部分经过缩放以适应 参数 destRect 指定的矩形。

使用 callback 参数的此重载提供了在图像根据应用程序确定的条件启动后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘图。

另请参阅

适用于

DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs, System::Drawing::Graphics::DrawImageAbort ^ callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback, IntPtr callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * nativeint -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit, imageAttrs As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As IntPtr)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Int32

要绘制的源图像部分的左上角的 x 坐标。

srcY
Int32

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Int32

要绘制的源图像部分的宽度。

srcHeight
Int32

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

imageAttrs
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) 方法的执行。

callbackData
IntPtr

nativeint

一个值,它为 Graphics.DrawImageAbort 委托指定在检查是否停止执行 DrawImage 方法时要使用的附加数据。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;该定义非常简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 该示例的main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义要在其中绘制图像的目标矩形的点。

  • 创建源矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建一个用于绘制调整后图像的附加目标矩形。

  • 创建并设置调整后图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕上。

对于原始、未调整的目标矩形,该位置将定位在屏幕上的图像,源矩形的大小以及目标矩形的大小和形状决定了绘制的图像的缩放比例。

由于此示例使用传递 callBackData 参数的重载,因此 Graphics.DrawImageAbort 回调将返回 false,这会导致 DrawImage 方法继续,并且该示例将调整后的图像绘制到屏幕上。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback6( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

private:
   void DrawImageRect4IntAtrribAbortData( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback6 );
      IntPtr imageCallbackData = IntPtr(1);

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying original image.
      Rectangle destRect1 = Rectangle(100,25,450,150);

      // Create coordinates of rectangle for source image.
      int x = 50;
      int y = 50;
      int width = 150;
      int height = 150;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

      // Create rectangle for adjusted image.
      Rectangle destRect2 = Rectangle(100,175,450,150);

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback6(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
private void DrawImageRect4IntAtrribAbortData(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback6);
    IntPtr imageCallbackData = new IntPtr(1);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    int x = 50;
    int y = 50;
    int width = 150;
    int height = 150;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destRect2,
                x, y,
                width, height,
                units,
                imageAttr,
                imageCallback,
                imageCallbackData);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback6(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Private Sub DrawImageRect4IntAtrribAbortData(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback6)
    Dim imageCallbackData As New IntPtr(1)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Integer = 50
    Dim y As Integer = 50
    Dim width As Integer = 150
    Dim height As Integer = 150
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, _
    units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
        height, units, imageAttr, imageCallback, imageCallbackData)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的 image 对象的矩形部分。 矩形相对于源图像的左上角。 此部分经过缩放以适应 参数 destRect 指定的矩形。

使用 callbackcallbackData 参数的这种重载提供了在图像根据应用程序确定的条件和数据启动后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘图。

另请参阅

适用于

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs, System::Drawing::Graphics::DrawImageAbort ^ callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback, IntPtr callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * nativeint -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Single, srcY As Single, srcWidth As Single, srcHeight As Single, srcUnit As GraphicsUnit, imageAttrs As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As IntPtr)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Single

要绘制的源图像部分的左上角的 x 坐标。

srcY
Single

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Single

要绘制的源图像部分的宽度。

srcHeight
Single

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

imageAttrs
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委托,它指定在绘制图像期间要调用的方法。 此方法被频繁调用以检查是否根据应用程序确定的条件停止 DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) 方法的执行。

callbackData
IntPtr

nativeint

一个值,它为 Graphics.DrawImageAbort 委托指定在检查是否停止执行 DrawImage 方法时要使用的附加数据。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 代码首先定义委托的 Graphics.DrawImageAbort 回调方法;该定义非常简单,只是测试方法是否 DrawImage 使用 null callBackData 参数调用它。 该示例的main正文执行以下操作:

  • 创建回调方法的 Graphics.DrawImageAbort 实例。

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义要在其中绘制图像的目标矩形的点。

  • 创建源矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建一个用于绘制调整后图像的附加目标矩形。

  • 创建并设置调整后图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕上。

对于原始、未调整的目标矩形,该位置将定位在屏幕上的图像,源矩形的大小以及目标矩形的大小和形状决定了绘制的图像的缩放比例。

由于此示例使用传递 callBackData 参数的重载,因此 Graphics.DrawImageAbort 回调将返回 false,这会导致 DrawImage 方法继续,并且该示例将调整后的图像绘制到屏幕上。

   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback8( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

public:
   void DrawImageRect4FloatAttribAbortData( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback8 );
      IntPtr imageCallbackData = IntPtr(1);

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying original image.
      Rectangle destRect1 = Rectangle(100,25,450,150);

      // Create coordinates of rectangle for source image.
      float x = 50.0F;
      float y = 50.0F;
      float width = 150.0F;
      float height = 150.0F;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

      // Create rectangle for adjusted image.
      Rectangle destRect2 = Rectangle(100,175,450,150);

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );

      // Draw adjusted image to screen.
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }

// Define DrawImageAbort callback method.
private bool DrawImageCallback8(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
public void DrawImageRect4FloatAttribAbortData(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback8);
    IntPtr imageCallbackData = new IntPtr(1);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    float x = 50.0F;
    float y = 50.0F;
    float width = 150.0F;
    float height = 150.0F;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destRect2,
                x, y,
                width, height,
                units,
                imageAttr,
                imageCallback,
                imageCallbackData);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}
Private Function DrawImageCallback8(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Public Sub DrawImageRect4FloatAttribAbortData(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback8)
    Dim imageCallbackData As New IntPtr(1)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Single = 50.0F
    Dim y As Single = 50.0F
    Dim width As Single = 150.0F
    Dim height As Single = 150.0F
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, _
    height, units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)

    ' Draw adjusted image to screen.
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
        height, units, imageAttr, imageCallback, imageCallbackData)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的 image 对象的矩形部分。 矩形相对于源图像的左上角。 此部分经过缩放以适应 参数 destRect 指定的矩形。

使用 callbackcallbackData 参数的这种重载提供了在图像根据应用程序确定的条件和数据启动后停止绘制图像的方法。 例如,应用程序可以开始绘制大图像,用户可能会在屏幕上滚动图像,在这种情况下,应用程序可能会停止绘图。

另请参阅

适用于

DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Single, srcY As Single, srcWidth As Single, srcHeight As Single, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcX
Single

要绘制的源图像部分的左上角的 x 坐标。

srcY
Single

要绘制的源图像部分的左上角的 y 坐标。

srcWidth
Single

要绘制的源图像部分的宽度。

srcHeight
Single

要绘制的源图像部分的高度。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定用于确定源矩形的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的目标矩形的坐标。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

目标矩形的位置在屏幕上定位图像,源矩形和目标矩形的大小决定了所绘制图像的缩放比例,源矩形的大小决定了原始图像被绘制到屏幕的哪个部分。

private:
   void DrawImageRect4Float( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying image.
      Rectangle destRect = Rectangle(100,100,450,150);

      // Create coordinates of rectangle for source image.
      float x = 50.0F;
      float y = 50.0F;
      float width = 150.0F;
      float height = 150.0F;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destRect, x, y, width, height, units );
   }
private void DrawImageRect4Float(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying image.
    Rectangle destRect = new Rectangle(100, 100, 450, 150);
             
    // Create coordinates of rectangle for source image.
    float x = 50.0F;
    float y = 50.0F;
    float width = 150.0F;
    float height = 150.0F;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units);
}
Private Sub DrawImageRect4Float(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim destRect As New Rectangle(100, 100, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Single = 50.0F
    Dim y As Single = 50.0F
    Dim width As Single = 150.0F
    Dim height As Single = 150.0F
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, x, y, width, height, _
    units)
End Sub

注解

srcXsrcYsrcWidthsrcHeight 参数指定要绘制的 image 对象的矩形部分。 矩形相对于源图像的左上角。 此部分经过缩放以适应 参数 destRect 指定的矩形。

另请参阅

适用于

DrawImage(Image, Int32, Int32, Int32, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, int x, int y, int width, int height);
public void DrawImage (System.Drawing.Image image, int x, int y, int width, int height);
member this.DrawImage : System.Drawing.Image * int * int * int * int -> unit
Public Sub DrawImage (image As Image, x As Integer, y As Integer, width As Integer, height As Integer)

参数

image
Image

要绘制的 Image

x
Int32

所绘制图像的左上角的 x 坐标。

y
Int32

所绘制图像的左上角的 y 坐标。

width
Int32

所绘制图像的宽度。

height
Int32

所绘制图像的高度。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的矩形的位置和大小。

  • 将图像绘制到屏幕。

矩形的位置在屏幕上定位图像,原始图像的大小和矩形的大小决定了绘制的图像的缩放比例。

public:
   void DrawImage4Int( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create coordinates for upper-left corner.
      // of image and for size of image.
      int x = 100;
      int y = 100;
      int width = 450;
      int height = 150;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, x, y, width, height );
   }
public void DrawImage4Int(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create coordinates for upper-left corner.
             
    // of image and for size of image.
    int x = 100;
    int y = 100;
    int width = 450;
    int height = 150;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, width, height);
}
Public Sub DrawImage4Int(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create coordinates for upper-left corner

    ' of image and for size of image.
    Dim x As Integer = 100
    Dim y As Integer = 100
    Dim width As Integer = 450
    Dim height As Integer = 150

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, width, height)
End Sub

注解

xywidthheight 参数定义的矩形确定所绘制图像的位置和大小。

另请参阅

适用于

DrawImage(Image, Single, Single, Single, Single)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, float x, float y, float width, float height);
public void DrawImage (System.Drawing.Image image, float x, float y, float width, float height);
member this.DrawImage : System.Drawing.Image * single * single * single * single -> unit
Public Sub DrawImage (image As Image, x As Single, y As Single, width As Single, height As Single)

参数

image
Image

要绘制的 Image

x
Single

所绘制图像的左上角的 x 坐标。

y
Single

所绘制图像的左上角的 y 坐标。

width
Single

所绘制图像的宽度。

height
Single

所绘制图像的高度。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的矩形的位置和大小。

  • 将图像绘制到屏幕。

矩形的位置在屏幕上定位图像,原始图像的大小和矩形的大小决定了绘制的图像的缩放比例。

public:
   void DrawImage4Float( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create coordinates for upper-left corner.
      // of image and for size of image.
      float x = 100.0F;
      float y = 100.0F;
      float width = 450.0F;
      float height = 150.0F;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, x, y, width, height );
   }
public void DrawImage4Float(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create coordinates for upper-left corner.
             
    // of image and for size of image.
    float x = 100.0F;
    float y = 100.0F;
    float width = 450.0F;
    float height = 150.0F;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, width, height);
}
Public Sub DrawImage4Float(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create coordinates for upper-left corner

    ' of image and for size of image.
    Dim x As Single = 100.0F
    Dim y As Single = 100.0F
    Dim width As Single = 450.0F
    Dim height As Single = 150.0F

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, width, height)
End Sub

注解

xywidthheight 参数定义的矩形确定所绘制图像的位置和大小。

另请参阅

适用于

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit, imageAttr As ImageAttributes)

参数

image
Image

要绘制的 Image

destPoints
PointF[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
RectangleF

RectangleF 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义要在其中绘制图像的目标平行四边形的点。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建用于绘制调整图像的附加平行四边形。

  • 创建并设置调整后图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕上。

对于原始的、未调整的目标平行四边形,该位置在屏幕上定位图像,源矩形的大小以及目标平行四边形的大小和形状决定了所绘制图像的缩放和剪切,矩形的大小决定了原始图像被绘制到屏幕的哪个部分。

void DrawImageParaFRectFAttrib( PaintEventArgs^ e )
{
   // Create image.
   Image^ newImage = Image::FromFile( "SampImag.jpg" );

   // Create parallelogram for drawing original image.
   PointF ulCorner1 = PointF(100.0F,100.0F);
   PointF urCorner1 = PointF(325.0F,100.0F);
   PointF llCorner1 = PointF(150.0F,250.0F);
   array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1};

   // Create rectangle for source image.
   RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
   GraphicsUnit units = GraphicsUnit::Pixel;

   // Create parallelogram for drawing adjusted image.
   PointF ulCorner2 = PointF(325.0F,100.0F);
   PointF urCorner2 = PointF(550.0F,100.0F);
   PointF llCorner2 = PointF(375.0F,250.0F);
   array<PointF>^ destPara2 = {ulCorner2,urCorner2,llCorner2};

   // Draw original image to screen.
   e->Graphics->DrawImage( newImage, destPara1, srcRect, units );

   // Create image attributes and set large gamma.
   ImageAttributes^ imageAttr = gcnew ImageAttributes;
   imageAttr->SetGamma( 4.0F );

   // Draw adjusted image to screen.
   e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr );
}
private void DrawImageParaFRectFAttrib(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing original image.
    PointF ulCorner1 = new PointF(100.0F, 100.0F);
    PointF urCorner1 = new PointF(325.0F, 100.0F);
    PointF llCorner1 = new PointF(150.0F, 250.0F);
    PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1};
             
    // Create rectangle for source image.
    RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Create parallelogram for drawing adjusted image.
    PointF ulCorner2 = new PointF(325.0F, 100.0F);
    PointF urCorner2 = new PointF(550.0F, 100.0F);
    PointF llCorner2 = new PointF(375.0F, 250.0F);
    PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}
Private Sub DrawImageParaFRectFAttrib(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing original image.
    Dim ulCorner1 As New PointF(100.0F, 100.0F)
    Dim urCorner1 As New PointF(325.0F, 100.0F)
    Dim llCorner1 As New PointF(150.0F, 250.0F)
    Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1}

    ' Create rectangle for source image.
    Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Create parallelogram for drawing adjusted image.
    Dim ulCorner2 As New PointF(325.0F, 100.0F)
    Dim urCorner2 As New PointF(550.0F, 100.0F)
    Dim llCorner2 As New PointF(375.0F, 250.0F)
    Dim destPara2 As PointF() = {ulCorner2, urCorner2, llCorner2}

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)

    ' Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
    imageAttr)
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应参数 destPoints 指定的平行四边形。

另请参阅

适用于

DrawImage(Image, Effect)

Source:
Graphics.cs
public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Imaging::Effects::Effect ^ effect);
public void DrawImage (System.Drawing.Image image, System.Drawing.Imaging.Effects.Effect effect);
member this.DrawImage : System.Drawing.Image * System.Drawing.Imaging.Effects.Effect -> unit
Public Sub DrawImage (image As Image, effect As Effect)

参数

image
Image
effect
Effect

适用于

DrawImage(Image, Point)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定的位置使用原始物理大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Point point);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point point);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point -> unit
Public Sub DrawImage (image As Image, point As Point)

参数

image
Image

要绘制的 Image

point
Point

Point 结构,它表示所绘制图像的左上角的位置。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建一个点,用于绘制图像左上角的点。

  • 将未缩放的图像绘制到屏幕。

private:
   void DrawImagePoint( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create Point for upper-left corner of image.
      Point ulCorner = Point(100,100);

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, ulCorner );
   }
private void DrawImagePoint(PaintEventArgs e)
{         
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create Point for upper-left corner of image.
    Point ulCorner = new Point(100, 100);
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, ulCorner);
}
Private Sub DrawImagePoint(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create Point for upper-left corner of image.
    Dim ulCorner As New Point(100, 100)

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, ulCorner)
End Sub

注解

存储 Image 像素宽度的值和水平分辨率的值 (每英寸点) 。 图像的物理宽度(以英寸为单位)是像素宽度除以水平分辨率。 例如,像素宽度为 216 且水平分辨率为每英寸 72 点的图像的物理宽度为 3 英寸。 类似的注释适用于像素高度和物理高度。

此方法使用其物理大小绘制图像,因此无论显示设备的分辨率 (点数) ,图像都将具有正确的大小(以英寸为单位)。 例如,假设图像的像素宽度为 216,水平分辨率为每英寸 72 点。 如果调用此方法在分辨率为每英寸 96 点的设备上绘制该图像,则呈现的图像的像素宽度将 (216/72) *96 = 288。

另请参阅

适用于

DrawImage(Image, Point[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定形状和大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] -> unit
Public Sub DrawImage (image As Image, destPoints As Point())

参数

image
Image

要绘制的 Image

destPoints
Point[]

由三个 Point 结构组成的数组,这三个结构定义一个平行四边形。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义用于绘制图像的平行四边形的点。

  • 将图像绘制到屏幕。

平行四边形的位置在屏幕上定位图像,原始图像的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

private:
   void DrawImagePara( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing image.
      Point ulCorner = Point(100,100);
      Point urCorner = Point(550,100);
      Point llCorner = Point(150,250);
      array<Point>^ destPara = {ulCorner,urCorner,llCorner};

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destPara );
   }
private void DrawImagePara(PaintEventArgs e)
{
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing image.
    Point ulCorner = new Point(100, 100);
    Point urCorner = new Point(550, 100);
    Point llCorner = new Point(150, 250);
    Point[] destPara = {ulCorner, urCorner, llCorner};
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara);
}
Private Sub DrawImagePara(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing image.
    Dim ulCorner As New Point(100, 100)
    Dim urCorner As New Point(550, 100)
    Dim llCorner As New Point(150, 250)
    Dim destPara As Point() = {ulCorner, urCorner, llCorner}

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara)
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 Point 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数表示 image 的图像经过缩放和剪切,以适应参数指定的 destPoints 平行四边形的形状。

另请参阅

适用于

DrawImage(Image, PointF)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定的位置使用原始物理大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::PointF point);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF point);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF -> unit
Public Sub DrawImage (image As Image, point As PointF)

参数

image
Image

要绘制的 Image

point
PointF

PointF 结构,它指定所绘制图像的左上角。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建一个点,用于绘制图像左上角的点。

  • 将未缩放的图像绘制到屏幕。

private:
   void DrawImagePointF( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create point for upper-left corner of image.
      PointF ulCorner = PointF(100.0F,100.0F);

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, ulCorner );
   }
private void DrawImagePointF(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create point for upper-left corner of image.
    PointF ulCorner = new PointF(100.0F, 100.0F);
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, ulCorner);
}
Private Sub DrawImagePointF(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create point for upper-left corner of image.
    Dim ulCorner As New PointF(100.0F, 100.0F)

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, ulCorner)
End Sub

注解

存储 Image 像素宽度的值和水平分辨率的值 (每英寸点) 。 图像的物理宽度(以英寸为单位)是像素宽度除以水平分辨率。 例如,像素宽度为 216 且水平分辨率为每英寸 72 点的图像的物理宽度为 3 英寸。 类似的注释适用于像素高度和物理高度。

此方法使用其物理大小绘制图像,因此无论显示设备的分辨率 (点数) ,图像都将具有正确的大小(以英寸为单位)。 例如,假设图像的像素宽度为 216,水平分辨率为每英寸 72 点。 如果调用此方法在分辨率为每英寸 96 点的设备上绘制该图像,则呈现的图像的像素宽度将 (216/72) *96 = 288。

另请参阅

适用于

DrawImage(Image, PointF[])

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定形状和大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] -> unit
Public Sub DrawImage (image As Image, destPoints As PointF())

参数

image
Image

要绘制的 Image

destPoints
PointF[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义用于绘制图像的平行四边形的点。

  • 将图像绘制到屏幕。

平行四边形的位置在屏幕上定位图像,原始图像的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

private:
   void DrawImageParaF( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing image.
      PointF ulCorner = PointF(100.0F,100.0F);
      PointF urCorner = PointF(550.0F,100.0F);
      PointF llCorner = PointF(150.0F,250.0F);
      array<PointF>^ destPara = {ulCorner,urCorner,llCorner};

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destPara );
   }
private void DrawImageParaF(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing image.
    PointF ulCorner = new PointF(100.0F, 100.0F);
    PointF urCorner = new PointF(550.0F, 100.0F);
    PointF llCorner = new PointF(150.0F, 250.0F);
    PointF[] destPara = {ulCorner, urCorner, llCorner};
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara);
}
Private Sub DrawImageParaF(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing image.
    Dim ulCorner As New PointF(100.0F, 100.0F)
    Dim urCorner As New PointF(550.0F, 100.0F)
    Dim llCorner As New PointF(150.0F, 250.0F)
    Dim destPara As PointF() = {ulCorner, urCorner, llCorner}

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara)
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

对象表示 image 的图像经过缩放和剪切,以适应 参数指定的 destPoints 平行四边形的形状。

另请参阅

适用于

DrawImage(Image, Rectangle)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image

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

参数

image
Image

要绘制的 Image

rect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的矩形。

  • 将图像绘制到屏幕。

矩形的位置在屏幕上定位图像,原始图像的大小和矩形的大小决定了绘制的图像的缩放比例。

private:
   void DrawImageRect( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying image.
      Rectangle destRect = Rectangle(100,100,450,150);

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destRect );
   }
private void DrawImageRect(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying image.
    Rectangle destRect = new Rectangle(100, 100, 450, 150);
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect);
}
Private Sub DrawImageRect(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim destRect As New Rectangle(100, 100, 450, 150)

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect)
End Sub

注解

对象表示 image 的图像将缩放到矩形的尺寸 rect

另请参阅

适用于

DrawImage(Image, RectangleF)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image

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

参数

image
Image

要绘制的 Image

rect
RectangleF

RectangleF 结构,它指定所绘制图像的位置和大小。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的矩形。

  • 将图像绘制到屏幕。

矩形的位置在屏幕上定位图像,图像的原始大小和矩形的大小决定了绘制的图像的缩放比例。

public:
   void DrawImageRectF( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying image.
      RectangleF rect = RectangleF(100.0F,100.0F,450.0F,150.0F);

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, rect );
   }
public void DrawImageRectF(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying image.
    RectangleF rect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F);
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, rect);
}
Public Sub DrawImageRectF(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim rect As New RectangleF(100.0F, 100.0F, 450.0F, 150.0F)

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, rect)
End Sub

注解

对象表示 image 的图像将缩放到矩形的尺寸 rect

另请参阅

适用于

DrawImage(Image, Int32, Int32, Rectangle, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定的位置绘制图像的一部分。

public:
 void DrawImage(System::Drawing::Image ^ image, int x, int y, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, int x, int y, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * int * int * System.Drawing.Rectangle * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, x As Integer, y As Integer, srcRect As Rectangle, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

x
Int32

所绘制图像的左上角的 x 坐标。

y
Int32

所绘制图像的左上角的 y 坐标。

srcRect
Rectangle

Rectangle 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建绘制图像左上角的坐标。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

源矩形的大小决定了未缩放的原始图像的哪个部分将绘制到屏幕上。

public:
   void DrawImage2IntRect( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create coordinates for upper-left corner of image.
      int x = 100;
      int y = 100;

      // Create rectangle for source image.
      Rectangle srcRect = Rectangle(50,50,150,150);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, x, y, srcRect, units );
   }
public void DrawImage2IntRect(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create coordinates for upper-left corner of image.
    int x = 100;
    int y = 100;
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, srcRect, units);
}
Public Sub DrawImage2IntRect(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create coordinates for upper-left corner of image.
    Dim x As Integer = 100
    Dim y As Integer = 100

    ' Create rectangle for source image.
    Dim srcRect As New Rectangle(50, 50, 150, 150)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y, srcRect, units)
End Sub

注解

存储 Image 像素宽度的值和水平分辨率的值 (每英寸点) 。 图像的物理宽度(以英寸为单位)是像素宽度除以水平分辨率。 例如,像素宽度为 360 且水平分辨率为每英寸 72 点的图像的物理宽度为 5 英寸。 类似的注释适用于像素高度和物理高度。

此方法使用图像的物理大小绘制图像的一部分,因此无论显示设备的分辨率 (点/英寸) ,图像部分都将具有正确的大小(以英寸为单位)。 例如,假设图像部分的像素宽度为 216,水平分辨率为每英寸 72 点。 如果调用此方法在分辨率为每英寸 96 点的设备上绘制该图像部分,则呈现的图像部分的像素宽度将 (216/72) *96 = 288。

另请参阅

适用于

DrawImage(Image, Single, Single)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定的位置使用原始物理大小绘制指定的 Image

public:
 void DrawImage(System::Drawing::Image ^ image, float x, float y);
public void DrawImage (System.Drawing.Image image, float x, float y);
member this.DrawImage : System.Drawing.Image * single * single -> unit
Public Sub DrawImage (image As Image, x As Single, y As Single)

参数

image
Image

要绘制的 Image

x
Single

所绘制图像的左上角的 x 坐标。

y
Single

所绘制图像的左上角的 y 坐标。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要绘制图像左上角的点的坐标。

  • 将未缩放的图像绘制到屏幕。

public:
   void DrawImage2Float( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create coordinates for upper-left corner of image.
      float x = 100.0F;
      float y = 100.0F;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, x, y );
   }
public void DrawImage2Float(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create coordinates for upper-left corner of image.
    float x = 100.0F;
    float y = 100.0F;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y);
}
Public Sub DrawImage2Float(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create coordinates for upper-left corner of image.
    Dim x As Single = 100.0F
    Dim y As Single = 100.0F

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y)
End Sub

注解

存储 Image 像素宽度的值和水平分辨率的值 (每英寸点) 。 图像的物理宽度(以英寸为单位)是像素宽度除以水平分辨率。 例如,像素宽度为 216 且水平分辨率为每英寸 72 点的图像的物理宽度为 3 英寸。 类似的注释适用于像素高度和物理高度。

此方法使用其物理大小绘制图像,因此无论显示设备的分辨率 (点数) ,图像都将具有正确的大小(以英寸为单位)。 例如,假设图像的像素宽度为 216,水平分辨率为每英寸 72 点。 如果调用此方法在分辨率为每英寸 96 点的设备上绘制该图像,则呈现的图像的像素宽度将 (216/72) *96 = 288。

另请参阅

适用于

DrawImage(Image, Point[], Rectangle, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

destPoints
Point[]

由三个 Point 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
Rectangle

Rectangle 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义用于绘制图像的平行四边形的点。

  • 创建一个矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将图像绘制到屏幕。

平行四边形的位置在屏幕上定位图像,矩形的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

private:
   void DrawImageParaRect( PaintEventArgs^ e )
   {

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing image.
      Point ulCorner = Point(100,100);
      Point urCorner = Point(325,100);
      Point llCorner = Point(150,250);
      array<Point>^ destPara = {ulCorner,urCorner,llCorner};

      // Create rectangle for source image.
      Rectangle srcRect = Rectangle(50,50,150,150);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destPara, srcRect, units );
   }
private void DrawImageParaRect(PaintEventArgs e)
{
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing image.
    Point ulCorner = new Point(100, 100);
    Point urCorner = new Point(325, 100);
    Point llCorner = new Point(150, 250);
    Point[] destPara = {ulCorner, urCorner, llCorner};
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara, srcRect, units);
}
Private Sub DrawImageParaRect(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing image.
    Dim ulCorner As New Point(100, 100)
    Dim urCorner As New Point(325, 100)
    Dim llCorner As New Point(150, 250)
    Dim destPara As Point() = {ulCorner, urCorner, llCorner}

    ' Create rectangle for source image.
    Dim srcRect As New Rectangle(50, 50, 150, 150)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara, srcRect, units)
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 Point 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应参数 destPoints 指定的平行四边形。

另请参阅

适用于

DrawImage(Image, PointF[], RectangleF, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

destPoints
PointF[]

由三个 PointF 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
RectangleF

RectangleF 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建用于定义要在其中绘制图像的目标平行四边形的点。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

目标平行四边形的位置在屏幕上定位图像、源矩形的大小以及目标平行四边形的大小和形状决定了所绘制图像的缩放比例和剪切,矩形的大小决定了原始图像被绘制到屏幕上的哪个部分。

private:
   void DrawImageParaFRectF( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing image.
      PointF ulCorner = PointF(100.0F,100.0F);
      PointF urCorner = PointF(550.0F,100.0F);
      PointF llCorner = PointF(150.0F,250.0F);
      array<PointF>^ destPara = {ulCorner,urCorner,llCorner};

      // Create rectangle for source image.
      RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destPara, srcRect, units );
   }
private void DrawImageParaFRectF(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing image.
    PointF ulCorner = new PointF(100.0F, 100.0F);
    PointF urCorner = new PointF(550.0F, 100.0F);
    PointF llCorner = new PointF(150.0F, 250.0F);
    PointF[] destPara = {ulCorner, urCorner, llCorner};
             
    // Create rectangle for source image.
    RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara, srcRect, units);
}
Private Sub DrawImageParaFRectF(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing image.
    Dim ulCorner As New PointF(100.0F, 100.0F)
    Dim urCorner As New PointF(550.0F, 100.0F)
    Dim llCorner As New PointF(150.0F, 250.0F)
    Dim destPara As PointF() = {ulCorner, urCorner, llCorner}

    ' Create rectangle for source image.
    Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destPara, srcRect, units)
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 PointF 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放和剪切,以适应参数 destPoints 指定的平行四边形。

另请参阅

适用于

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * System.Drawing.Rectangle * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcRect As Rectangle, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

destRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcRect
Rectangle

Rectangle 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的目标矩形。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

目标矩形的位置在屏幕上定位图像,源矩形和目标矩形的大小决定了所绘制图像的缩放比例,源矩形的大小决定了原始图像被绘制到屏幕的哪个部分。

private:
   void DrawImageRectRect( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying image.
      Rectangle destRect = Rectangle(100,100,450,150);

      // Create rectangle for source image.
      Rectangle srcRect = Rectangle(50,50,150,150);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destRect, srcRect, units );
   }
private void DrawImageRectRect(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying image.
    Rectangle destRect = new Rectangle(100, 100, 450, 150);
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, srcRect, units);
}
Private Sub DrawImageRectRect(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim destRect As New Rectangle(100, 100, 450, 150)

    ' Create rectangle for source image.
    Dim srcRect As New Rectangle(50, 50, 150, 150)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, srcRect, units)
End Sub

注解

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放以适应 参数 destRect 指定的矩形。

另请参阅

适用于

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置并且按指定大小绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, System::Drawing::RectangleF destRect, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.RectangleF * System.Drawing.RectangleF * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As RectangleF, srcRect As RectangleF, srcUnit As GraphicsUnit)

参数

image
Image

要绘制的 Image

destRect
RectangleF

RectangleF 结构,它指定所绘制图像的位置和大小。 将图像进行缩放以适合该矩形。

srcRect
RectangleF

RectangleF 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 此代码执行以下操作:

  • 从示例文件夹中的 JPEG 文件 SampImag.jpg 创建映像。

  • 创建要在其中绘制图像的目标矩形。

  • 创建一个源矩形,从中提取图像的一部分。

  • 将源矩形的度量单位设置为像素。

  • 将图像绘制到屏幕。

目标矩形的位置在屏幕上定位图像,源矩形和目标矩形的大小决定了所绘制图像的缩放比例,源矩形的大小决定了原始图像被绘制到屏幕的哪个部分。

public:
   void DrawImageRectFRectF( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying image.
      RectangleF destRect = RectangleF(100.0F,100.0F,450.0F,150.0F);

      // Create rectangle for source image.
      RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, destRect, srcRect, units );
   }
public void DrawImageRectFRectF(PaintEventArgs e)
{
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying image.
    RectangleF destRect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F);
             
    // Create rectangle for source image.
    RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, srcRect, units);
}
Public Sub DrawImageRectFRectF(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying image.
    Dim destRect As New RectangleF(100.0F, 100.0F, 450.0F, 150.0F)

    ' Create rectangle for source image.
    Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, destRect, srcRect, units)
End Sub

注解

参数 srcRect 指定要绘制的 image 对象的矩形部分。 此部分经过缩放以适应 参数 destRect 指定的矩形。

另请参阅

适用于

DrawImage(Image, Int32, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在由坐标对指定的位置,使用图像的原始物理大小绘制指定的图像。

public:
 void DrawImage(System::Drawing::Image ^ image, int x, int y);
public void DrawImage (System.Drawing.Image image, int x, int y);
member this.DrawImage : System.Drawing.Image * int * int -> unit
Public Sub DrawImage (image As Image, x As Integer, y As Integer)

参数

image
Image

要绘制的 Image

x
Int32

所绘制图像的左上角的 x 坐标。

y
Int32

所绘制图像的左上角的 y 坐标。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 从示例文件夹中 SampImag.jpg JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建绘制图像左上角的点的坐标。

  • 绘制未缩放的图像。

public:
   void DrawImage2Int( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create coordinates for upper-left corner of image.
      int x = 100;
      int y = 100;

      // Draw image to screen.
      e->Graphics->DrawImage( newImage, x, y );
   }
public void DrawImage2Int(PaintEventArgs e)
{
                
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
                
    // Create coordinates for upper-left corner of image.
    int x = 100;
    int y = 100;
                
    // Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y);
}
Public Sub DrawImage2Int(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create coordinates for upper-left corner of image.
    Dim x As Integer = 100
    Dim y As Integer = 100

    ' Draw image to screen.
    e.Graphics.DrawImage(newImage, x, y)
End Sub

注解

Image存储像素宽度的值和水平分辨率的值 (每英寸点) 。 图像的物理宽度(以英寸为单位)是像素宽度除以水平分辨率。 例如,像素宽度为 216、水平分辨率为每英寸 72 点的图像的物理宽度为 3 英寸。 类似的备注适用于像素高度和物理高度。

方法 DrawImage 使用其物理大小绘制图像,因此无论显示设备) 分辨率 (每英寸点数如何,图像都将具有正确的英寸大小。 例如,假设图像的像素宽度为 216,水平分辨率为每英寸 72 点。 如果调用 DrawImage 以在分辨率为每英寸 96 点的设备上绘制该图像,则呈现的图像的像素宽度将 (216/72) *96 = 288。

另请参阅

适用于

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

在指定位置绘制指定的 Image 的指定部分。

public:
 void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit, imageAttr As ImageAttributes)

参数

image
Image

要绘制的 Image

destPoints
Point[]

由三个 Point 结构组成的数组,这三个结构定义一个平行四边形。

srcRect
Rectangle

Rectangle 结构,它指定 image 对象中要绘制的部分。

srcUnit
GraphicsUnit

GraphicsUnit 枚举的成员,它指定 srcRect 参数所用的度量单位。

imageAttr
ImageAttributes

ImageAttributes,它指定 image 对象的重新着色和伽玛信息。

例外

imagenull

示例

下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:

  • 从 JPEG 文件创建图像,SampImag.jpg 示例的 文件夹中。

  • 创建用于定义绘制图像的平行四边形的点。

  • 创建一个矩形以选择要绘制的图像部分。

  • 将图形绘制单位设置为像素。

  • 将原始图像绘制到屏幕。

  • 创建用于绘制调整图像的附加平行四边形。

  • 创建并设置调整后的图像的属性,以具有比平常更大的伽玛值。

  • 将调整后的图像绘制到屏幕。

对于原始的、未调整的平行四边形,位置将定位在屏幕上的图像,矩形的大小以及平行四边形的大小和形状决定了所绘制图像的缩放和剪切。

private:
   void DrawImageParaRectAttrib( PaintEventArgs^ e )
   {
      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create parallelogram for drawing image.
      Point ulCorner1 = Point(100,100);
      Point urCorner1 = Point(325,100);
      Point llCorner1 = Point(150,250);
      array<Point>^ destPara1 = {ulCorner1,urCorner1,llCorner1};

      // Create rectangle for source image.
      Rectangle srcRect = Rectangle(50,50,150,150);
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destPara1, srcRect, units );

      // Create parallelogram for drawing adjusted image.
      Point ulCorner2 = Point(325,100);
      Point urCorner2 = Point(550,100);
      Point llCorner2 = Point(375,250);
      array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2};

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );

      // Draw adjusted image to screen.
      e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr );
   }
private void DrawImageParaRectAttrib(PaintEventArgs e)
{
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing image.
    Point ulCorner1 = new Point(100, 100);
    Point urCorner1 = new Point(325, 100);
    Point llCorner1 = new Point(150, 250);
    Point[] destPara1 = {ulCorner1, urCorner1, llCorner1};
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create parallelogram for drawing adjusted image.
    Point ulCorner2 = new Point(325, 100);
    Point urCorner2 = new Point(550, 100);
    Point llCorner2 = new Point(375, 250);
    Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}
Private Sub DrawImageParaRectAttrib(ByVal e As PaintEventArgs)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create parallelogram for drawing image.
    Dim ulCorner1 As New Point(100, 100)
    Dim urCorner1 As New Point(325, 100)
    Dim llCorner1 As New Point(150, 250)
    Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}

    ' Create rectangle for source image.
    Dim srcRect As New Rectangle(50, 50, 150, 150)
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units)

    ' Create parallelogram for drawing adjusted image.
    Dim ulCorner2 As New Point(325, 100)
    Dim urCorner2 As New Point(550, 100)
    Dim llCorner2 As New Point(375, 250)
    Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2}

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)

    ' Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
    imageAttr)
End Sub

注解

参数 destPoints 指定平行四边形的三个点。 这三个 Point 结构表示平行四边形的左上角、右上角和左下角。 从前三个点推断出第四个点,形成一个平行四边形。

参数 srcRect 指定要绘制的image 对象的矩形部分。 此部分经过缩放和剪切,以适应 参数指定的 destPoints 平行四边形。

另请参阅

适用于