Graphics.DrawImage メソッド

定義

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

オーバーロード

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

イメージの一部を指定の位置に描画します。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

DrawImage(Image, Point[])

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

DrawImage(Image, PointF)

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

DrawImage(Image, PointF[])

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

DrawImage(Image, Rectangle)

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

DrawImage(Image, RectangleF)

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

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

イメージの一部を指定の位置に描画します。

DrawImage(Image, Single, Single)

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

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

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

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

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

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

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

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

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

DrawImage(Image, Int32, Int32)

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

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

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

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

イメージの一部を指定の位置に描画します。

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

パラメーター

image
Image

描画する Image

x
Single

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

y
Single

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

srcRect
RectangleF

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージの左上隅を描画する座標を作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

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

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

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

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

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

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

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

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

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

注釈

には Image 、ピクセル幅の値と水平解像度の値 (1 インチあたりのドット数) が格納されます。 画像の物理的な幅 (インチ単位) は、ピクセルの幅を水平方向の解像度で割った値です。 たとえば、ピクセル幅が 360 で、水平方向の解像度が 72 ドット/インチの画像の物理的な幅は 5 インチです。 同様の注釈は、ピクセルの高さと物理的な高さに適用されます。

このメソッドは、物理サイズを使用してイメージの一部を描画するため、ディスプレイ デバイスの解像度 (1 インチあたりのドット数) に関係なく、イメージ部分のサイズはインチ単位で正しく設定されます。 たとえば、画像部分のピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチとします。 このメソッドを呼び出して、解像度が 96 ドット/インチのデバイスでそのイメージ部分を描画すると、レンダリングされるイメージ部分のピクセル幅は (216/72)*96 = 288 になります。

こちらもご覧ください

適用対象

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

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

パラメーター

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

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
Point[]

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

srcRect
Rectangle

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

例外

imagenullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 描画するイメージの部分を選択する四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の平行四辺形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない平行四辺形の場合、位置は画面上の画像を見つけ、四角形のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

パラメーターを使用した callback このオーバーロードは、アプリケーションによって決定された条件に従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
PointF[]

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

srcRect
RectangleF

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

例外

imagenullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 描画するイメージの部分を選択する四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の平行四辺形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない平行四辺形の場合、位置は画面上の画像を見つけ、四角形のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

パラメーターを使用した callback このオーバーロードは、アプリケーションによって決定された条件に従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
Point[]

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

srcRect
Rectangle

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

callbackData
Int32

DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) メソッドの実行を停止するかどうかをチェックするときに使用する、Graphics.DrawImageAbort デリゲートの追加データを指定する値。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 描画するイメージの部分を選択する四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の平行四辺形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない平行四辺形の場合、位置は画面上の画像を見つけ、四角形のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

パラメーターと callbackData パラメーターをcallback持つこのオーバーロードは、アプリケーションによって決定された条件とデータに従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
PointF[]

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

srcRect
RectangleF

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

callbackData
Int32

DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) メソッドの実行を停止するかどうかをチェックするときに使用する、Graphics.DrawImageAbort デリゲートの追加データを指定する値。

例外

imagenullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintPaパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 描画するイメージの部分を選択する四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の平行四辺形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない平行四辺形の場合、位置は画面上の画像を見つけ、四角形のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形を形成します。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形内に収まるように拡大縮小およびせん断されます destPoints

パラメーターと callbackData パラメーターをcallback持つこのオーバーロードは、アプリケーションによって決定された条件とデータに従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションが大きなイメージの描画を開始し、ユーザーが画面から画像をスクロールする場合、アプリケーションで描画を停止できます。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Int32

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

srcY
Int32

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

srcWidth
Int32

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

srcHeight
Int32

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する目的の四角形を作成します。

  • イメージの一部を抽出するソース四角形の座標を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

