Graphics.DrawImage 方法

定義

以原始大小,在指定之位置繪製指定的 ImageDraws the specified Image at the specified location and with the original size.

多載

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

將影像的一部分繪製於指定位置。Draws a portion of an image at a specified location.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

DrawImage(Image, Point)

使用原始的實體大小,在指定位置繪製指定的 ImageDraws the specified Image, using its original physical size, at the specified location.

DrawImage(Image, Point[])

以指定的形狀和大小,在指定之位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified shape and size.

DrawImage(Image, PointF)

使用原始的實體大小,在指定位置繪製指定的 ImageDraws the specified Image, using its original physical size, at the specified location.

DrawImage(Image, PointF[])

以指定的形狀和大小,在指定之位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified shape and size.

DrawImage(Image, Rectangle)

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

DrawImage(Image, RectangleF)

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

DrawImage(Image, Int32, Int32)

使用原始的實體大小將指定的影像繪製於座標對所指定的位置。Draws the specified image, using its original physical size, at the location specified by a coordinate pair.

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

將影像的一部分繪製於指定位置。Draws a portion of an image at a specified location.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

DrawImage(Image, Single, Single)

使用原始的實體大小,在指定位置繪製指定的 ImageDraws the specified Image, using its original physical size, at the specified location.

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

在指定的位置,繪製指定之 Image 的指定部分。Draws the specified portion of the specified Image at the specified location.

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

將影像的一部分繪製於指定位置。Draws a portion of an image at a specified location.

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

參數

image
Image

要繪製的 ImageImage to draw.

x
Single

繪製影像左上角的 X 座標。The x-coordinate of the upper-left corner of the drawn image.

y
Single

所繪製影像左上角的 Y 座標。The y-coordinate of the upper-left corner of the drawn image.

srcRect
RectangleF

RectangleF 結構,指定要繪製之 Image 的部分。RectangleF structure that specifies the portion of the Image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其上繪製影像左上角的座標。Creates the coordinates at which to draw the upper-left corner of the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

來源矩形的大小會決定要將未縮放原始影像的哪個部分繪製到螢幕上。The size of the source rectangle determines what portion of the unscaled original image is drawn to the screen.

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儲存圖元寬度的值和水準解析度的值(以每英寸點為單位)。An Image stores a value for pixel width and a value for horizontal resolution (dots per inch). 影像的實體寬度(以英寸為單位)是圖元寬度除以水準解析度。The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. 例如,圖元寬度為360的影像,以及每英寸72個點的水準解析度,其實體寬度為5英寸。For example, an image with a pixel width of 360 and a horizontal resolution of 72 dots per inch has a physical width of 5 inches. 類似的備註適用于圖元高度和實體高度。Similar remarks apply to pixel height and physical height.

這個方法會使用其實體大小來繪製影像的一部分,因此不論顯示裝置的解析度(每英寸點),影像部分的大小都會以英寸為單位。This method draws a portion of an image using its physical size, so the image portion will have its correct size in inches regardless of the resolution (dots per inch) of the display device. 例如,假設影像部分的圖元寬度為216,而水準解析度為每英寸72個點。For example, suppose an image portion has a pixel width of 216 and a horizontal resolution of 72 dots per inch. 如果您呼叫此方法,在解析度為每英寸96個點的裝置上繪製該影像部分,則轉譯影像部分的圖元寬度會是(216/72) * 96 = 288。If you call this method to draw that image portion on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image portion will be (216/72)*96 = 288.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Single

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Single

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Single

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Single

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

imageAttrs
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) method according to application-determined criteria.

callbackData
IntPtr

數值,指定 Graphics.DrawImageAbort 委派在檢查是否停止執行 DrawImage 方法時要使用的額外資料。Value specifying additional data for the Graphics.DrawImageAbort delegate to use when checking whether to stop execution of the DrawImage method.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的目的地矩形。Creates points that define a destination rectangle in which to draw the image.

  • 建立來源矩形以選取要繪製之影像的部分。Creates a source rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他目的地矩形。Creates an additional destination rectangle in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 目的地矩形,位置會在螢幕上尋找影像,而來源矩形的大小和目的矩形的大小和形狀,會決定所繪製影像的縮放比例。For the original, unadjusted destination rectangle, the position locates the image on the screen, and the size of the source rectangle and the size and shape of the destination rectangle determines the scaling of the drawn image.

因為此範例使用callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼false會傳回,這會導致DrawImage方法繼續進行,而範例會將調整的影像繪製到螢幕上。Because this example uses an overload that passes a callBackData parameter, the Graphics.DrawImageAbort callback returns false, which causes the DrawImage method to continue, and the example draws the adjusted image to the screen.

   // 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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

具有callbackcallbackData參數的這個多載提供了一種方法,可在根據應用程式所決定的準則和資料啟動時,停止繪製影像。This overload with the callback and callbackData parameters provides the means to stop the drawing of an image once it starts according to criteria and data determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Int32

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Int32

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Int32

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Int32

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

imageAttrs
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) method according to application-determined criteria.

callbackData
IntPtr

