Graphics.DrawImage メソッド (Image, RectangleF)
指定した位置に指定したサイズで、指定した Image オブジェクトを描画します。
Overloads Public Sub DrawImage( _
ByVal image As Image, _ ByVal rect As RectangleF _)
[C#]
public void DrawImage(Imageimage,RectangleFrect);
[C++]
public: void DrawImage(Image* image,RectangleFrect);
[JScript]
public function DrawImage(
image : Image,rect : RectangleF);
パラメータ
- image
描画する Image オブジェクト。 - rect
描画イメージの位置とサイズを指定する RectangleF 構造体。
戻り値
このメソッドは値を返しません。
解説
image オブジェクトによって表されるイメージは、 rect 四角形の大きさに合わせてスケーリングされます。
使用例
[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。
- この例が保存されているフォルダの JPEG ファイル SampImag.jpg からイメージを作成します。
- イメージを描画するための四角形を作成します。
- 画面にイメージを描画します。
[Visual Basic, C#] 四角形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズと四角形のサイズによって描画イメージのスケーリングが決まります。
Public Sub DrawImageRectF(e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim rect As New RectangleF(100F, 100F, 450F, 150F)
' Draw image to screen.
e.Graphics.DrawImage(newImage, rect)
End Sub
[C#]
public void DrawImageRectF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
RectangleF rect = new RectangleF( 100.0F, 100.0F, 450.0F, 150.0F);
// Draw image to screen.
e.Graphics.DrawImage(newImage, rect);
}
[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 オーバーロードの一覧