Graphics.DrawImageとは? わかりやすく解説

Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As PointF(), _
    srcRect As RectangleF, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes, _
    callback As DrawImageAbort, _
    callbackData As Integer _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As PointF()
Dim srcRect As RectangleF
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes
Dim callback As DrawImageAbort
Dim callbackData As Integer

instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, callbackData)
public void DrawImage (
    Image image,
    PointF[] destPoints,
    RectangleF srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr,
    DrawImageAbort callback,
    int callbackData
)
public:
void DrawImage (
    Image^ image, 
    array<PointF>^ destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr, 
    DrawImageAbort^ callback, 
    int callbackData
)
public void DrawImage (
    Image image, 
    PointF[] destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr, 
    DrawImageAbort callback, 
    int callbackData
)
public function DrawImage (
    image : Image, 
    destPoints : PointF[], 
    srcRect : RectangleF, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes, 
    callback : DrawImageAbort, 
    callbackData : int
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

srcRect

描画する image オブジェクト部分指定する RectangleF 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

callbackData

DrawImage メソッド実行停止するかどうかチェックするときに使用するGraphics.DrawImageAbort デリゲート追加データ指定する値。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、PaPaint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整平行四辺形では、その位置によって画面上のイメージ位置決まり四角形サイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

この例では callBackData パラメータを渡すオーバーロード使用するため、Graphics.DrawImageAbort コールバックfalse返します。これにより、DrawImage メソッド続行し調整済みイメージ画面描画されます。

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, PointF)

指定した位置に、指定した Image を元の物理サイズ描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    point As PointF _
)
Dim instance As Graphics
Dim image As Image
Dim point As PointF

instance.DrawImage(image, point)
public void DrawImage (
    Image image,
    PointF point
)
public:
void DrawImage (
    Image^ image, 
    PointF point
)
public void DrawImage (
    Image image, 
    PointF point
)
public function DrawImage (
    image : Image, 
    point : PointF
)

パラメータ

image

描画する Image

point

描画イメージ左上隅を表す PointF 構造体

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Int32, Int32, Int32, Int32)

指定した位置指定したサイズで、指定した Image描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

四角形位置によって画面上のイメージ位置決まり、元のイメージサイズ四角形サイズによって描画イメージスケーリング決まります

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
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 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.get_Graphics().DrawImage(newImage, x, y, width, height);
} //DrawImage4Int
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, RectangleF)

指定した位置指定したサイズで、指定した Image描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    rect As RectangleF _
)
Dim instance As Graphics
Dim image As Image
Dim rect As RectangleF

instance.DrawImage(image, rect)
public void DrawImage (
    Image image,
    RectangleF rect
)
public:
void DrawImage (
    Image^ image, 
    RectangleF rect
)
public void DrawImage (
    Image image, 
    RectangleF rect
)
public function DrawImage (
    image : Image, 
    rect : RectangleF
)

パラメータ

image

描画する Image

rect

描画イメージ位置サイズ指定する RectangleF 構造体

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

四角形位置によって画面上のイメージ位置決まり、元のイメージサイズ四角形サイズによって描画イメージスケーリング決まります

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
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:
   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, 100, 450, 150);

    // Draw image to screen.
    e.get_Graphics().DrawImage(newImage, rect);
} //DrawImageRectF
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As PointF(), _
    srcRect As RectangleF, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes, _
    callback As DrawImageAbort _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As PointF()
Dim srcRect As RectangleF
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes
Dim callback As DrawImageAbort

instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback)
public void DrawImage (
    Image image,
    PointF[] destPoints,
    RectangleF srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr,
    DrawImageAbort callback
)
public:
void DrawImage (
    Image^ image, 
    array<PointF>^ destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr, 
    DrawImageAbort^ callback
)
public void DrawImage (
    Image image, 
    PointF[] destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr, 
    DrawImageAbort callback
)
public function DrawImage (
    image : Image, 
    destPoints : PointF[], 
    srcRect : RectangleF, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes, 
    callback : DrawImageAbort
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

srcRect

描画する image オブジェクト部分指定する RectangleF 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整平行四辺形では、その位置によって画面上のイメージ位置決まり四角形サイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

この例では callBackData パラメータ渡さないオーバーロード使用するため、Graphics.DrawImageAbort コールバックtrue返します。これにより、DrawImage メソッド終了し、例に含まれる例外処理コードは、イメージ描画せずに、例外テキスト出力します

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, RectangleF, RectangleF, GraphicsUnit)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As RectangleF, _
    srcRect As RectangleF, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As RectangleF
Dim srcRect As RectangleF
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, destRect, srcRect, srcUnit)
public void DrawImage (
    Image image,
    RectangleF destRect,
    RectangleF srcRect,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    RectangleF destRect, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    RectangleF destRect, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    destRect : RectangleF, 
    srcRect : RectangleF, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する RectangleF 構造体イメージは、四角形合わせてスケーリングされます

srcRect

描画する image オブジェクト部分指定する RectangleF 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

描画先の四角形位置によって画面上のイメージ位置決まり抽出元および描画先の四角形サイズによって描画イメージスケーリング決まり抽出元の四角形サイズによって画面描画する元のイメージ部分決まります

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
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:
   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, 100, 450, 150);

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

    // Draw image to screen.
    e.get_Graphics().DrawImage(newImage, destRect, srcRect, units);
} //DrawImageRectFRectF
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As Point(), _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As Point()
Dim srcRect As Rectangle
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, destPoints, srcRect, srcUnit)
public void DrawImage (
    Image image,
    Point[] destPoints,
    Rectangle srcRect,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    array<Point>^ destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    Point[] destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    destPoints : Point[], 
    srcRect : Rectangle, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの Point 構造体配列

srcRect

描画する image オブジェクト部分指定する Rectangle 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

平行四辺形位置によって画面上のイメージ位置決まり四角形サイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As PointF(), _
    srcRect As RectangleF, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As PointF()
Dim srcRect As RectangleF
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, destPoints, srcRect, srcUnit)
public void DrawImage (
    Image image,
    PointF[] destPoints,
    RectangleF srcRect,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    array<PointF>^ destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    PointF[] destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    destPoints : PointF[], 
    srcRect : RectangleF, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

srcRect

描画する image オブジェクト部分指定する RectangleF 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

描画先の平行四辺形位置によって画面上のイメージ位置決まり抽出元の四角形サイズおよび描画先の平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まり四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Rectangle, GraphicsUnit)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcRect As Rectangle
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, destRect, srcRect, srcUnit)
public void DrawImage (
    Image image,
    Rectangle destRect,
    Rectangle srcRect,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcRect : Rectangle, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcRect

描画する image オブジェクト部分指定する Rectangle 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

描画先の四角形位置によって画面上のイメージ位置決まり抽出元および描画先の四角形サイズによって描画イメージスケーリング決まり抽出元の四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Int32, Int32, Rectangle, GraphicsUnit)

イメージ一部指定位置描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    x As Integer, _
    y As Integer, _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim x As Integer
Dim y As Integer
Dim srcRect As Rectangle
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, x, y, srcRect, srcUnit)
public void DrawImage (
    Image image,
    int x,
    int y,
    Rectangle srcRect,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    int x, 
    int y, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    int x, 
    int y, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    x : int, 
    y : int, 
    srcRect : Rectangle, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

x

描画イメージ左上隅の x 座標

y

描画イメージ左上隅の y 座標

srcRect

描画する image オブジェクト部分指定する Rectangle 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

抽出元の四角形サイズによって、スケーリングされない元のイメージのどの部分画面描画されるかが決まります

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
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:
   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.get_Graphics().DrawImage(newImage, x, y, srcRect, units);
} //DrawImage2IntRect
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)

