次の方法で共有


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

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

Overloads Public Sub DrawImage( _
   ByVal image As Image, _   ByVal x As Integer, _   ByVal y As Integer, _   ByVal width As Integer, _   ByVal height As Integer _)
[C#]
public void DrawImage(Imageimage,intx,inty,intwidth,intheight);
[C++]
public: void DrawImage(Image* image,intx,inty,intwidth,intheight);
[JScript]
public function DrawImage(
   image : Image,x : int,y : int,width : int,height : int);

パラメータ

  • image
    描画する Image オブジェクト。
  • x
    描画イメージの左上隅の x 座標。
  • y
    描画イメージの左上隅の y 座標。
  • width
    描画イメージの幅。
  • height
    描画イメージの高さ。

戻り値

このメソッドは値を返しません。

解説

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

使用例

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

  • この例が保存されているフォルダの JPEG ファイル SampImag.jpg からイメージを作成します。
  • イメージを描画するための四角形の位置とサイズを作成します。
  • 画面にイメージを描画します。

[Visual Basic, C#] 四角形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズと四角形のサイズによって描画イメージのスケーリングが決まります。

 
Public Sub DrawImage4Int(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
        
[C#] 
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);
}
        

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

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Graphics クラス | Graphics メンバ | System.Drawing 名前空間 | Graphics.DrawImage オーバーロードの一覧