次の方法で共有


Graphics.DrawImage メソッド (Image, PointF , RectangleF, GraphicsUnit, ImageAttributes)

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

Overloads Public Sub DrawImage( _
   ByVal image As Image, _   ByVal destPoints() As PointF, _   ByVal srcRect As RectangleF, _   ByVal srcUnit As GraphicsUnit, _   ByVal imageAttr As ImageAttributes _)
[C#]
public void DrawImage(Imageimage,PointF[] destPoints,RectangleFsrcRect,GraphicsUnitsrcUnit,ImageAttributesimageAttr);
[C++]
public: void DrawImage(Image* image,PointFdestPoints[],RectangleFsrcRect,GraphicsUnitsrcUnit,ImageAttributes* imageAttr);
[JScript]
public function DrawImage(
   image : Image,destPoints : PointF[],srcRect : RectangleF,srcUnit : GraphicsUnit,imageAttr : ImageAttributes);

パラメータ

  • image
    描画する Image オブジェクト。
  • destPoints
    平行四辺形を定義する 3 つの Point 構造体の配列。
  • srcRect
    描画する image オブジェクトの部分を指定する RectangleF 構造体。
  • srcUnit
    srcRect パラメータで使用する単位を指定する GraphicsUnit 列挙体のメンバ。
  • imageAttr
    image オブジェクトのカラー変更情報とガンマ情報を指定する ImageAttributes オブジェクト。

戻り値

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

解説

destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの Point 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。

描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、 destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。

使用例

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

  • この例が保存されているフォルダの JPEG ファイル SampImag.jpg からイメージを作成します。
  • イメージを描画するための平行四辺形を定義する点を作成します。
  • イメージの一部を抽出するための四角形を作成します。
  • 抽出元の四角形の単位をピクセルに設定します。
  • 画面に元のイメージを描画します。
  • 調整済みイメージを描画するための追加の平行四辺形を作成します。
  • ガンマ値が通常よりも大きくなるように、調整済みイメージの属性を作成して設定します。
  • 画面に調整済みイメージを描画します。

[Visual Basic, C#] 元の未調整の描画先の平行四辺形では、その位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まり、四角形のサイズによって画面に描画する元のイメージの部分が決まります。

 
Public Sub DrawImageParaFRectFAttrib(e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing original image.
Dim ulCorner1 As New PointF(100F, 100F)
Dim urCorner1 As New PointF(325F, 100F)
Dim llCorner1 As New PointF(150F, 250F)
Dim destPara1 As PointF() =  {ulCorner1, urCorner1, llCorner1}
' Create rectangle for source image.
Dim srcRect As New RectangleF(50F, 50F, 150F, 150F)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Create parallelogram for drawing adjusted image.
Dim ulCorner2 As New PointF(325F, 100F)
Dim urCorner2 As New PointF(550F, 100F)
Dim llCorner2 As New PointF(375F, 250F)
Dim destPara2 As PointF() =  {ulCorner2, urCorner2, llCorner2}
' Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units)
' Create image attributes and set large gamma.
Dim imageAttr As New ImageAttributes()
imageAttr.SetGamma(4F)
' Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
imageAttr)
End Sub
        
[C#] 
public void DrawImageParaFRectFAttrib(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing original image.
PointF ulCorner1 = new PointF(100.0F, 100.0F);
PointF urCorner1 = new PointF(325.0F, 100.0F);
PointF llCorner1 = new PointF(150.0F, 250.0F);
PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1};
// Create rectangle for source image.
RectangleF srcRect = new RectangleF( 50.0F, 50.0F, 150.0F, 150.0F);
GraphicsUnit units = GraphicsUnit.Pixel;
// Create parallelogram for drawing adjusted image.
PointF ulCorner2 = new PointF(325.0F, 100.0F);
PointF urCorner2 = new PointF(550.0F, 100.0F);
PointF llCorner2 = new PointF(375.0F, 250.0F);
PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2};
// Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
// Create image attributes and set large gamma.
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetGamma(4.0F);
// Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}
        

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