指定した位置に、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As Point(), _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As Point()
Dim srcRect As Rectangle
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes

instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr)
public void DrawImage (
    Image image,
    Point[] destPoints,
    Rectangle srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr
)
public:
void DrawImage (
    Image^ image, 
    array<Point>^ destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr
)
public void DrawImage (
    Image image, 
    Point[] destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr
)
public function DrawImage (
    image : Image, 
    destPoints : Point[], 
    srcRect : Rectangle, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの Point 構造体配列

srcRect

描画する image オブジェクト部分指定する Rectangle 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

元の未調整平行四辺形では、その位置によって画面上のイメージ位置決まり四角形サイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

Public 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
public 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);
}
public:
   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
 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Single, Single, Single, Single)

指定した位置指定したサイズで、指定した Image描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

四角形位置によって画面上のイメージ位置決まり、元のイメージサイズ四角形サイズによって描画イメージスケーリング決まります

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
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 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;
    float y = 100;
    float width = 450;
    float height = 150;

    // Draw image to screen.
    e.get_Graphics().DrawImage(newImage, x, y, width, height);
} //DrawImage4Float
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As Point(), _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes, _
    callback As DrawImageAbort _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As Point()
Dim srcRect As Rectangle
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes
Dim callback As DrawImageAbort

instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback)
public void DrawImage (
    Image image,
    Point[] destPoints,
    Rectangle srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr,
    DrawImageAbort callback
)
public:
void DrawImage (
    Image^ image, 
    array<Point>^ destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr, 
    DrawImageAbort^ callback
)
public void DrawImage (
    Image image, 
    Point[] destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr, 
    DrawImageAbort callback
)
public function DrawImage (
    image : Image, 
    destPoints : Point[], 
    srcRect : Rectangle, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes, 
    callback : DrawImageAbort
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

srcRect

描画する image オブジェクト部分指定する Rectangle 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整平行四辺形では、その位置によって画面上のイメージ位置決まり四角形サイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

この例では callBackData パラメータ渡さないオーバーロード使用するため、Graphics.DrawImageAbort コールバックtrue返します。これにより、DrawImage メソッド終了し、例に含まれる例外処理コードは、イメージ描画せずに、例外テキスト出力します

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As Point(), _
    srcRect As Rectangle, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes, _
    callback As DrawImageAbort, _
    callbackData As Integer _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As Point()
Dim srcRect As Rectangle
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes
Dim callback As DrawImageAbort
Dim callbackData As Integer

instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, callbackData)
public void DrawImage (
    Image image,
    Point[] destPoints,
    Rectangle srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr,
    DrawImageAbort callback,
    int callbackData
)
public:
void DrawImage (
    Image^ image, 
    array<Point>^ destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr, 
    DrawImageAbort^ callback, 
    int callbackData
)
public void DrawImage (
    Image image, 
    Point[] destPoints, 
    Rectangle srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr, 
    DrawImageAbort callback, 
    int callbackData
)
public function DrawImage (
    image : Image, 
    destPoints : Point[], 
    srcRect : Rectangle, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes, 
    callback : DrawImageAbort, 
    callbackData : int
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

srcRect

描画する image オブジェクト部分指定する Rectangle 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

callbackData

DrawImage メソッド実行停止するかどうかチェックするときに使用するGraphics.DrawImageAbort デリゲート追加データ指定する値。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整平行四辺形では、その位置によって画面上のイメージ位置決まり四角形サイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

この例では callBackData パラメータを渡すオーバーロード使用するため、Graphics.DrawImageAbort コールバックfalse返します。これにより、DrawImage メソッド続行し調整済みイメージ画面描画されます。

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Integer, _
    srcY As Integer, _
    srcWidth As Integer, _
    srcHeight As Integer, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Integer
Dim srcY As Integer
Dim srcWidth As Integer
Dim srcHeight As Integer
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit)
public void DrawImage (
    Image image,
    Rectangle destRect,
    int srcX,
    int srcY,
    int srcWidth,
    int srcHeight,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : int, 
    srcY : int, 
    srcWidth : int, 
    srcHeight : int, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

描画先の四角形位置によって画面上のイメージ位置決まり抽出元および描画先の四角形サイズによって描画イメージスケーリング決まり抽出元の四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
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 );
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Integer, _
    srcY As Integer, _
    srcWidth As Integer, _
    srcHeight As Integer, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Integer