コピー先の四角形の位置によって画面上のイメージが検索され、ソース四角形とコピー先の四角形のサイズによって描画されるイメージの拡大縮小が決まります。また、元の四角形のサイズによって、元のイメージの画面に描画される部分が決まります。

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

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

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

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

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

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

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

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

注釈

、、、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定srcWidthsrcYします。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Int32

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

srcY
Int32

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

srcWidth
Int32

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

srcHeight
Int32

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する目的の四角形を作成します。

  • イメージの一部を抽出するソース四角形の座標を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の四角形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の四角形の場合、位置は画面上でイメージを検索し、ソース四角形とコピー先の四角形のサイズによって描画されるイメージの拡大縮小が決まります。また、元の四角形のサイズによって、元のイメージの描画部分が画面に描画されます。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

、、、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定srcWidthsrcYします。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Single

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

srcY
Single

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

srcWidth
Single

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

srcHeight
Single

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

srcUnit
GraphicsUnit

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

imageAttrs
ImageAttributes

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する目的の四角形を作成します。

  • イメージの一部を抽出するソース四角形の座標を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の四角形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の四角形の場合、位置は画面上でイメージを検索し、ソース四角形とコピー先の四角形のサイズによって描画されるイメージの拡大縮小が決まります。また、元の四角形のサイズによって、元のイメージの描画部分が画面に描画されます。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

、、、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定srcWidthsrcYします。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Int32

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

srcY
Int32

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

srcWidth
Int32

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

srcHeight
Int32

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

例外

imagenullです。

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

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する対象の四角形を定義するポイントを作成します。

  • 描画するイメージの部分を選択するソース四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加のコピー先の四角形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の四角形の場合、位置は画面上のイメージを検索し、ソース四角形のサイズと、コピー先の四角形のサイズと図形によって、描画されるイメージの拡大縮小が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

、、srcYsrcWidth、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定します。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 オブジェクトで destRect 指定された四角形の内側に収まるように拡大縮小されます。

パラメーターを使用した callback このオーバーロードは、アプリケーションによって決定された条件に従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Single

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

srcY
Single

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

srcWidth
Single

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

srcHeight
Single

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

srcUnit
GraphicsUnit

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

imageAttrs
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

例外

imagenullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する変換先の四角形を定義するポイントを作成します。

  • 描画するイメージの部分を選択するソース四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の変換先の四角形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の四角形の場合、位置は画面上で画像を見つけ、ソース四角形のサイズと移動先の四角形のサイズと形状によって、描画されるイメージの拡大縮小が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

、、srcYsrcWidth、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定します。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

パラメーターを使用した callback このオーバーロードは、アプリケーションによって決定された条件に従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Int32

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

srcY
Int32

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

srcWidth
Int32

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

srcHeight
Int32

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

srcUnit
GraphicsUnit

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

imageAttrs
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

callbackData
IntPtr

nativeint

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

例外

imagenullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する変換先の四角形を定義するポイントを作成します。

  • 描画するイメージの部分を選択するソース四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の変換先の四角形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の四角形の場合、位置は画面上で画像を見つけ、ソース四角形のサイズと移動先の四角形のサイズと形状によって、描画されるイメージの拡大縮小が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

、、srcYsrcWidth、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定します。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

パラメーターと callbackData パラメーターをcallback持つこのオーバーロードは、アプリケーションによって決定された条件とデータに従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Single

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

srcY
Single

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

srcWidth
Single

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

srcHeight
Single

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

srcUnit
GraphicsUnit

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

imageAttrs
ImageAttributes

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

callback
Graphics.DrawImageAbort

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

callbackData
IntPtr

nativeint

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

例外

imagenullです。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、最初にデリゲートのコールバック メソッドをGraphics.DrawImageAbort定義します。定義は単純であり、単にテストして、メソッドが null callBackData パラメーターを使用して呼び出すかどうかをDrawImage確認するだけです。 この例のメイン本文では、次のアクションを実行します。

  • コールバック メソッドのインスタンスを Graphics.DrawImageAbort 作成します。

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する変換先の四角形を定義するポイントを作成します。

  • 描画するイメージの部分を選択するソース四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の変換先の四角形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の四角形の場合、位置は画面上で画像を見つけ、ソース四角形のサイズと移動先の四角形のサイズと形状によって、描画されるイメージの拡大縮小が決まります。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    ' Draw adjusted image to screen.
    Try

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