數值,指定 Graphics.DrawImageAbort 委派在檢查是否停止執行 DrawImage 方法時要使用的額外資料。Value specifying additional data for the Graphics.DrawImageAbort delegate to use when checking whether to stop execution of the DrawImage method.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的目的地矩形。Creates points that define a destination rectangle in which to draw the image.

  • 建立來源矩形以選取要繪製之影像的部分。Creates a source rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他目的地矩形。Creates an additional destination rectangle in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 目的地矩形,位置會在螢幕上尋找影像,而來源矩形的大小和目的矩形的大小和形狀,會決定所繪製影像的縮放比例。For the original, unadjusted destination rectangle, the position locates the image on the screen, and the size of the source rectangle and the size and shape of the destination rectangle determines the scaling of the drawn image.

因為此範例使用callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼false會傳回,這會導致DrawImage方法繼續進行,而範例會將調整的影像繪製到螢幕上。Because this example uses an overload that passes a callBackData parameter, the Graphics.DrawImageAbort callback returns false, which causes the DrawImage method to continue, and the example draws the adjusted image to the screen.

   // 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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

具有callbackcallbackData參數的這個多載提供了一種方法,可在根據應用程式所決定的準則和資料啟動時,停止繪製影像。This overload with the callback and callbackData parameters provides the means to stop the drawing of an image once it starts according to criteria and data determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Single

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Single

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Single

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Single

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

imageAttrs
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) method according to application-determined criteria.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的目的地矩形。Creates points that define a destination rectangle in which to draw the image.

  • 建立來源矩形以選取要繪製之影像的部分。Creates a source rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他目的地矩形。Creates an additional destination rectangle in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 目的地矩形,位置會在螢幕上尋找影像,而來源矩形的大小和目的矩形的大小和形狀,會決定所繪製影像的縮放比例。For the original, unadjusted destination rectangle, the position locates the image on the screen, and the size of the source rectangle and the size and shape of the destination rectangle determines the scaling of the drawn image.

因為此範例使用不會callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼true會傳回,這會導致DrawImage方法結束,而範例中所包含的例外狀況處理常式代碼會列印出例外狀況文字,而不是繪製影像。Because this example uses an overload that does not pass a callBackData parameter, the Graphics.DrawImageAbort callback returns true, which causes the DrawImage method to end, and the exception-handling code included in the example prints out the exception text rather than drawing the image.

   // 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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

具有callback參數的這個多載提供了一種方法,可在根據應用程式所決定的準則開始時,停止繪製影像。This overload with the callback parameter provides the means to stop the drawing of an image once it starts according to criteria determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Int32

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Int32

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Int32

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Int32

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

imageAttr
ImageAttributes

ImageAttributes,指定 image 的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for image.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) method according to application-determined criteria.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的目的地矩形。Creates points that define a destination rectangle in which to draw the image.

  • 建立來源矩形以選取要繪製之影像的部分。Creates a source rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他目的地矩形。Creates an additional destination rectangle in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 目的地矩形,位置會在螢幕上尋找影像,而來源矩形的大小和目的矩形的大小和形狀,會決定所繪製影像的縮放比例。For the original, unadjusted destination rectangle, the position locates the image on the screen, and the size of the source rectangle and the size and shape of the destination rectangle determines the scaling of the drawn image.

因為此範例使用不會callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼true會傳回,這會導致DrawImage方法結束,而範例中所包含的例外狀況處理常式代碼會列印出例外狀況文字,而不是繪製影像。Because this example uses an overload that does not pass a callBackData parameter, the Graphics.DrawImageAbort callback returns true, which causes the DrawImage method to end, and the exception-handling code included in the example prints out the exception text rather than drawing the image.

   // 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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect物件所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect object.

具有callback參數的這個多載提供了一種方法,可在根據應用程式所決定的準則開始時,停止繪製影像。This overload with the callback parameter provides the means to stop the drawing of an image once it starts according to criteria determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Single

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Single

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Single

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Single

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

imageAttrs
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的目的地矩形。Creates a destination rectangle in which to draw the image.

  • 建立來源矩形的座標,從中提取影像的一部分。Creates the coordinates of a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的額外矩形。Creates an additional rectangle in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 [unadjusted 目的地] 矩形,位置會在畫面上尋找影像,而來源和目的地矩形的大小會決定繪製影像的縮放比例,而來源矩形的大小則決定了哪個部分的原始影像會繪製到螢幕上。For the original, unadjusted destination rectangle, the position locates the image on the screen, and the sizes of the source and destination rectangles determine the scaling of the drawn image, and the size of the source rectangle determines what portion of the original image is drawn to the screen.

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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Int32

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Int32

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Int32

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Int32

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的目的地矩形。Creates a destination rectangle in which to draw the image.

  • 建立來源矩形的座標,從中提取影像的一部分。Creates the coordinates of a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的額外矩形。Creates an additional rectangle in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 [unadjusted 目的地] 矩形,位置會在畫面上尋找影像,而來源和目的地矩形的大小會決定繪製影像的縮放比例,而來源矩形的大小則決定了哪個部分的原始影像會繪製到螢幕上。For the original, unadjusted destination rectangle, the position locates the image on the screen, and the sizes of the source and destination rectangles determine the scaling of the drawn image, and the size of the source rectangle determines what portion of the original image is drawn to the screen.

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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Single

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Single

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Single

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Single

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像之目的地矩形的座標。Creates the coordinates of a destination rectangle in which to draw the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