Dim srcY As Integer
Dim srcWidth As Integer
Dim srcHeight As Integer
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr)
public void DrawImage (
    Image image,
    Rectangle destRect,
    int srcX,
    int srcY,
    int srcWidth,
    int srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : int, 
    srcY : int, 
    srcWidth : int, 
    srcHeight : int, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

元の未調整描画先の四角形では、その位置によって画面上のイメージ位置決まり抽出元および描画先の四角形サイズによって描画イメージスケーリング決まり抽出元の四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
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 );
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Integer, _
    srcY As Integer, _
    srcWidth As Integer, _
    srcHeight As Integer, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes, _
    callback As DrawImageAbort _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Integer
Dim srcY As Integer
Dim srcWidth As Integer
Dim srcHeight As Integer
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes
Dim callback As DrawImageAbort

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr,
 callback)
public void DrawImage (
    Image image,
    Rectangle destRect,
    int srcX,
    int srcY,
    int srcWidth,
    int srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr,
    DrawImageAbort callback
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr, 
    DrawImageAbort^ callback
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr, 
    DrawImageAbort callback
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : int, 
    srcY : int, 
    srcWidth : int, 
    srcHeight : int, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes, 
    callback : DrawImageAbort
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

imageカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整描画先の四角形では、その位置によって画面上のイメージ位置決まり抽出元の四角形サイズおよび描画先の四角形サイズ形状によって描画イメージスケーリング決まります

この例では callBackData パラメータ渡さないオーバーロード使用するため、Graphics.DrawImageAbort コールバックtrue返します。これにより、DrawImage メソッド終了し、例に含まれる例外処理コードは、イメージ描画せずに、例外テキスト出力します

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Integer, _
    srcY As Integer, _
    srcWidth As Integer, _
    srcHeight As Integer, _
    srcUnit As GraphicsUnit, _
    imageAttrs As ImageAttributes, _
    callback As DrawImageAbort, _
    callbackData As IntPtr _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Integer
Dim srcY As Integer
Dim srcWidth As Integer
Dim srcHeight As Integer
Dim srcUnit As GraphicsUnit
Dim imageAttrs As ImageAttributes
Dim callback As DrawImageAbort
Dim callbackData As IntPtr

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs,
 callback, callbackData)
