次の方法で共有


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

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

Overloads Public Sub DrawImage( _
   ByVal image As Image, _   ByVal x As Single, _   ByVal y As Single _)
[C#]
public void DrawImage(Imageimage,floatx,floaty);
[C++]
public: void DrawImage(Image* image,floatx,floaty);
[JScript]
public function DrawImage(
   image : Image,x : float,y : float);

パラメータ

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

戻り値

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

解説

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

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

使用例

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

  • この例が保存されているフォルダの JPEG ファイル SampImag.jpg からイメージを作成します。
  • イメージの左上隅を描画する点の座標を作成します。
  • 画面にスケーリングされないイメージを描画します。
 
Public Sub DrawImage2Float(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 = 100F
Dim y As Single = 100F
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y)
End Sub
        
[C#] 
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);
}
        

[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 オーバーロードの一覧