目的地矩形的位置會在螢幕上尋找影像,來源和目的地矩形的大小會決定繪製影像的縮放比例,而來源矩形的大小會決定要將原始影像的哪個部分繪製至寬屏.The position of the destination rectangle locates the image on the screen, the sizes of the source and destination rectangles determine the scaling of the drawn image, and the size of the source rectangle determines what portion of the original image is drawn to the screen.

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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcX
Int32

要繪製之來源影像部分左上角的 X 座標。The x-coordinate of the upper-left corner of the portion of the source image to draw.

srcY
Int32

要繪製之來源影像部分左上角的 Y 座標。The y-coordinate of the upper-left corner of the portion of the source image to draw.

srcWidth
Int32

要繪製之來源影像部分的寬度。Width of the portion of the source image to draw.

srcHeight
Int32

要繪製之來源影像部分的高度。Height of the portion of the source image to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉型別的成員,指定用來判斷來源矩形的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used to determine the source rectangle.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的目的地矩形。Creates a destination rectangle in which to draw the image.

  • 建立來源矩形的座標,從中提取影像的一部分。Creates the coordinates of a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

目的地矩形的位置會在螢幕上尋找影像,而來源和目的地矩形的大小會決定繪製影像的縮放比例,而來源矩形的大小會決定要將原始影像的哪個部分繪製至寬屏.The position of the destination rectangle locates the image on the screen, and the sizes of the source and destination rectangles determine the scaling of the drawn image, and the size of the source rectangle determines what portion of the original image is drawn to the screen.

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

備註

srcX、 、和srcWidth參數會指定要繪製之image物件的矩形部分。 srcHeight srcYThe srcX, srcY, srcWidth, and srcHeight parameters specify a rectangular portion, of the image object to draw. 矩形相對於來源影像的左上角。The rectangle is relative to the upper-left corner of the source image. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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);
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

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
PointF[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

srcRect
RectangleF

RectangleF 結構,指定 image 物件要繪製的部分。RectangleF structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) method according to application-determined criteria.

callbackData
Int32

數值,指定 Graphics.DrawImageAbort 委派在檢查是否停止執行 DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法時要使用的額外資料。Value specifying additional data for the Graphics.DrawImageAbort delegate to use when checking whether to stop execution of the DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) method.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Pa Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the PaPaint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 建立矩形以選取要繪製之影像的部分。Creates a rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他平行四邊形。Creates an additional parallelogram in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 平行四邊形,位置會在螢幕上尋找影像,而矩形的大小和平行四邊形的大小和形狀,會決定所繪製影像的縮放比例和切變。For the original, unadjusted parallelogram, the position locates the image on the screen, and the size of the rectangle and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

因為此範例使用callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼false會傳回,這會導致DrawImage方法繼續進行,而範例會將調整的影像繪製到螢幕上。Because this example uses an overload that passes a callBackData parameter, the Graphics.DrawImageAbort callback returns false, which causes the DrawImage method to continue, and the example draws the adjusted image to the screen.

   // 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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

具有callbackcallbackData參數的這個多載提供了一種方法,可在根據應用程式所決定的準則和資料啟動時,停止繪製影像。This overload with the callback and callbackData parameters provides the means to stop the drawing of an image once it starts according to criteria and data determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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);
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

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
Point[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

srcRect
Rectangle

Rectangle 結構,指定 image 物件要繪製的部分。Rectangle structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) method according to application-determined criteria.

callbackData
Int32

數值,指定 Graphics.DrawImageAbort 委派在檢查是否停止執行 DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) 方法時要使用的額外資料。Value specifying additional data for the Graphics.DrawImageAbort delegate to use when checking whether to stop execution of the DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) method.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 建立矩形以選取要繪製之影像的部分。Creates a rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他平行四邊形。Creates an additional parallelogram in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 平行四邊形,位置會在螢幕上尋找影像,而矩形的大小和平行四邊形的大小和形狀,會決定所繪製影像的縮放比例和切變。For the original, unadjusted parallelogram, the position locates the image on the screen, and the size of the rectangle and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

因為此範例使用callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼false會傳回,這會導致DrawImage方法繼續進行,而範例會將調整的影像繪製到螢幕上。Because this example uses an overload that passes a callBackData parameter, the Graphics.DrawImageAbort callback returns false, which causes the DrawImage method to continue, and the example draws the adjusted image to the screen.

   // 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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