public void DrawImage (
    Image image,
    Rectangle destRect,
    int srcX,
    int srcY,
    int srcWidth,
    int srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttrs,
    DrawImageAbort callback,
    IntPtr callbackData
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttrs, 
    DrawImageAbort^ callback, 
    IntPtr callbackData
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    int srcX, 
    int srcY, 
    int srcWidth, 
    int srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttrs, 
    DrawImageAbort callback, 
    IntPtr callbackData
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : int, 
    srcY : int, 
    srcWidth : int, 
    srcHeight : int, 
    srcUnit : GraphicsUnit, 
    imageAttrs : ImageAttributes, 
    callback : DrawImageAbort, 
    callbackData : IntPtr
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttrs

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

callbackData

DrawImage メソッド実行停止するかどうかチェックするときに使用するGraphics.DrawImageAbort デリゲート追加データ指定する値。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整描画先の四角形では、その位置によって画面上のイメージ位置決まり抽出元の四角形サイズおよび描画先の四角形サイズ形状によって描画イメージスケーリング決まります

この例では callBackData パラメータを渡すオーバーロード使用するため、Graphics.DrawImageAbort コールバックfalse返します。これにより、DrawImage メソッド続行し調整済みイメージ画面描画されます。

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド

指定した位置に元のサイズで、指定した Image描画ます。
オーバーロードの一覧オーバーロードの一覧

名前 説明
Graphics.DrawImage (Image, Point) 指定した位置に、指定した Image を元の物理サイズ描画ます。
Graphics.DrawImage (Image, Point[]) 指定した Image指定した場所に指定した形状とサイズ描画ます。
Graphics.DrawImage (Image, PointF) 指定した位置に、指定した Image を元の物理サイズ描画ます。
Graphics.DrawImage (Image, PointF[]) 指定した Image指定した場所に指定した形状とサイズ描画ます。
Graphics.DrawImage (Image, Rectangle) 指定した位置指定したサイズで、指定した Image描画ます。
Graphics.DrawImage (Image, RectangleF) 指定した位置指定したサイズで、指定した Image描画ます。
Graphics.DrawImage (Image, Int32, Int32) 指定したイメージ座標ペア指定され位置に元の物理サイズ描画ます。

.NET Compact Framework によってサポートされています。

Graphics.DrawImage (Image, Single, Single) 指定した位置に、指定した Image を元の物理サイズ描画ます。
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Rectangle, GraphicsUnit) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。

.NET Compact Framework によってサポートされています。

Graphics.DrawImage (Image, RectangleF, RectangleF, GraphicsUnit) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Int32, Int32, Int32, Int32) 指定した位置指定したサイズで、指定した Image描画ます。
Graphics.DrawImage (Image, Int32, Int32, Rectangle, GraphicsUnit) イメージ一部指定位置描画ます。

.NET Compact Framework によってサポートされています。

Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes) 指定した位置に、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Single, Single, RectangleF, GraphicsUnit) イメージ一部指定位置描画ます。
Graphics.DrawImage (Image, Single, Single, Single, Single) 指定した位置指定したサイズで、指定した Image描画ます。
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。

.NET Compact Framework によってサポートされています。

Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr) 指定した位置指定したサイズで、指定した Image指定した部分描画ます。
参照参照

Graphics.DrawImage メソッド (Image, PointF[])

指定した Image指定した場所に指定した形状とサイズ描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As PointF() _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As PointF()

instance.DrawImage(image, destPoints)
public void DrawImage (
    Image image,
    PointF[] destPoints
)
public:
void DrawImage (
    Image^ image, 
    array<PointF>^ destPoints
)
public void DrawImage (
    Image image, 
    PointF[] destPoints
)
public function DrawImage (
    image : Image, 
    destPoints : PointF[]
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

平行四辺形位置によって画面上のイメージ位置決まり、元のイメージサイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Single, _
    srcY As Single, _
    srcWidth As Single, _
    srcHeight As Single, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Single
Dim srcY As Single
Dim srcWidth As Single
Dim srcHeight As Single
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit)
public void DrawImage (
    Image image,
    Rectangle destRect,
    float srcX,
    float srcY,
    float srcWidth,
    float srcHeight,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : float, 
    srcY : float, 
    srcWidth : float, 
    srcHeight : float, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

描画先の四角形位置によって画面上のイメージ位置決まり抽出元および描画先の四角形サイズによって描画イメージスケーリング決まり抽出元の四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
public:
   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
 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As PointF(), _
    srcRect As RectangleF, _
    srcUnit As GraphicsUnit, _
    imageAttr As ImageAttributes _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As PointF()
Dim srcRect As RectangleF
Dim srcUnit As GraphicsUnit
Dim imageAttr As ImageAttributes

instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr)
public void DrawImage (
    Image image,
    PointF[] destPoints,
    RectangleF srcRect,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttr
)
public:
void DrawImage (
    Image^ image, 
    array<PointF>^ destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttr
)
public void DrawImage (
    Image image, 
    PointF[] destPoints, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttr
)
public function DrawImage (
    image : Image, 
    destPoints : PointF[], 
    srcRect : RectangleF, 
    srcUnit : GraphicsUnit, 
    imageAttr : ImageAttributes
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの PointF 構造体配列

srcRect

描画する image オブジェクト部分指定する RectangleF 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttr

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

元の未調整描画先の平行四辺形では、その位置によって画面上のイメージ位置決まり抽出元の四角形サイズおよび描画先の平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まり四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
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 );
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Single, Single, RectangleF, GraphicsUnit)

