次の方法で共有


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

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

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

パラメータ

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

戻り値

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

解説

Image オブジェクトは、ピクセル幅の値および水平方向の解像度 (dpi) の値を格納します。イメージの物理的な幅 (インチ) は、ピクセル幅を水平解像度で割った値です。たとえば、ピクセル幅 216、水平解像度 72 dpi のイメージの物理的な幅は 3 インチです。ピクセルの高さと物理的な高さについても同様です。

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

使用例

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

  • example のフォルダで、JPEG ファイル SampImag.jpg からイメージを作成します。
  • イメージの左上隅を描画する点の座標を作成します。
  • スケーリングされないイメージを描画します。
 
Public Sub DrawImage2Int(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
        
[C#] 
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);
}
        

[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 ファミリ, .NET Compact Framework - Windows CE .NET

参照

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