具有callbackcallbackData參數的這個多載提供了一種方法,可在根據應用程式所決定的準則和資料啟動時,停止繪製影像。This overload with the callback and callbackData parameters provides the means to stop the drawing of an image once it starts according to criteria and data determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
PointF[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

srcRect
RectangleF

RectangleF 結構,指定 image 物件要繪製的部分。RectangleF structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) method according to application-determined criteria.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例。Creates an instance of the Graphics.DrawImageAbort callback method.

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 建立矩形以選取要繪製之影像的部分。Creates a rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他平行四邊形。Creates an additional parallelogram in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 平行四邊形,位置會在螢幕上尋找影像,而矩形的大小和平行四邊形的大小和形狀,會決定所繪製影像的縮放比例和切變。For the original, unadjusted parallelogram, the position locates the image on the screen, and the size of the rectangle and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

因為此範例使用不會callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼true會傳回,這會導致DrawImage方法結束,而範例中所包含的例外狀況處理常式代碼會列印出例外狀況文字,而不是繪製影像。Because this example uses an overload that does not pass a callBackData parameter, the Graphics.DrawImageAbort callback returns true, which causes the DrawImage method to end, and the exception-handling code included in the example prints out the exception text rather than drawing the image.

   // 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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

具有callback參數的這個多載提供了一種方法,可在根據應用程式所決定的準則開始時,停止繪製影像。This overload with the callback parameter provides the means to stop the drawing of an image once it starts according to criteria determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
Point[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

srcRect
Rectangle

Rectangle 結構,指定 image 物件要繪製的部分。Rectangle structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

callback
Graphics.DrawImageAbort

Graphics.DrawImageAbort 委派,在繪製影像期間指定要呼叫的方法。Graphics.DrawImageAbort delegate that specifies a method to call during the drawing of the image. 這個方法會經常被呼叫,以檢查是否要根據應用程式所決定的準則來停止執行 DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) 方法。This method is called frequently to check whether to stop execution of the DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) method according to application-determined criteria.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式Graphics.DrawImageAbort代碼會先定義委派的回呼方法,定義很簡單,而且只會測試以查看DrawImage方法是否使用 null callBackData參數呼叫它。The code first defines a callback method for the Graphics.DrawImageAbort delegate; the definition is simplistic and merely tests to see whether the DrawImage method calls it with a null callBackData parameter. 範例的主要主體會執行下列動作:The main body of the example performs the following actions:

  • 建立Graphics.DrawImageAbort回呼方法的實例:Creates an instance of the Graphics.DrawImageAbort callback method:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 建立矩形以選取要繪製之影像的部分。Creates a rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他平行四邊形。Creates an additional parallelogram in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 平行四邊形,位置會在螢幕上尋找影像,而矩形的大小和平行四邊形的大小和形狀,會決定所繪製影像的縮放比例和切變。For the original, unadjusted parallelogram, the position locates the image on the screen, and the size of the rectangle and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

因為此範例使用不會callBackData傳遞參數Graphics.DrawImageAbort的多載,所以回呼true會傳回,這會導致DrawImage方法結束,而範例中所包含的例外狀況處理常式代碼會列印出例外狀況文字,而不是繪製影像。Because this example uses an overload that does not pass a callBackData parameter, the Graphics.DrawImageAbort callback returns true, which causes the DrawImage method to end, and the exception-handling code included in the example prints out the exception text rather than drawing the image.

   // 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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

具有callback參數的這個多載提供了一種方法,可在根據應用程式所決定的準則開始時,停止繪製影像。This overload with the callback parameter provides the means to stop the drawing of an image once it starts according to criteria determined by the application. 例如,應用程式可能會開始繪製大型影像,而使用者可能會將影像從畫面中取出,在此情況下,應用程式可能會停止繪圖。For example, an application could start drawing a large image and the user might scroll the image off the screen, in which case the application could stop the drawing.

另請參閱

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

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

x
Int32

繪製影像左上角的 X 座標。The x-coordinate of the upper-left corner of the drawn image.

y
Int32

所繪製影像左上角的 Y 座標。The y-coordinate of the upper-left corner of the drawn image.

width
Int32

繪製影像的寬度。Width of the drawn image.

height
Int32

繪製影像的高度。Height of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像之矩形的位置和大小。Creates the position and size of a rectangle in which to draw the image.

  • 將影像繪製到螢幕上。Draws the image to the screen.

矩形的位置會在螢幕上尋找影像,而原始影像的大小和矩形的大小會決定繪製影像的縮放比例。The position of the rectangle locates the image on the screen, and the size of the original image and the size of the rectangle determines the scaling of the drawn image.

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

備註

x、 、y和參數height所定義的矩形會決定所繪製影像的位置和大小。 widthThe rectangle defined by the x, y, width, and height parameters determines the position and size of the drawn image.

另請參閱

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

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

x
Single

繪製影像左上角的 X 座標。The x-coordinate of the upper-left corner of the drawn image.

y
Single

所繪製影像左上角的 Y 座標。The y-coordinate of the upper-left corner of the drawn image.

width
Single

繪製影像的寬度。Width of the drawn image.

height
Single

繪製影像的高度。Height of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像之矩形的位置和大小。Creates the position and size of a rectangle in which to draw the image.

  • 將影像繪製到螢幕上。Draws the image to the screen.

