Graphics.DrawImage メソッド (Image, Point)
指定した位置に、指定した Image オブジェクトを元の物理サイズで描画します。
Overloads Public Sub DrawImage( _
ByVal image As Image, _ ByVal point As Point _)
[C#]
public void DrawImage(Imageimage,Pointpoint);
[C++]
public: void DrawImage(Image* image,Pointpoint);
[JScript]
public function DrawImage(
image : Image,point : Point);
パラメータ
戻り値
このメソッドは値を返しません。
解説
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 DrawImagePoint(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
[C#]
public 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);
}
[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 オーバーロードの一覧