次の方法で共有


Graphics.DrawImage メソッド

指定した位置に元のサイズで、指定した Image オブジェクトを描画します。

オーバーロードの一覧

指定した位置に、指定した Image オブジェクトを元の物理サイズで描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Point)

[C#] public void DrawImage(Image, Point);

[C++] public: void DrawImage(Image*, Point);

[JScript] public function DrawImage(Image, Point);

指定した Image オブジェクトを指定した場所に指定した形状とサイズで描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Point())

[C#] public void DrawImage(Image, Point[]);

[C++] public: void DrawImage(Image*, Point[]);

[JScript] public function DrawImage(Image, Point[]);

指定した位置に、指定した Image オブジェクトを元の物理サイズで描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, PointF)

[C#] public void DrawImage(Image, PointF);

[C++] public: void DrawImage(Image*, PointF);

[JScript] public function DrawImage(Image, PointF);

指定した Image オブジェクトを指定した場所に指定した形状とサイズで描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, PointF())

[C#] public void DrawImage(Image, PointF[]);

[C++] public: void DrawImage(Image*, PointF[]);

[JScript] public function DrawImage(Image, PointF[]);

指定した位置に指定したサイズで、指定した Image オブジェクトを描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle)

[C#] public void DrawImage(Image, Rectangle);

[C++] public: void DrawImage(Image*, Rectangle);

[JScript] public function DrawImage(Image, Rectangle);

指定した位置に指定したサイズで、指定した Image オブジェクトを描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, RectangleF)