注釈

、、srcYsrcWidth、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定します。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

パラメーターと callbackData パラメーターをcallback持つこのオーバーロードは、アプリケーションによって決定された条件とデータに従って開始されたイメージの描画を停止する手段を提供します。 たとえば、アプリケーションで大きな画像の描画を開始し、ユーザーが画面から画像をスクロールして、その場合、アプリケーションが描画を停止する可能性があります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcX
Single

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

srcY
Single

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

srcWidth
Single

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

srcHeight
Single

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する目的の四角形の座標を作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

移動先の四角形の位置によって画面に画像が配置され、ソース四角形とコピー先の四角形のサイズによって描画イメージの拡大縮小が決まります。また、元の四角形のサイズによって、元のイメージの画面に描画される部分が決まります。

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

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

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

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

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

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

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

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

注釈

、、srcYsrcWidth、および srcHeight パラメーターはsrcX、描画するオブジェクトの四角形の部分をimage指定します。 四角形は、ソース イメージの左上隅を基準にしています。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

x
Int32

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

y
Int32

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

width
Int32

描画イメージの幅。

height
Int32

描画イメージの高さ。

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する四角形の位置とサイズを作成します。

  • 画像を画面に描画します。

四角形の位置によって画面上のイメージが検索され、元のイメージのサイズと四角形のサイズによって描画イメージの拡大縮小が決まります。

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

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

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

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

    ' Create coordinates for upper-left corner

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

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

注釈

、および height パラメーターによって定義されるyxwidth四角形によって、描画されるイメージの位置とサイズが決まります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

x
Single

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

y
Single

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

width
Single

描画イメージの幅。

height
Single

描画イメージの高さ。

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する四角形の位置とサイズを作成します。

  • 画像を画面に描画します。

四角形の位置によって画面上のイメージが検索され、元のイメージのサイズと四角形のサイズによって描画イメージの拡大縮小が決まります。

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

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

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

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

    ' Create coordinates for upper-left corner

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

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

注釈

、および height パラメーターによって定義されるyxwidth四角形によって、描画されるイメージの位置とサイズが決まります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
PointF[]

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

srcRect
RectangleF

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する変換先の平行四辺形を定義するポイントを作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の平行四辺形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない変換先の平行四辺形の場合、位置は画面上の画像を見つけ、ソース四角形のサイズとコピー先の平行四辺形のサイズと形状によって描画イメージの拡大縮小とせん断が決まります。四角形のサイズによって、元の画像の描画部分が画面に描画されます。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

こちらもご覧ください

適用対象

DrawImage(Image, Effect)

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

パラメーター

image
Image
effect
Effect

適用対象

DrawImage(Image, Point)

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

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

パラメーター

image
Image

描画する Image

point
Point

描画イメージの左上隅の位置を表す Point 構造体。

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージの左上隅を描画するポイントを作成します。

  • スケーリングされていないイメージを画面に描画します。

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

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

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

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

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

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

注釈

には Image 、ピクセル幅の値と水平解像度の値 (1 インチあたりのドット数) が格納されます。 画像の物理的な幅 (インチ単位) は、ピクセルの幅を水平方向の解像度で割った値です。 たとえば、ピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチの画像の物理的な幅は 3 インチです。 同様の注釈は、ピクセルの高さと物理的な高さに適用されます。

このメソッドは、物理サイズを使用してイメージを描画するため、ディスプレイ デバイスの解像度 (1 インチあたりのドット数) に関係なく、イメージのサイズがインチ単位で正しく設定されます。 たとえば、画像のピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチとします。 このメソッドを呼び出して、解像度が 96 ドット/インチのデバイスでそのイメージを描画すると、レンダリングされるイメージのピクセル幅は (216/72)*96 = 288 になります。