イメージ一部指定位置描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    x As Single, _
    y As Single, _
    srcRect As RectangleF, _
    srcUnit As GraphicsUnit _
)
Dim instance As Graphics
Dim image As Image
Dim x As Single
Dim y As Single
Dim srcRect As RectangleF
Dim srcUnit As GraphicsUnit

instance.DrawImage(image, x, y, srcRect, srcUnit)
public void DrawImage (
    Image image,
    float x,
    float y,
    RectangleF srcRect,
    GraphicsUnit srcUnit
)
public:
void DrawImage (
    Image^ image, 
    float x, 
    float y, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit
)
public void DrawImage (
    Image image, 
    float x, 
    float y, 
    RectangleF srcRect, 
    GraphicsUnit srcUnit
)
public function DrawImage (
    image : Image, 
    x : float, 
    y : float, 
    srcRect : RectangleF, 
    srcUnit : GraphicsUnit
)

パラメータ

image

描画する Image

x

描画イメージ左上隅の x 座標

y

描画イメージ左上隅の y 座標

srcRect

描画する Image部分指定する RectangleF 構造体

srcUnit

srcRect パラメータ使用する単位指定する GraphicsUnit 列挙体のメンバ

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

抽出元の四角形サイズによって、スケーリングされない元のイメージのどの部分画面描画されるかが決まります

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
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:
   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;
    float y = 100;

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

    // Draw image to screen.
    e.get_Graphics().DrawImage(newImage, x, y, srcRect, units);
} //DrawImage2FloatRectF
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle)

指定した位置指定したサイズで、指定した Image描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

四角形位置によって画面上のイメージ位置決まり、元のイメージサイズ四角形サイズによって描画イメージスケーリング決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Single, _
    srcY As Single, _
    srcWidth As Single, _
    srcHeight As Single, _
    srcUnit As GraphicsUnit, _
    imageAttrs As ImageAttributes _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Single
Dim srcY As Single
Dim srcWidth As Single
Dim srcHeight As Single
Dim srcUnit As GraphicsUnit
Dim imageAttrs As ImageAttributes

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs)
public void DrawImage (
    Image image,
    Rectangle destRect,
    float srcX,
    float srcY,
    float srcWidth,
    float srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttrs
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttrs
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttrs
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : float, 
    srcY : float, 
    srcWidth : float, 
    srcHeight : float, 
    srcUnit : GraphicsUnit, 
    imageAttrs : ImageAttributes
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttrs

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

元の未調整描画先の四角形では、その位置によって画面上のイメージ位置決まり抽出元および描画先の四角形サイズによって描画イメージスケーリング決まり抽出元の四角形サイズによって画面描画する元のイメージ部分決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Point)

指定した位置に、指定した Image を元の物理サイズ描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Point[])

指定した Image指定した場所に指定した形状とサイズ描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destPoints As Point() _
)
Dim instance As Graphics
Dim image As Image
Dim destPoints As Point()

instance.DrawImage(image, destPoints)
public void DrawImage (
    Image image,
    Point[] destPoints
)
public:
void DrawImage (
    Image^ image, 
    array<Point>^ destPoints
)
public void DrawImage (
    Image image, 
    Point[] destPoints
)
public function DrawImage (
    image : Image, 
    destPoints : Point[]
)

パラメータ

image

描画する Image

destPoints