矩形的位置會在螢幕上尋找影像,而原始影像的大小和矩形的大小會決定繪製影像的縮放比例。The position of the rectangle locates the image on the screen, and the size of the original image and the size of the rectangle determines the scaling of the drawn image.

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

備註

x、 、y和參數height所定義的矩形會決定所繪製影像的位置和大小。 widthThe rectangle defined by the x, y, width, and height parameters determines the position and size of the drawn image.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
PointF[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

srcRect
RectangleF

RectangleF 結構,指定 image 物件要繪製的部分。RectangleF structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的目的地平行四邊形。Creates points that define a destination parallelogram in which to draw the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他平行四邊形。Creates an additional parallelogram in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 目的地平行四邊形,位置會找出螢幕上的影像、來源矩形的大小,以及目的地平行四邊形的大小和形狀,決定繪製影像的縮放比例和切變,以及的大小矩形決定要將原始影像的哪個部分繪製到螢幕上。For the original, unadjusted destination parallelogram, the position locates the image on the screen, the size of the source rectangle and the size and shape of the destination parallelogram determines the scaling and shearing of the drawn image, and the size of the rectangle determines what portion of the original image is drawn to the screen.

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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

另請參閱

DrawImage(Image, Point)

使用原始的實體大小,在指定位置繪製指定的 ImageDraws the specified Image, using its original physical size, at the specified location.

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

參數

image
Image

要繪製的 ImageImage to draw.

point
Point

Point 結構,指定繪製影像的左上角位置。Point structure that represents the location of the upper-left corner of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其上繪製影像左上角的點。Creates a point at which to draw the upper-left corner of the image.

  • 將未縮放的影像繪製到螢幕上。Draws the unscaled image to the screen.

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儲存圖元寬度的值和水準解析度的值(以每英寸點為單位)。An Image stores a value for pixel width and a value for horizontal resolution (dots per inch). 影像的實體寬度(以英寸為單位)是圖元寬度除以水準解析度。The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. 例如,圖元寬度為216的影像,以及每英寸72個點的水準解析度,其實體寬度為3英寸。For example, an image with a pixel width of 216 and a horizontal resolution of 72 dots per inch has a physical width of 3 inches. 類似的備註適用于圖元高度和實體高度。Similar remarks apply to pixel height and physical height.

這個方法會使用其實體大小來繪製影像,因此不論顯示裝置的解析度(每英寸的點),影像的大小都會以英寸為單位。This method draws an image using its physical size, so the image will have its correct size in inches regardless of the resolution (dots per inch) of the display device. 例如,假設影像的圖元寬度為216,而水準解析度為每英寸72個點。For example, suppose an image has a pixel width of 216 and a horizontal resolution of 72 dots per inch. 如果您呼叫此方法,在解析度為每英寸96個點的裝置上繪製該影像,則轉譯影像的圖元寬度會是(216/72) * 96 = 288。If you call this method to draw that image on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image will be (216/72)*96 = 288.

另請參閱

DrawImage(Image, Point[])

以指定的形狀和大小,在指定之位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified shape and size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
Point[]

定義平行四邊形之三個 Point 結構的陣列。Array of three Point structures that define a parallelogram.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 將影像繪製到螢幕上。Draws the image to the screen.

平行四邊形的位置會在螢幕上尋找影像,而原始影像的大小和平行四邊形的大小和形狀,會決定繪製影像的縮放比例和切變。The position of the parallelogram locates the image on the screen, and the size of the original image and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三Point個結構代表平行四邊形的左上方、右上方和左下角。The three Point structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

image參數所表示的影像會縮放並切變,以符合destPoints參數所指定之平行四邊形的形狀。The image represented by the image parameter is scaled and sheared to fit the shape of the parallelogram specified by the destPoints parameters.

另請參閱

DrawImage(Image, PointF)

使用原始的實體大小,在指定位置繪製指定的 ImageDraws the specified Image, using its original physical size, at the specified location.

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

參數

image
Image

要繪製的 ImageImage to draw.

point
PointF

PointF 結構,表示繪製影像的左上角。PointF structure that represents the upper-left corner of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其上繪製影像左上角的點。Creates a point at which to draw the upper-left corner of the image.

  • 將未縮放的影像繪製到螢幕上。Draws the unscaled image to the screen.

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儲存圖元寬度的值和水準解析度的值(以每英寸點為單位)。An Image stores a value for pixel width and a value for horizontal resolution (dots per inch). 影像的實體寬度(以英寸為單位)是圖元寬度除以水準解析度。The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. 例如,圖元寬度為216的影像,以及每英寸72個點的水準解析度,其實體寬度為3英寸。For example, an image with a pixel width of 216 and a horizontal resolution of 72 dots per inch has a physical width of 3 inches. 類似的備註適用于圖元高度和實體高度。Similar remarks apply to pixel height and physical height.

這個方法會使用其實體大小來繪製影像,因此不論顯示裝置的解析度(每英寸的點),影像的大小都會以英寸為單位。This method draws an image using its physical size, so the image will have its correct size in inches regardless of the resolution (dots per inch) of the display device. 例如,假設影像的圖元寬度為216,而水準解析度為每英寸72個點。For example, suppose an image has a pixel width of 216 and a horizontal resolution of 72 dots per inch. 如果您呼叫此方法,在解析度為每英寸96個點的裝置上繪製該影像,則轉譯影像的圖元寬度會是(216/72) * 96 = 288。If you call this method to draw that image on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image will be (216/72)*96 = 288.

另請參閱

DrawImage(Image, PointF[])

以指定的形狀和大小,在指定之位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified shape and size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
PointF[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 將影像繪製到螢幕上。Draws the image to the screen.

平行四邊形的位置會在螢幕上尋找影像,而原始影像的大小和平行四邊形的大小和形狀,會決定繪製影像的縮放比例和切變。The position of the parallelogram locates the image on the screen, and the size of the original image and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

image物件所代表的影像會縮放並切變,以符合destPoints參數所指定之平行四邊形的形狀。The image represented by the image object is scaled and sheared to fit the shape of the parallelogram specified by the destPoints parameter.

另請參閱

DrawImage(Image, Rectangle)

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

rect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的矩形。Creates a rectangle in which to draw the image.

  • 將影像繪製到螢幕上。Draws the image to the screen.

矩形的位置會在螢幕上尋找影像,而原始影像的大小和矩形的大小會決定繪製影像的縮放比例。The position of the rectangle locates the image on the screen, and the size of the original image and the size of the rectangle determines the scaling of the drawn image.

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矩形的維度。The image represented by the image object is scaled to the dimensions of the rect rectangle.

另請參閱

DrawImage(Image, RectangleF)

以指定的大小,在指定的位置繪製指定的 ImageDraws the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

rect
RectangleF

RectangleF 結構,指定繪製影像的位置和大小。RectangleF structure that specifies the location and size of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的矩形。Creates a rectangle in which to draw the image.

  • 將影像繪製到螢幕上。Draws the image to the screen.

矩形的位置會在螢幕上尋找影像,而影像的原始大小和矩形的大小會決定繪製影像的縮放比例。The position of the rectangle locates the image on the screen, and the original size of the image and the size of the rectangle determines the scaling of the drawn image.

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矩形的維度。The image represented by the image object is scaled to the dimensions of the rect rectangle.

另請參閱

DrawImage(Image, Int32, Int32)

使用原始的實體大小將指定的影像繪製於座標對所指定的位置。Draws the specified image, using its original physical size, at the location specified by a coordinate pair.

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

參數

image
Image

要繪製的 ImageImage to draw.

x
Int32

繪製影像左上角的 X 座標。The x-coordinate of the upper-left corner of the drawn image.

y
Int32

所繪製影像左上角的 Y 座標。The y-coordinate of the upper-left corner of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 SampImag 範例的資料夾中建立 JPEG 檔案 SampImag 的影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example SampImag.jpg in the folder of the example.

  • 建立要繪製影像左上角之點的座標。Creates the coordinates of a point at which to draw the upper-left corner of the image.

  • 繪製未縮放的影像。Draws the unscaled image.

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儲存圖元寬度的值和水準解析度的值(以每英寸點為單位)。An Image stores a value for pixel width and a value for horizontal resolution (dots per inch). 影像的實體寬度(以英寸為單位)是圖元寬度除以水準解析度。The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. 例如,圖元寬度為216的影像,以及每英寸72個點的水準解析度,其實體寬度為3英寸。For example, an image with a pixel width of 216 and a horizontal resolution of 72 dots per inch has a physical width of 3 inches. 類似的備註適用于圖元高度和實體高度。Similar remarks apply to pixel height and physical height.

DrawImage方法會使用其實體大小來繪製影像,因此不論顯示裝置的解析度(每英寸的點),影像的大小都會以英寸為單位。The DrawImage method draws an image using its physical size, so the image will have its correct size in inches regardless of the resolution (dots per inch) of the display device. 例如,假設影像的圖元寬度為216,而水準解析度為每英寸72個點。For example, suppose an image has a pixel width of 216 and a horizontal resolution of 72 dots per inch. 如果您呼叫DrawImage以在解析度為每英寸96個點的裝置上繪製該影像,則轉譯影像的圖元寬度會是(216/72) * 96 = 288。If you call DrawImage to draw that image on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image will be (216/72)*96 = 288.

另請參閱

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

將影像的一部分繪製於指定位置。Draws a portion of an image at a specified location.

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

參數

image
Image

要繪製的 ImageImage to draw.

x
Int32

繪製影像左上角的 X 座標。The x-coordinate of the upper-left corner of the drawn image.

y
Int32

所繪製影像左上角的 Y 座標。The y-coordinate of the upper-left corner of the drawn image.

srcRect
Rectangle

Rectangle 結構,指定 image 物件要繪製的部分。Rectangle structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其上繪製影像左上角的座標。Creates the coordinates at which to draw the upper-left corner of the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

來源矩形的大小會決定要將未縮放原始影像的哪個部分繪製到螢幕上。The size of the source rectangle determines what portion of the unscaled original image is drawn to the screen.

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儲存圖元寬度的值和水準解析度的值(以每英寸點為單位)。An Image stores a value for pixel width and a value for horizontal resolution (dots per inch). 影像的實體寬度(以英寸為單位)是圖元寬度除以水準解析度。The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. 例如,圖元寬度為360的影像,以及每英寸72個點的水準解析度,其實體寬度為5英寸。For example, an image with a pixel width of 360 and a horizontal resolution of 72 dots per inch has a physical width of 5 inches. 類似的備註適用于圖元高度和實體高度。Similar remarks apply to pixel height and physical height.

這個方法會使用其實體大小來繪製影像的一部分,因此不論顯示裝置的解析度(每英寸點),影像部分的大小都會以英寸為單位。This method draws a portion of an image using its physical size, so the image portion will have its correct size in inches regardless of the resolution (dots per inch) of the display device. 例如,假設影像部分的圖元寬度為216,而水準解析度為每英寸72個點。For example, suppose an image portion has a pixel width of 216 and a horizontal resolution of 72 dots per inch. 如果您呼叫此方法,在解析度為每英寸96個點的裝置上繪製該影像部分,則轉譯影像部分的圖元寬度會是(216/72) * 96 = 288。If you call this method to draw that image portion on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image portion will be (216/72)*96 = 288.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
Point[]

定義平行四邊形之三個 Point 結構的陣列。Array of three Point structures that define a parallelogram.

srcRect
Rectangle

Rectangle 結構,指定 image 物件要繪製的部分。Rectangle structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 建立矩形以選取要繪製之影像的部分。Creates a rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將影像繪製到螢幕上。Draws the image to the screen.

平行四邊形的位置會在螢幕上尋找影像,而矩形的大小和平行四邊形的大小和形狀,會決定所繪製影像的縮放比例和切變。The position of the parallelogram locates the image on the screen, and the size of the rectangle and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三Point個結構代表平行四邊形的左上方、右上方和左下角。The three Point structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

另請參閱

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

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
PointF[]

定義平行四邊形之三個 PointF 結構的陣列。Array of three PointF structures that define a parallelogram.

srcRect
RectangleF

RectangleF 結構,指定 image 物件要繪製的部分。RectangleF structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的目的地平行四邊形。Creates points that define a destination parallelogram in which to draw the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

目的地平行四邊形的位置會在螢幕上尋找影像、來源矩形的大小,以及目的地平行四邊形的大小和形狀,決定繪製影像的縮放比例和切變,而矩形的大小決定原始影像的哪個部分會繪製到螢幕上。The position of the destination parallelogram locates the image on the screen, the size of the source rectangle and the size and shape of the destination parallelogram determines the scaling and shearing of the drawn image, and the size of the rectangle determines what portion of the original image is drawn to the screen.

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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三PointF個結構代表平行四邊形的左上方、右上方和左下角。The three PointF structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

另請參閱

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
Rectangle

Rectangle 結構,指定繪製影像的位置和大小。Rectangle structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcRect
Rectangle

Rectangle 結構,指定 image 物件要繪製的部分。Rectangle structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的目的地矩形。Creates a destination rectangle in which to draw the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

目的地矩形的位置會在螢幕上尋找影像,來源和目的地矩形的大小會決定繪製影像的縮放比例,而來源矩形的大小會決定要將原始影像的哪個部分繪製至寬屏.The position of the destination rectangle locates the image on the screen, the sizes of the source and destination rectangles determine the scaling of the drawn image, and the size of the source rectangle determines what portion of the original image is drawn to the screen.

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

備註

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

另請參閱

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

以指定的大小,在指定的位置繪製所指定 Image 之指定部分。Draws the specified portion of the specified Image at the specified location and with the specified size.

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

參數

image
Image

要繪製的 ImageImage to draw.

destRect
RectangleF

RectangleF 結構,指定繪製影像的位置和大小。RectangleF structure that specifies the location and size of the drawn image. 縮放影像來符合矩形。The image is scaled to fit the rectangle.

srcRect
RectangleF

RectangleF 結構,指定 image 物件要繪製的部分。RectangleF structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要在其中繪製影像的目的地矩形。Creates a destination rectangle in which to draw the image.

  • 建立來源矩形,從中解壓縮部分影像。Creates a source rectangle from which to extract a portion of the image.

  • 將來源矩形的測量單位設定為圖元。Sets the unit of measure of the source rectangle to pixels.

  • 將影像繪製到螢幕上。Draws the image to the screen.

目的地矩形的位置會在螢幕上尋找影像,來源和目的地矩形的大小會決定繪製影像的縮放比例,而來源矩形的大小會決定要將原始影像的哪個部分繪製至寬屏.The position of the destination rectangle locates the image on the screen, the sizes of the source and destination rectangles determine the scaling of the drawn image, and the size of the source rectangle determines what portion of the original image is drawn to the screen.

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

備註

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of the image object to draw. 這個部分會經過調整,以符合destRect參數所指定的矩形內部。This portion is scaled to fit inside the rectangle specified by the destRect parameter.

另請參閱

DrawImage(Image, Single, Single)

使用原始的實體大小,在指定位置繪製指定的 ImageDraws the specified Image, using its original physical size, at the specified location.

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

參數

image
Image

要繪製的 ImageImage to draw.

x
Single

繪製影像左上角的 X 座標。The x-coordinate of the upper-left corner of the drawn image.

y
Single

所繪製影像左上角的 Y 座標。The y-coordinate of the upper-left corner of the drawn image.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立要繪製影像左上角之點的座標。Creates the coordinates of a point at which to draw the upper-left corner of the image.

  • 將未縮放的影像繪製到螢幕上。Draws the unscaled image to the screen.

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儲存圖元寬度的值和水準解析度的值(以每英寸點為單位)。An Image stores a value for pixel width and a value for horizontal resolution (dots per inch). 影像的實體寬度(以英寸為單位)是圖元寬度除以水準解析度。The physical width, measured in inches, of an image is the pixel width divided by the horizontal resolution. 例如,圖元寬度為216的影像,以及每英寸72個點的水準解析度,其實體寬度為3英寸。For example, an image with a pixel width of 216 and a horizontal resolution of 72 dots per inch has a physical width of 3 inches. 類似的備註適用于圖元高度和實體高度。Similar remarks apply to pixel height and physical height.

這個方法會使用其實體大小來繪製影像,因此不論顯示裝置的解析度(每英寸的點),影像的大小都會以英寸為單位。This method draws an image using its physical size, so the image will have its correct size in inches regardless of the resolution (dots per inch) of the display device. 例如,假設影像的圖元寬度為216,而水準解析度為每英寸72個點。For example, suppose an image has a pixel width of 216 and a horizontal resolution of 72 dots per inch. 如果您呼叫此方法,在解析度為每英寸96個點的裝置上繪製該影像,則轉譯影像的圖元寬度會是(216/72) * 96 = 288。If you call this method to draw that image on a device that has a resolution of 96 dots per inch, the pixel width of the rendered image will be (216/72)*96 = 288.

另請參閱

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

在指定的位置,繪製指定之 Image 的指定部分。Draws the specified portion of the specified Image at the specified location.

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);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit

參數

image
Image

要繪製的 ImageImage to draw.

destPoints
Point[]

定義平行四邊形之三個 Point 結構的陣列。Array of three Point structures that define a parallelogram.

srcRect
Rectangle

Rectangle 結構,指定 image 物件要繪製的部分。Rectangle structure that specifies the portion of the image object to draw.

srcUnit
GraphicsUnit

GraphicsUnit 列舉的成員,指定 srcRect 參數所使用的測量單位。Member of the GraphicsUnit enumeration that specifies the units of measure used by the srcRect parameter.

imageAttr
ImageAttributes

ImageAttributes,指定 image 物件的重新著色和 Gamma 資訊。ImageAttributes that specifies recoloring and gamma information for the image object.

例外狀況

imagenullimage is null.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計,而且PaintEventArgs它需要e,這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  • 在範例的資料夾中,從 JPEG 檔案 SampImag 建立影像。Creates an image from a JPEG file SampImag.jpg in the folder of the example.

  • 建立點,以定義要在其中繪製影像的平行四邊形。Creates points that define a parallelogram in which to draw the image.

  • 建立矩形以選取要繪製之影像的部分。Creates a rectangle to select the portion of the image to draw.

  • 將圖形繪圖單位設定為圖元。Sets the graphics drawing unit to pixel.

  • 將原始影像繪製到螢幕上。Draws the original image to the screen.

  • 建立要在其中繪製已調整影像的其他平行四邊形。Creates an additional parallelogram in which to draw an adjusted image.

  • 建立並設定已調整影像的屬性,使其具有大於一般的 gamma 值。Creates and sets the attributes of the adjusted image to have a larger-than-usual gamma value.

  • 將已調整的影像繪製到螢幕上。Draws the adjusted image to the screen.

針對原始的 unadjusted 平行四邊形,位置會在螢幕上尋找影像,而矩形的大小和平行四邊形的大小和形狀,會決定所繪製影像的縮放比例和切變。For the original, unadjusted parallelogram, the position locates the image on the screen, and the size of the rectangle and the size and shape of the parallelogram determines the scaling and shearing of the drawn image.

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參數指定平行四邊形的三個點。The destPoints parameter specifies three points of a parallelogram. 這三Point個結構代表平行四邊形的左上方、右上方和左下角。The three Point structures represent the upper-left, upper-right, and lower-left corners of the parallelogram. 第四個點是從前三個中推入,以形成平行四邊形。The fourth point is extrapolated from the first three to form a parallelogram.

參數會指定要繪製image之物件的矩形部分。 srcRectThe srcRect parameter specifies a rectangular portion of theimage object to draw. 這個部分會縮放並切變,以符合destPoints參數所指定的平行四邊形內部。This portion is scaled and sheared to fit inside the parallelogram specified by the destPoints parameter.

另請參閱

適用於