こちらもご覧ください

適用対象

DrawImage(Image, Point[])

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

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

パラメーター

image
Image

描画する Image

destPoints
Point[]

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 画像を画面に描画します。

平行四辺形の位置によって画面に画像が配置され、元の画像のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの Point 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターで image 表されるイメージは、パラメーターで destPoints 指定された平行四辺形の形状に合わせて拡大縮小およびせん断されます。

こちらもご覧ください

適用対象

DrawImage(Image, PointF)

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

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

パラメーター

image
Image

描画する Image

point
PointF

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージの左上隅を描画するポイントを作成します。

  • スケーリングされていないイメージを画面に描画します。

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

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

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

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

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

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

注釈

には Image 、ピクセル幅の値と水平解像度の値 (1 インチあたりのドット数) が格納されます。 画像の物理的な幅 (インチ単位) は、ピクセルの幅を水平方向の解像度で割った値です。 たとえば、ピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチの画像の物理的な幅は 3 インチです。 同様の注釈は、ピクセルの高さと物理的な高さに適用されます。

このメソッドは、物理サイズを使用してイメージを描画するため、ディスプレイ デバイスの解像度 (1 インチあたりのドット数) に関係なく、イメージのサイズがインチ単位で正しく設定されます。 たとえば、画像のピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチとします。 このメソッドを呼び出して、解像度が 96 ドット/インチのデバイスでそのイメージを描画すると、レンダリングされるイメージのピクセル幅は (216/72)*96 = 288 になります。

こちらもご覧ください

適用対象

DrawImage(Image, PointF[])

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

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

パラメーター

image
Image

描画する Image

destPoints
PointF[]

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 画像を画面に描画します。

平行四辺形の位置によって画面に画像が配置され、元の画像のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

オブジェクトによって image 表されるイメージは、 パラメーターで destPoints 指定された平行四辺形の形状に合わせて拡大縮小およびせん断されます。

こちらもご覧ください

適用対象

DrawImage(Image, Rectangle)

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

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

パラメーター

image
Image

描画する Image

rect
Rectangle

描画イメージの位置とサイズを指定する Rectangle 構造体。

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する四角形を作成します。

  • 画像を画面に描画します。

四角形の位置によって画面上のイメージが検索され、元のイメージのサイズと四角形のサイズによって描画イメージの拡大縮小が決まります。

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

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

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

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

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

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

注釈

オブジェクトによって image 表されるイメージは、四角形の rect 寸法に合わせてスケーリングされます。

こちらもご覧ください

適用対象

DrawImage(Image, RectangleF)

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

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

パラメーター

image
Image

描画する Image

rect
RectangleF

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する四角形を作成します。

  • 画像を画面に描画します。

四角形の位置は画面上の画像を検索し、画像の元のサイズと四角形のサイズによって描画イメージの拡大縮小が決まります。

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

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

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

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

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

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

注釈

オブジェクトによって image 表されるイメージは、四角形の rect 寸法に合わせてスケーリングされます。

こちらもご覧ください

適用対象

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

イメージの一部を指定の位置に描画します。

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

パラメーター

image
Image

描画する Image

x
Int32

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

y
Int32

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

srcRect
Rectangle

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージの左上隅を描画する座標を作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

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

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

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

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

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

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

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

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

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

注釈

には Image 、ピクセル幅の値と水平解像度の値 (1 インチあたりのドット数) が格納されます。 画像の物理的な幅 (インチ単位) は、ピクセルの幅を水平方向の解像度で割った値です。 たとえば、ピクセル幅が 360 で、水平方向の解像度が 72 ドット/インチの画像の物理的な幅は 5 インチです。 同様の注釈は、ピクセルの高さと物理的な高さに適用されます。