平行四辺形定義する 3 つの Point 構造体配列

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

平行四辺形位置によって画面上のイメージ位置決まり、元のイメージサイズおよび平行四辺形サイズ形状によって描画イメージスケーリング傾斜決まります

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Int32, Int32)

指定したイメージ座標ペア指定され位置に元の物理サイズ描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    x As Integer, _
    y As Integer _
)
Dim instance As Graphics
Dim image As Image
Dim x As Integer
Dim y As Integer

instance.DrawImage(image, x, y)
public void DrawImage (
    Image image,
    int x,
    int y
)
public:
void DrawImage (
    Image^ image, 
    int x, 
    int y
)
public void DrawImage (
    Image image, 
    int x, 
    int y
)
public function DrawImage (
    image : Image, 
    x : int, 
    y : int
)

パラメータ

image

描画する Image

x

描画イメージ左上隅の x 座標

y

描画イメージ左上隅の y 座標

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

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
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 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.get_Graphics().DrawImage(newImage, x, y);
} //DrawImage2Int
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Single, _
    srcY As Single, _
    srcWidth As Single, _
    srcHeight As Single, _
    srcUnit As GraphicsUnit, _
    imageAttrs As ImageAttributes, _
    callback As DrawImageAbort, _
    callbackData As IntPtr _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Single
Dim srcY As Single
Dim srcWidth As Single
Dim srcHeight As Single
Dim srcUnit As GraphicsUnit
Dim imageAttrs As ImageAttributes
Dim callback As DrawImageAbort
Dim callbackData As IntPtr

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs,
 callback, callbackData)
public void DrawImage (
    Image image,
    Rectangle destRect,
    float srcX,
    float srcY,
    float srcWidth,
    float srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttrs,
    DrawImageAbort callback,
    IntPtr callbackData
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttrs, 
    DrawImageAbort^ callback, 
    IntPtr callbackData
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttrs, 
    DrawImageAbort callback, 
    IntPtr callbackData
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : float, 
    srcY : float, 
    srcWidth : float, 
    srcHeight : float, 
    srcUnit : GraphicsUnit, 
    imageAttrs : ImageAttributes, 
    callback : DrawImageAbort, 
    callbackData : IntPtr
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttrs

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

callbackData

DrawImage メソッド実行停止するかどうかチェックするときに使用するGraphics.DrawImageAbort デリゲート追加データ指定する値。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整描画先の四角形では、その位置によって画面上のイメージ位置決まり抽出元の四角形サイズおよび描画先の四角形サイズ形状によって描画イメージスケーリング決まります

この例では callBackData パラメータを渡すオーバーロード使用するため、Graphics.DrawImageAbort コールバックfalse返します。これにより、DrawImage メソッド続行し調整済みイメージ画面描画されます。

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
// 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));
    }
}
   // 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 boolean DrawImageCallback8(IntPtr callBackData) 
{    
    // Test for call that passes callBackData parameter.
    if (callBackData.Equals( IntPtr.Zero)) { 
        // If no callBackData passed, abort DrawImage method.
        return true ;
    }
    else {
        // If callBackData passed, continue DrawImage method.
        return false ;
    }
} //DrawImageCallback8

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;
    float y = 50;
    float width = 150;
    float height = 150;
    GraphicsUnit units = GraphicsUnit.Pixel;

    // Draw original image to screen.
    e.get_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);

    try {
            // Draw adjusted image to screen.
        e.get_Graphics().DrawImage(newImage, destRect2, x, y, width,
            height, units, imageAttr, imageCallback, imageCallbackData);
    }
    catch(System.Exception  ex) {    
        e.get_Graphics().DrawString(ex.ToString(), new Font("Arial",
 8), 
            Brushes.get_Black(), new PointF(0, 0));
    }
} //DrawImageRect4FloatAttribAbortData
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