[C#] public void DrawImage(Image, RectangleF);

[C++] public: void DrawImage(Image*, RectangleF);

[JScript] public function DrawImage(Image, RectangleF);

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Sub DrawImage(Image, Integer, Integer)

[C#] public void DrawImage(Image, int, int);

[C++] public: void DrawImage(Image*, int, int);

[JScript] public function DrawImage(Image, int, int);

指定した位置に、指定した Image オブジェクトを元の物理サイズで描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Single, Single)

[C#] public void DrawImage(Image, float, float);

[C++] public: void DrawImage(Image*, float, float);

[JScript] public function DrawImage(Image, float, float);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Point(), Rectangle, GraphicsUnit)

[C#] public void DrawImage(Image, Point[], Rectangle, GraphicsUnit);

[C++] public: void DrawImage(Image*, Point[], Rectangle, GraphicsUnit);

[JScript] public function DrawImage(Image, Point[], Rectangle, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, PointF(), RectangleF, GraphicsUnit)

[C#] public void DrawImage(Image, PointF[], RectangleF, GraphicsUnit);

[C++] public: void DrawImage(Image*, PointF[], RectangleF, GraphicsUnit);

[JScript] public function DrawImage(Image, PointF[], RectangleF, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

[C#] public void DrawImage(Image, Rectangle, Rectangle, GraphicsUnit);

[C++] public: void DrawImage(Image*, Rectangle, Rectangle, GraphicsUnit);

[JScript] public function DrawImage(Image, Rectangle, Rectangle, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)

[C#] public void DrawImage(Image, RectangleF, RectangleF, GraphicsUnit);

[C++] public: void DrawImage(Image*, RectangleF, RectangleF, GraphicsUnit);

[JScript] public function DrawImage(Image, RectangleF, RectangleF, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトを描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Integer, Integer, Integer, Integer)

[C#] public void DrawImage(Image, int, int, int, int);

[C++] public: void DrawImage(Image*, int, int, int, int);

[JScript] public function DrawImage(Image, int, int, int, int);

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

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Sub DrawImage(Image, Integer, Integer, Rectangle, GraphicsUnit)

[C#] public void DrawImage(Image, int, int, Rectangle, GraphicsUnit);

[C++] public: void DrawImage(Image*, int, int, Rectangle, GraphicsUnit);

[JScript] public function DrawImage(Image, int, int, Rectangle, GraphicsUnit);

指定した位置に、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Point(), Rectangle, GraphicsUnit, ImageAttributes)

[C#] public void DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes);

[C++] public: void DrawImage(Image*, Point[], Rectangle, GraphicsUnit, ImageAttributes*);

[JScript] public function DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, PointF(), RectangleF, GraphicsUnit, ImageAttributes)

[C#] public void DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes);

[C++] public: void DrawImage(Image*, PointF[], RectangleF, GraphicsUnit, ImageAttributes*);

[JScript] public function DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes);

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

[Visual Basic] Overloads Public Sub DrawImage(Image, Single, Single, RectangleF, GraphicsUnit)

[C#] public void DrawImage(Image, float, float, RectangleF, GraphicsUnit);

[C++] public: void DrawImage(Image*, float, float, RectangleF, GraphicsUnit);

[JScript] public function DrawImage(Image, float, float, RectangleF, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトを描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Single, Single, Single, Single)

[C#] public void DrawImage(Image, float, float, float, float);

[C++] public: void DrawImage(Image*, float, float, float, float);

[JScript] public function DrawImage(Image, float, float, float, float);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Point(), Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

[C#] public void DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

[C++] public: void DrawImage(Image*, Point[], Rectangle, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*);

[JScript] public function DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, PointF(), RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

[C#] public void DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

[C++] public: void DrawImage(Image*, PointF[], RectangleF, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*);

[JScript] public function DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Point(), Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Integer)

[C#] public void DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, int);

[C++] public: void DrawImage(Image*, Point[], Rectangle, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*, int);

[JScript] public function DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, int);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, PointF(), RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Integer)

[C#] public void DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, int);

[C++] public: void DrawImage(Image*, PointF[], RectangleF, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*, int);

[JScript] public function DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, int);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Integer, Integer, Integer, Integer, GraphicsUnit)

[C#] public void DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit);

[C++] public: void DrawImage(Image*, Rectangle, int, int, int, int, GraphicsUnit);

[JScript] public function DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit)

[C#] public void DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit);

[C++] public: void DrawImage(Image*, Rectangle, float, float, float, float, GraphicsUnit);

[JScript] public function DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Integer, Integer, Integer, Integer, GraphicsUnit, ImageAttributes)

[C#] public void DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes);

[C++] public: void DrawImage(Image*, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes*);

[JScript] public function DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes)

[C#] public void DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes);

[C++] public: void DrawImage(Image*, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes*);

[JScript] public function DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Integer, Integer, Integer, Integer, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

[C#] public void DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

[C++] public: void DrawImage(Image*, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*);

[JScript] public function DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)

[C#] public void DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

[C++] public: void DrawImage(Image*, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*);

[JScript] public function DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Integer, Integer, Integer, Integer, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr)

[C#] public void DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr);

[C++] public: void DrawImage(Image*, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*, IntPtr);

[JScript] public function DrawImage(Image, Rectangle, int, int, int, int, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr);

指定した位置に指定したサイズで、指定した Image オブジェクトの指定した部分を描画します。

[Visual Basic] Overloads Public Sub DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr)

[C#] public void DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr);

[C++] public: void DrawImage(Image*, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes*, Graphics.DrawImageAbort*, IntPtr);

[JScript] public function DrawImage(Image, Rectangle, float, float, float, float, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr);

使用例

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

  • DrawImageAbort コールバック メソッドのインスタンスを作成します。
  • この例が保存されているフォルダの JPEG ファイル SampImag.jpg からイメージを作成します。
  • イメージを描画するための四角形を定義する点を作成します。
  • 描画するイメージの一部を選択するための四角形を作成します。
  • グラフィックス描画単位をピクセルに設定します。
  • 画面に元のイメージを描画します。
  • 調整済みイメージを描画するための追加の四角形を作成します。
  • ガンマ値が通常よりも大きくなるように、調整済みイメージの属性を作成して設定します。
  • 画面に調整済みイメージを描画します。

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

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

[Visual Basic, C#] メモ   ここでは、DrawImage のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Private Function DrawImageCallback(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(e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback)
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 = 50F
Dim y As Single = 50F
Dim width As Single = 150F
Dim height As Single = 150F
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(4F)
' 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
        
[C#] 
// Define DrawImageAbort callback method.
private bool DrawImageCallback(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(DrawImageCallback);
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));
}
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Graphics クラス | Graphics メンバ | System.Drawing 名前空間