このメソッドは、物理サイズを使用してイメージの一部を描画するため、ディスプレイ デバイスの解像度 (1 インチあたりのドット数) に関係なく、イメージ部分のサイズはインチ単位で正しく設定されます。 たとえば、画像部分のピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチとします。 このメソッドを呼び出して、解像度が 96 ドット/インチのデバイスでそのイメージ部分を描画すると、レンダリングされるイメージ部分のピクセル幅は (216/72)*96 = 288 になります。

こちらもご覧ください

適用対象

DrawImage(Image, Single, Single)

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

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

パラメーター

image
Image

描画する Image

x
Single

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

y
Single

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージの左上隅を描画するポイントの座標を作成します。

  • スケーリングされていないイメージを画面に描画します。

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

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

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

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

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

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

注釈

には Image 、ピクセル幅の値と水平解像度の値 (1 インチあたりのドット数) が格納されます。 画像の物理的な幅 (インチ単位) は、ピクセルの幅を水平方向の解像度で割った値です。 たとえば、ピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチの画像の物理的な幅は 3 インチです。 同様の注釈は、ピクセルの高さと物理的な高さに適用されます。

このメソッドは、物理サイズを使用してイメージを描画するため、ディスプレイ デバイスの解像度 (1 インチあたりのドット数) に関係なく、イメージのサイズがインチ単位で正しく設定されます。 たとえば、画像のピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチとします。 このメソッドを呼び出して、解像度が 96 ドット/インチのデバイスでそのイメージを描画すると、レンダリングされるイメージのピクセル幅は (216/72)*96 = 288 になります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
Point[]

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

srcRect
Rectangle

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 描画するイメージの部分を選択する四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 画像を画面に描画します。

平行四辺形の位置によって画面に画像が配置され、四角形のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

private:
   void DrawImageParaRect( PaintEventArgs^ e )
   {

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの Point 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
PointF[]

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

srcRect
RectangleF

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する変換先の平行四辺形を定義するポイントを作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

コピー先の平行四辺形の位置によって、画面上に画像が配置され、ソースの四角形のサイズとコピー先の平行四辺形のサイズと形状によって、描画されるイメージの拡大縮小とせん断が決まります。また、四角形のサイズによって、元の画像が画面に描画される部分が決まります。

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

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

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

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの PointF 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

こちらもご覧ください

適用対象

DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

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

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

パラメーター

image
Image

描画する Image

destRect
Rectangle

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

srcRect
Rectangle

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する目的の四角形を作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

移動先の四角形の位置によって画面に画像が配置され、ソース四角形とコピー先の四角形のサイズによって描画イメージの拡大縮小が決まります。また、元の四角形のサイズによって、元のイメージの画面に描画される部分が決まります。

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

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

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

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

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

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

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

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

注釈

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

こちらもご覧ください

適用対象

DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

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

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

パラメーター

image
Image

描画する Image

destRect
RectangleF

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

srcRect
RectangleF

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

srcUnit
GraphicsUnit

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する目的の四角形を作成します。

  • イメージの一部を抽出するソース四角形を作成します。

  • ソース四角形の測定単位をピクセルに設定します。

  • 画像を画面に描画します。

移動先の四角形の位置によって画面に画像が配置され、ソース四角形とコピー先の四角形のサイズによって描画イメージの拡大縮小が決まります。また、元の四角形のサイズによって、元のイメージの画面に描画される部分が決まります。

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

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

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

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

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

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

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

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

注釈

パラメーターは srcRect 、描画するオブジェクトの四角形の image 部分を指定します。 この部分は、 パラメーターで destRect 指定された四角形内に収まるように拡大縮小されます。

こちらもご覧ください

適用対象

DrawImage(Image, Int32, Int32)

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

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

パラメーター

image
Image

描画する Image

x
Int32

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

y
Int32

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

例外

imagenullです。

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

  • 例のフォルダー内の SampImag.jpg 例のフォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージの左上隅を描画するポイントの座標を作成します。

  • スケーリングされていないイメージを描画します。

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

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

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

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

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

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

注釈

には Image 、ピクセル幅の値と水平解像度の値 (1 インチあたりのドット数) が格納されます。 画像の物理的な幅 (インチ単位) は、ピクセルの幅を水平方向の解像度で割った値です。 たとえば、ピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチの画像の物理的な幅は 3 インチです。 同様の注釈は、ピクセルの高さと物理的な高さに適用されます。

メソッドは DrawImage 、物理サイズを使用してイメージを描画するため、ディスプレイ デバイスの解像度 (1 インチあたりのドット数) に関係なく、イメージのサイズがインチ単位で正しく設定されます。 たとえば、画像のピクセル幅が 216 で、水平方向の解像度が 72 ドット/インチとします。 を呼び出 DrawImage して、解像度が 96 ドット/インチのデバイスでそのイメージを描画する場合、レンダリングされるイメージのピクセル幅は (216/72)*96 = 288 になります。

こちらもご覧ください

適用対象

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

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

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

パラメーター

image
Image

描画する Image

destPoints
Point[]

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

srcRect
Rectangle

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

srcUnit
GraphicsUnit

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

imageAttr
ImageAttributes

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

例外

imagenullです。

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

  • 例の フォルダーに SampImag.jpg JPEG ファイルから画像を作成します。

  • イメージを描画する平行四辺形を定義するポイントを作成します。

  • 描画するイメージの部分を選択する四角形を作成します。

  • グラフィックス描画単位をピクセルに設定します。

  • 元の画像を画面に描画します。

  • 調整されたイメージを描画する追加の平行四辺形を作成します。

  • 調整されたイメージの属性を作成し、通常よりも大きいガンマ値を持つよう設定します。

  • 調整した画像を画面に描画します。

元の調整されていない平行四辺形の場合、位置は画面上の画像を見つけ、四角形のサイズと平行四辺形のサイズと形状によって、描画されたイメージの拡大縮小とせん断が決まります。

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

      // Create parallelogram for drawing image.
      Point ulCorner1 = Point(100,100);
      Point urCorner1 = Point(325,100);
      Point llCorner1 = Point(150,250);
      array<Point>^ destPara1 = {ulCorner1,urCorner1,llCorner1};

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

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

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

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

      // Draw adjusted image to screen.
      e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr );
   }
private void DrawImageParaRectAttrib(PaintEventArgs e)
{
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create parallelogram for drawing image.
    Point ulCorner1 = new Point(100, 100);
    Point urCorner1 = new Point(325, 100);
    Point llCorner1 = new Point(150, 250);
    Point[] destPara1 = {ulCorner1, urCorner1, llCorner1};
             
    // Create rectangle for source image.
    Rectangle srcRect = new Rectangle(50, 50, 150, 150);
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
             
    // Create parallelogram for drawing adjusted image.
    Point ulCorner2 = new Point(325, 100);
    Point urCorner2 = new Point(550, 100);
    Point llCorner2 = new Point(375, 250);
    Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}
Private Sub DrawImageParaRectAttrib(ByVal e As PaintEventArgs)

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

    ' Create parallelogram for drawing image.
    Dim ulCorner1 As New Point(100, 100)
    Dim urCorner1 As New Point(325, 100)
    Dim llCorner1 As New Point(150, 250)
    Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}

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

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

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

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

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

注釈

パラメーターは destPoints 、平行四辺形の 3 つのポイントを指定します。 3 つの Point 構造体は、平行四辺形の左上、右上、左下の角を表します。 4 番目の点は、最初の 3 つから外挿され、平行四辺形が形成されます。

パラメーターは srcRect 、描画するオブジェクトの四角形のimage 部分を指定します。 この部分は、 パラメーターで指定された平行四辺形の内側に収まるように拡大縮小され、 destPoints せん断されます。

こちらもご覧ください

適用対象