指定した位置指定したサイズで、指定した Image指定した部分描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Single, _
    srcY As Single, _
    srcWidth As Single, _
    srcHeight As Single, _
    srcUnit As GraphicsUnit, _
    imageAttrs As ImageAttributes, _
    callback As DrawImageAbort _
)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Single
Dim srcY As Single
Dim srcWidth As Single
Dim srcHeight As Single
Dim srcUnit As GraphicsUnit
Dim imageAttrs As ImageAttributes
Dim callback As DrawImageAbort

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs,
 callback)
public void DrawImage (
    Image image,
    Rectangle destRect,
    float srcX,
    float srcY,
    float srcWidth,
    float srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttrs,
    DrawImageAbort callback
)
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttrs, 
    DrawImageAbort^ callback
)
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttrs, 
    DrawImageAbort callback
)
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : float, 
    srcY : float, 
    srcWidth : float, 
    srcHeight : float, 
    srcUnit : GraphicsUnit, 
    imageAttrs : ImageAttributes, 
    callback : DrawImageAbort
)

パラメータ

image

描画する Image

destRect

描画イメージ位置サイズ指定する Rectangle 構造体イメージは、四角形合わせてスケーリングされます

srcX

描画するソース イメージ一部左上隅の x 座標

srcY

描画するソース イメージ一部左上隅の y 座標

srcWidth

描画するソース イメージ一部の幅。

srcHeight

描画するソース イメージ一部の高さ。

srcUnit

抽出元の四角形決定するために使用する単位指定する GraphicsUnit 列挙体のメンバ

imageAttrs

image オブジェクトカラー変更情報ガンマ情報指定する ImageAttributes。

callback

イメージ描画時に呼び出すメソッド指定する Graphics.DrawImageAbort デリゲート。このメソッドは、アプリケーションにより決定され基準に従って実行されDrawImage メソッド停止するかどうかチェックするため頻繁に呼び出されます。

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートコールバック メソッド定義します。その定義は単純で、DrawImage メソッドnull 値callBackData パラメータ呼び出しを行うかどうかテストするだけです。この例の本文は、次の処理を実行します

元の未調整描画先の四角形では、その位置によって画面上のイメージ位置決まり抽出元の四角形サイズおよび描画先の四角形サイズ形状によって描画イメージスケーリング決まります

この例では callBackData パラメータ渡さないオーバーロード使用するため、Graphics.DrawImageAbort コールバックtrue返します。これにより、DrawImage メソッド終了し、例に含まれる例外処理コードは、イメージ描画せずに、例外テキスト出力します

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
Public 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
// 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;
    }
}
public 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));
    }
}
   // 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;
      }
   }

public:
   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) );
      }
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawImage メソッド (Image, Single, Single)

指定した位置に、指定した Image を元の物理サイズ描画ます。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawImage ( _
    image As Image, _
    x As Single, _
    y As Single _
)
Dim instance As Graphics
Dim image As Image
Dim x As Single
Dim y As Single

instance.DrawImage(image, x, y)
public void DrawImage (
    Image image,
    float x,
    float y
)
public:
void DrawImage (
    Image^ image, 
    float x, 
    float y
)
public void DrawImage (
    Image image, 
    float x, 
    float y
)
public function DrawImage (
    image : Image, 
    x : float, 
    y : float
)

パラメータ

image

描画する Image

x

描画イメージ左上隅の x 座標

y

描画イメージ左上隅の y 座標

例外例外
例外種類条件

ArgumentNullException

imagenull 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

次の例は、Windows フォームでの使用意図してデザインされており、Paint イベント ハンドラパラメータである PaintEventArgse が必要です。このコード次のアクション実行します

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
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 void DrawImage2Float(PaintEventArgs
 e) 
{
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");

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

    // Draw image to screen.
    e.get_Graphics().DrawImage(newImage, x, y);
} //DrawImage2Float
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Graphics.DrawImage」の関連用語

Graphics.DrawImageのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Graphics.DrawImageのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS