Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As PointF(), _ srcRect As RectangleF, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes, _ callback As DrawImageAbort, _ callbackData As Integer _ )
Dim instance As Graphics Dim image As Image Dim destPoints As PointF() Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes Dim callback As DrawImageAbort Dim callbackData As Integer instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, callbackData)
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData )
public: void DrawImage ( Image^ image, array<PointF>^ destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr, DrawImageAbort^ callback, int callbackData )
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData )
public function DrawImage ( image : Image, destPoints : PointF[], srcRect : RectangleF, srcUnit : GraphicsUnit, imageAttr : ImageAttributes, callback : DrawImageAbort, callbackData : int )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。
callback パラメータおよび callbackData パラメータを指定したオーバーロードによって、アプリケーションにより決定された基準とデータに従って開始されたイメージの描画を停止する手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、PaPaint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の平行四辺形では、その位置によって画面上のイメージの位置が決まり、四角形のサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
この例では callBackData パラメータを渡すオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは false を返します。これにより、DrawImage メソッドは続行し、調整済みイメージが画面に描画されます。
Private Function DrawImageCallback4(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageParaFRectAttribAbortData(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback4) Dim imageCallbackData As Integer = 1 ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing original image. Dim ulCorner1 As New PointF(100.0F, 100.0F) Dim urCorner1 As New PointF(325.0F, 100.0F) Dim llCorner1 As New PointF(150.0F, 250.0F) Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1} ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New PointF(325.0F, 100.0F) Dim urCorner2 As New PointF(550.0F, 100.0F) Dim llCorner2 As New PointF(375.0F, 250.0F) 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(4.0F) Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr, imageCallback, imageCallbackData) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback4(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageParaFRectAttribAbortData(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback4); int imageCallbackData = 1; // 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); try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback4( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageParaFRectAttribAbortData( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback4 ); int imageCallbackData = 1; // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing original image. PointF ulCorner1 = PointF(100.0F,100.0F); PointF urCorner1 = PointF(325.0F,100.0F); PointF llCorner1 = PointF(150.0F,250.0F); array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1}; // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Create parallelogram for drawing adjusted image. PointF ulCorner2 = PointF(325.0F,100.0F); PointF urCorner2 = PointF(550.0F,100.0F); PointF llCorner2 = PointF(375.0F,250.0F); array<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 = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, PointF)
アセンブリ: System.Drawing (system.drawing.dll 内)



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

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
Public Sub DrawImagePointF(ByVal 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 PointF(100.0F, 100.0F) ' Draw image to screen. e.Graphics.DrawImage(newImage, ulCorner) End Sub

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Int32, Int32, Int32, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ x As Integer, _ y As Integer, _ width As Integer, _ height As Integer _ )
Dim instance As Graphics Dim image As Image Dim x As Integer Dim y As Integer Dim width As Integer Dim height As Integer instance.DrawImage(image, x, y, width, height)



次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
四角形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズと四角形のサイズによって描画イメージのスケーリングが決まります。
Public Sub DrawImage4Int(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create coordinates for upper-left corner ' of image and for size of image. Dim x As Integer = 100 Dim y As Integer = 100 Dim width As Integer = 450 Dim height As Integer = 150 ' Draw image to screen. e.Graphics.DrawImage(newImage, x, y, width, height) End Sub
public void DrawImage4Int(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner. // of image and for size of image. int x = 100; int y = 100; int width = 450; int height = 150; // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, width, height); }
public: void DrawImage4Int( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create coordinates for upper-left corner. // of image and for size of image. int x = 100; int y = 100; int width = 450; int height = 150; // Draw image to screen. e->Graphics->DrawImage( newImage, x, y, width, height ); }
public void DrawImage4Int(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner. // of image and for size of image. int x = 100; int y = 100; int width = 450; int height = 150; // Draw image to screen. e.get_Graphics().DrawImage(newImage, x, y, width, height); } //DrawImage4Int

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, RectangleF)
アセンブリ: System.Drawing (system.drawing.dll 内)




次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
四角形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズと四角形のサイズによって描画イメージのスケーリングが決まります。
Public Sub DrawImageRectF(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim rect As New RectangleF(100.0F, 100.0F, 450.0F, 150.0F) ' Draw image to screen. e.Graphics.DrawImage(newImage, rect) End Sub
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); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As PointF(), _ srcRect As RectangleF, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes, _ callback As DrawImageAbort _ )
Dim instance As Graphics Dim image As Image Dim destPoints As PointF() Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes Dim callback As DrawImageAbort instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback)
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public: void DrawImage ( Image^ image, array<PointF>^ destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr, DrawImageAbort^ callback )
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public function DrawImage ( image : Image, destPoints : PointF[], srcRect : RectangleF, srcUnit : GraphicsUnit, imageAttr : ImageAttributes, callback : DrawImageAbort )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。
callback パラメータを指定したオーバーローによって、アプリケーションにより決定された基準に従って開始されたイメージの描画を停止するための手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の平行四辺形では、その位置によって画面上のイメージの位置が決まり、四角形のサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
この例では callBackData パラメータを渡さないオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは true を返します。これにより、DrawImage メソッドは終了し、例に含まれる例外処理コードは、イメージを描画せずに、例外テキストを出力します。
Private Function DrawImageCallback3(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageParaFRectAttribAbort(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback3) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing original image. Dim ulCorner1 As New PointF(100.0F, 100.0F) Dim urCorner1 As New PointF(325.0F, 100.0F) Dim llCorner1 As New PointF(150.0F, 250.0F) Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1} ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New PointF(325.0F, 100.0F) Dim urCorner2 As New PointF(550.0F, 100.0F) Dim llCorner2 As New PointF(375.0F, 250.0F) 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(4.0F) Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr, imageCallback) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback3(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageParaFRectAttribAbort(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback3); // 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); try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback3( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageParaFRectAttribAbort( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback3 ); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing original image. PointF ulCorner1 = PointF(100.0F,100.0F); PointF urCorner1 = PointF(325.0F,100.0F); PointF llCorner1 = PointF(150.0F,250.0F); array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1}; // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Create parallelogram for drawing adjusted image. PointF ulCorner2 = PointF(325.0F,100.0F); PointF urCorner2 = PointF(550.0F,100.0F); PointF llCorner2 = PointF(375.0F,250.0F); array<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 = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, RectangleF, RectangleF, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As RectangleF, _ srcRect As RectangleF, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim destRect As RectangleF Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit instance.DrawImage(image, destRect, srcRect, srcUnit)
public void DrawImage ( Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit )
public: void DrawImage ( Image^ image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit )
public void DrawImage ( Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit )
public function DrawImage ( image : Image, destRect : RectangleF, srcRect : RectangleF, srcUnit : GraphicsUnit )



次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
描画先の四角形の位置によって画面上のイメージの位置が決まり、抽出元および描画先の四角形のサイズによって描画イメージのスケーリングが決まり、抽出元の四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageRectFRectF(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim destRect As New RectangleF(100.0F, 100.0F, 450.0F, 150.0F) ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, destRect, srcRect, units) End Sub
public void DrawImageRectFRectF(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying image. RectangleF destRect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F); // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, srcRect, units); }
public: void DrawImageRectFRectF( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying image. RectangleF destRect = RectangleF(100.0F,100.0F,450.0F,150.0F); // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, destRect, srcRect, units ); }
public void DrawImageRectFRectF(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying image. RectangleF destRect = new RectangleF(100, 100, 450, 150); // Create rectangle for source image. RectangleF srcRect = new RectangleF(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.get_Graphics().DrawImage(newImage, destRect, srcRect, units); } //DrawImageRectFRectF

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As Point(), _ srcRect As Rectangle, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim destPoints As Point() Dim srcRect As Rectangle Dim srcUnit As GraphicsUnit instance.DrawImage(image, destPoints, srcRect, srcUnit)
public: void DrawImage ( Image^ image, array<Point>^ destPoints, Rectangle srcRect, GraphicsUnit srcUnit )
public function DrawImage ( image : Image, destPoints : Point[], srcRect : Rectangle, srcUnit : GraphicsUnit )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの Point 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
平行四辺形の位置によって画面上のイメージの位置が決まり、四角形のサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
Public Sub DrawImageParaRect(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing image. Dim ulCorner As New Point(100, 100) Dim urCorner As New Point(325, 100) Dim llCorner As New Point(150, 250) Dim destPara As Point() = {ulCorner, urCorner, llCorner} ' Create rectangle for source image. Dim srcRect As New Rectangle(50, 50, 150, 150) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, destPara, srcRect, units) End Sub
public void DrawImageParaRect(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(325, 100); Point llCorner = new Point(150, 250); Point[] destPara = {ulCorner, urCorner, llCorner}; // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, destPara, srcRect, units); }
public: void DrawImageParaRect( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing image. Point ulCorner = Point(100,100); Point urCorner = Point(325,100); Point llCorner = Point(150,250); array<Point>^ destPara = {ulCorner,urCorner,llCorner}; // Create rectangle for source image. Rectangle srcRect = Rectangle(50,50,150,150); GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, destPara, srcRect, units ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As PointF(), _ srcRect As RectangleF, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim destPoints As PointF() Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit instance.DrawImage(image, destPoints, srcRect, srcUnit)
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit )
public: void DrawImage ( Image^ image, array<PointF>^ destPoints, RectangleF srcRect, GraphicsUnit srcUnit )
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit )
public function DrawImage ( image : Image, destPoints : PointF[], srcRect : RectangleF, srcUnit : GraphicsUnit )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
描画先の平行四辺形の位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まり、四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageParaFRectF(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing image. Dim ulCorner As New PointF(100.0F, 100.0F) Dim urCorner As New PointF(550.0F, 100.0F) Dim llCorner As New PointF(150.0F, 250.0F) Dim destPara As PointF() = {ulCorner, urCorner, llCorner} ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, destPara, srcRect, units) End Sub
public void DrawImageParaFRectF(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing image. PointF ulCorner = new PointF(100.0F, 100.0F); PointF urCorner = new PointF(550.0F, 100.0F); PointF llCorner = new PointF(150.0F, 250.0F); PointF[] destPara = {ulCorner, urCorner, llCorner}; // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, destPara, srcRect, units); }
public: void DrawImageParaFRectF( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing image. PointF ulCorner = PointF(100.0F,100.0F); PointF urCorner = PointF(550.0F,100.0F); PointF llCorner = PointF(150.0F,250.0F); array<PointF>^ destPara = {ulCorner,urCorner,llCorner}; // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, destPara, srcRect, units ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Rectangle, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcRect As Rectangle, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcRect As Rectangle Dim srcUnit As GraphicsUnit instance.DrawImage(image, destRect, srcRect, srcUnit)
public: void DrawImage ( Image^ image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit )
public function DrawImage ( image : Image, destRect : Rectangle, srcRect : Rectangle, srcUnit : GraphicsUnit )



次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
描画先の四角形の位置によって画面上のイメージの位置が決まり、抽出元および描画先の四角形のサイズによって描画イメージのスケーリングが決まり、抽出元の四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageRectRect(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim destRect As New Rectangle(100, 100, 450, 150) ' Create rectangle for source image. Dim srcRect As New Rectangle(50, 50, 150, 150) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, destRect, srcRect, units) End Sub
public void DrawImageRectRect(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, srcRect, units); }
public: void DrawImageRectRect( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying image. Rectangle destRect = Rectangle(100,100,450,150); // Create rectangle for source image. Rectangle srcRect = Rectangle(50,50,150,150); GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, destRect, srcRect, units ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Int32, Int32, Rectangle, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ x As Integer, _ y As Integer, _ srcRect As Rectangle, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim x As Integer Dim y As Integer Dim srcRect As Rectangle Dim srcUnit As GraphicsUnit instance.DrawImage(image, x, y, srcRect, srcUnit)
public function DrawImage ( image : Image, x : int, y : int, srcRect : Rectangle, srcUnit : GraphicsUnit )


Image は、ピクセル幅の値および水平方向の解像度 (dpi) の値を格納します。イメージの物理的な幅 (インチ) は、ピクセル幅を水平解像度で割った値です。たとえば、幅が 360 ピクセルで、水平解像度が 72 dpi のイメージの物理的な幅は 5 インチになります。ピクセルの高さと物理的な高さについても同様です。
このメソッドは物理サイズを使用してイメージの一部を描画するため、イメージのその部分は表示デバイスの解像度 (dpi) に関係なく、インチで指定された正しいサイズで描画されます。たとえば、幅が 216 ピクセルで、水平解像度が 72 dpi であるイメージの一部を想定します。このメソッドを呼び出して、96 dpi (1 インチあたりのドット数) の解像度のデバイスにそのイメージの部分を描画すると、レンダリングされたイメージの幅は (216/72)*96 = 288 (ピクセル) になります。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
抽出元の四角形のサイズによって、スケーリングされない元のイメージのどの部分が画面に描画されるかが決まります。
Public Sub DrawImage2IntRect(ByVal 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 ' Create rectangle for source image. Dim srcRect As New Rectangle(50, 50, 150, 150) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, x, y, srcRect, units) End Sub
public void DrawImage2IntRect(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner of image. int x = 100; int y = 100; // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, srcRect, units); }
public: void DrawImage2IntRect( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create coordinates for upper-left corner of image. int x = 100; int y = 100; // Create rectangle for source image. Rectangle srcRect = Rectangle(50,50,150,150); GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, x, y, srcRect, units ); }
public void DrawImage2IntRect(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner of image. int x = 100; int y = 100; // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.get_Graphics().DrawImage(newImage, x, y, srcRect, units); } //DrawImage2IntRect

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As Point(), _ srcRect As Rectangle, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes _ )
Dim instance As Graphics Dim image As Image Dim destPoints As Point() Dim srcRect As Rectangle Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr)
public void DrawImage ( Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr )
public: void DrawImage ( Image^ image, array<Point>^ destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr )
public void DrawImage ( Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr )
public function DrawImage ( image : Image, destPoints : Point[], srcRect : Rectangle, srcUnit : GraphicsUnit, imageAttr : ImageAttributes )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの Point 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
元の未調整の平行四辺形では、その位置によって画面上のイメージの位置が決まり、四角形のサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
Public Sub DrawImageParaRectAttrib(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing image. Dim ulCorner1 As New Point(100, 100) Dim urCorner1 As New Point(325, 100) Dim llCorner1 As New Point(150, 250) Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1} ' Create rectangle for source image. Dim srcRect As New Rectangle(50, 50, 150, 150) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units) ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New Point(325, 100) Dim urCorner2 As New Point(550, 100) Dim llCorner2 As New Point(375, 250) Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2} ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr) End Sub
public void DrawImageParaRectAttrib(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing image. Point ulCorner1 = new Point(100, 100); Point urCorner1 = new Point(325, 100); Point llCorner1 = new Point(150, 250); Point[] destPara1 = {ulCorner1, urCorner1, llCorner1}; // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); // Create parallelogram for drawing adjusted image. Point ulCorner2 = new Point(325, 100); Point urCorner2 = new Point(550, 100); Point llCorner2 = new Point(375, 250); Point[] destPara2 = {ulCorner2, urCorner2, llCorner2}; // 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); }
public: void DrawImageParaRectAttrib( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing image. Point ulCorner1 = Point(100,100); Point urCorner1 = Point(325,100); Point llCorner1 = Point(150,250); array<Point>^ destPara1 = {ulCorner1,urCorner1,llCorner1}; // Create rectangle for source image. Rectangle srcRect = Rectangle(50,50,150,150); GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destPara1, srcRect, units ); // Create parallelogram for drawing adjusted image. Point ulCorner2 = Point(325,100); Point urCorner2 = Point(550,100); Point llCorner2 = Point(375,250); array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2}; // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Single, Single, Single, Single)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ x As Single, _ y As Single, _ width As Single, _ height As Single _ )
Dim instance As Graphics Dim image As Image Dim x As Single Dim y As Single Dim width As Single Dim height As Single instance.DrawImage(image, x, y, width, height)



次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
四角形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズと四角形のサイズによって描画イメージのスケーリングが決まります。
Public Sub DrawImage4Float(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create coordinates for upper-left corner ' of image and for size of image. Dim x As Single = 100.0F Dim y As Single = 100.0F Dim width As Single = 450.0F Dim height As Single = 150.0F ' Draw image to screen. e.Graphics.DrawImage(newImage, x, y, width, height) End Sub
public void DrawImage4Float(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner. // of image and for size of image. float x = 100.0F; float y = 100.0F; float width = 450.0F; float height = 150.0F; // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, width, height); }
public: void DrawImage4Float( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create coordinates for upper-left corner. // of image and for size of image. float x = 100.0F; float y = 100.0F; float width = 450.0F; float height = 150.0F; // Draw image to screen. e->Graphics->DrawImage( newImage, x, y, width, height ); }
public void DrawImage4Float(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner. // of image and for size of image. float x = 100; float y = 100; float width = 450; float height = 150; // Draw image to screen. e.get_Graphics().DrawImage(newImage, x, y, width, height); } //DrawImage4Float

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As Point(), _ srcRect As Rectangle, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes, _ callback As DrawImageAbort _ )
Dim instance As Graphics Dim image As Image Dim destPoints As Point() Dim srcRect As Rectangle Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes Dim callback As DrawImageAbort instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback)
public void DrawImage ( Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public: void DrawImage ( Image^ image, array<Point>^ destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr, DrawImageAbort^ callback )
public void DrawImage ( Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public function DrawImage ( image : Image, destPoints : Point[], srcRect : Rectangle, srcUnit : GraphicsUnit, imageAttr : ImageAttributes, callback : DrawImageAbort )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。
callback パラメータを指定したオーバーローによって、アプリケーションにより決定された基準に従って開始されたイメージの描画を停止するための手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の平行四辺形では、その位置によって画面上のイメージの位置が決まり、四角形のサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
この例では callBackData パラメータを渡さないオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは true を返します。これにより、DrawImage メソッドは終了し、例に含まれる例外処理コードは、イメージを描画せずに、例外テキストを出力します。
Private Function DrawImageCallback1(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageParaRectAttribAbort(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback1) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing original image. Dim ulCorner As New Point(100, 100) Dim urCorner As New Point(550, 100) Dim llCorner As New Point(150, 250) Dim destPara1 As Point() = {ulCorner, urCorner, llCorner} ' Create rectangle for source image. Dim srcRect As New Rectangle(50, 50, 150, 150) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units) ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New Point(325, 100) Dim urCorner2 As New Point(550, 100) Dim llCorner2 As New Point(375, 250) Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2} ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) Try ' Draw image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr, imageCallback) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback1(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageParaRectAttribAbort(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback1); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing original image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(550, 100); Point llCorner = new Point(150, 250); Point[] destPara1 = {ulCorner, urCorner, llCorner}; // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); // Create parallelogram for drawing adjusted image. Point ulCorner2 = new Point(325, 100); Point urCorner2 = new Point(550, 100); Point llCorner2 = new Point(375, 250); Point[] destPara2 = {ulCorner2, urCorner2, llCorner2}; // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); try { checked { // Draw image to screen. e.Graphics.DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback1( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageParaRectAttribAbort( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback1 ); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing original image. Point ulCorner = Point(100,100); Point urCorner = Point(550,100); Point llCorner = Point(150,250); array<Point>^ destPara1 = {ulCorner,urCorner,llCorner}; // Create rectangle for source image. Rectangle srcRect = Rectangle(50,50,150,150); GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destPara1, srcRect, units ); // Create parallelogram for drawing adjusted image. Point ulCorner2 = Point(325,100); Point urCorner2 = Point(550,100); Point llCorner2 = Point(375,250); array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2}; // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As Point(), _ srcRect As Rectangle, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes, _ callback As DrawImageAbort, _ callbackData As Integer _ )
Dim instance As Graphics Dim image As Image Dim destPoints As Point() Dim srcRect As Rectangle Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes Dim callback As DrawImageAbort Dim callbackData As Integer instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback, callbackData)
public void DrawImage ( Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData )
public: void DrawImage ( Image^ image, array<Point>^ destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr, DrawImageAbort^ callback, int callbackData )
public void DrawImage ( Image image, Point[] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData )
public function DrawImage ( image : Image, destPoints : Point[], srcRect : Rectangle, srcUnit : GraphicsUnit, imageAttr : ImageAttributes, callback : DrawImageAbort, callbackData : int )

destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。
callback パラメータおよび callbackData パラメータを指定したオーバーロードによって、アプリケーションにより決定された基準とデータに従って開始されたイメージの描画を停止する手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の平行四辺形では、その位置によって画面上のイメージの位置が決まり、四角形のサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
この例では callBackData パラメータを渡すオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは false を返します。これにより、DrawImage メソッドは続行し、調整済みイメージが画面に描画されます。
Private Function DrawImageCallback2(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageParaRectAttribAbortData(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback2) Dim imageCallbackData As Integer = 1 ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing original image. Dim ulCorner As New Point(100, 100) Dim urCorner As New Point(550, 100) Dim llCorner As New Point(150, 250) Dim destPara1 As Point() = {ulCorner, urCorner, llCorner} ' Create rectangle for source image. Dim srcRect As New Rectangle(50, 50, 150, 150) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units) ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New Point(325, 100) Dim urCorner2 As New Point(550, 100) Dim llCorner2 As New Point(375, 250) Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2} ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) Try ' Draw image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr, imageCallback, imageCallbackData) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback2(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageParaRectAttribAbortData(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback2); int imageCallbackData = 1; // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing original image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(550, 100); Point llCorner = new Point(150, 250); Point[] destPara1 = {ulCorner, urCorner, llCorner}; // Create rectangle for source image. Rectangle srcRect = new Rectangle(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); // Create parallelogram for drawing adjusted image. Point ulCorner2 = new Point(325, 100); Point urCorner2 = new Point(550, 100); Point llCorner2 = new Point(375, 250); Point[] destPara2 = {ulCorner2, urCorner2, llCorner2}; // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); try { checked { // Draw image to screen. e.Graphics.DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback2( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageParaRectAttribAbortData( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback2 ); int imageCallbackData = 1; // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing original image. Point ulCorner = Point(100,100); Point urCorner = Point(550,100); Point llCorner = Point(150,250); array<Point>^ destPara1 = {ulCorner,urCorner,llCorner}; // Create rectangle for source image. Rectangle srcRect = Rectangle(50,50,150,150); GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destPara1, srcRect, units ); // Create parallelogram for drawing adjusted image. Point ulCorner2 = Point(325,100); Point urCorner2 = Point(550,100); Point llCorner2 = Point(375,250); array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2}; // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Integer, _ srcY As Integer, _ srcWidth As Integer, _ srcHeight As Integer, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Integer Dim srcY As Integer Dim srcWidth As Integer Dim srcHeight As Integer Dim srcUnit As GraphicsUnit instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit)
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit )
public: void DrawImage ( Image^ image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit )
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : int, srcY : int, srcWidth : int, srcHeight : int, srcUnit : GraphicsUnit )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
描画先の四角形の位置によって画面上のイメージの位置が決まり、抽出元および描画先の四角形のサイズによって描画イメージのスケーリングが決まり、抽出元の四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageRect4Int(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim destRect As New Rectangle(100, 100, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Integer = 50 Dim y As Integer = 50 Dim width As Integer = 150 Dim height As Integer = 150 Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, destRect, x, y, width, height, _ units) End Sub
public void DrawImageRect4Int(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units); }
void DrawImageRect4Int( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying image. Rectangle destRect = Rectangle(100,100,450,150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, destRect, x, y, width, height, units ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Integer, _ srcY As Integer, _ srcWidth As Integer, _ srcHeight As Integer, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Integer Dim srcY As Integer Dim srcWidth As Integer Dim srcHeight As Integer Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr)
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr )
public: void DrawImage ( Image^ image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes^ imageAttr )
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : int, srcY : int, srcWidth : int, srcHeight : int, srcUnit : GraphicsUnit, imageAttr : ImageAttributes )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
元の未調整の描画先の四角形では、その位置によって画面上のイメージの位置が決まり、抽出元および描画先の四角形のサイズによって描画イメージのスケーリングが決まり、抽出元の四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageRect4IntAtrrib(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying original image. Dim destRect1 As New Rectangle(100, 25, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Integer = 50 Dim y As Integer = 50 Dim width As Integer = 150 Dim height As Integer = 150 Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, _ units) ' Create rectangle for adjusted image. Dim destRect2 As New Rectangle(100, 175, 450, 150) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, _ units, imageAttr) End Sub
public void DrawImageRect4IntAtrrib(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); // Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr); }
void DrawImageRect4IntAtrrib( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying original image. Rectangle destRect1 = Rectangle(100,25,450,150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units ); // Create rectangle for adjusted image. Rectangle destRect2 = Rectangle(100,175,450,150); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Integer, _ srcY As Integer, _ srcWidth As Integer, _ srcHeight As Integer, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes, _ callback As DrawImageAbort _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Integer Dim srcY As Integer Dim srcWidth As Integer Dim srcHeight As Integer Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes Dim callback As DrawImageAbort instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttr, callback)
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public: void DrawImage ( Image^ image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes^ imageAttr, DrawImageAbort^ callback )
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : int, srcY : int, srcWidth : int, srcHeight : int, srcUnit : GraphicsUnit, imageAttr : ImageAttributes, callback : DrawImageAbort )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は destRect オブジェクトで指定された四角形に収まるようにスケーリングされます。
callback パラメータを指定したオーバーローによって、アプリケーションにより決定された基準に従って開始されたイメージの描画を停止するための手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の描画先の四角形では、その位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の四角形のサイズと形状によって描画イメージのスケーリングが決まります。
この例では callBackData パラメータを渡さないオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは true を返します。これにより、DrawImage メソッドは終了し、例に含まれる例外処理コードは、イメージを描画せずに、例外テキストを出力します。
Private Function DrawImageCallback5(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageRect4IntAtrribAbort(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback5) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying original image. Dim destRect1 As New Rectangle(100, 25, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Integer = 50 Dim y As Integer = 50 Dim width As Integer = 150 Dim height As Integer = 150 Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, _ units) ' Create rectangle for adjusted image. Dim destRect2 As New Rectangle(100, 175, 450, 150) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, _ height, units, imageAttr, imageCallback) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback5(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageRect4IntAtrribAbort(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback5); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback5( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageRect4IntAtrribAbort( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback5 ); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying original image. Rectangle destRect1 = Rectangle(100,25,450,150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units ); // Create rectangle for adjusted image. Rectangle destRect2 = Rectangle(100,175,450,150); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Integer, _ srcY As Integer, _ srcWidth As Integer, _ srcHeight As Integer, _ srcUnit As GraphicsUnit, _ imageAttrs As ImageAttributes, _ callback As DrawImageAbort, _ callbackData As IntPtr _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Integer Dim srcY As Integer Dim srcWidth As Integer Dim srcHeight As Integer Dim srcUnit As GraphicsUnit Dim imageAttrs As ImageAttributes Dim callback As DrawImageAbort Dim callbackData As IntPtr instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, callback, callbackData)
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData )
public: void DrawImage ( Image^ image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes^ imageAttrs, DrawImageAbort^ callback, IntPtr callbackData )
public void DrawImage ( Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : int, srcY : int, srcWidth : int, srcHeight : int, srcUnit : GraphicsUnit, imageAttrs : ImageAttributes, callback : DrawImageAbort, callbackData : IntPtr )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。
callback パラメータおよび callbackData パラメータを指定したオーバーロードによって、アプリケーションにより決定された基準とデータに従って開始されたイメージの描画を停止する手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の描画先の四角形では、その位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の四角形のサイズと形状によって描画イメージのスケーリングが決まります。
この例では callBackData パラメータを渡すオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは false を返します。これにより、DrawImage メソッドは続行し、調整済みイメージが画面に描画されます。
Private Function DrawImageCallback6(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageRect4IntAtrribAbortData(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback6) Dim imageCallbackData As New IntPtr(1) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying original image. Dim destRect1 As New Rectangle(100, 25, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Integer = 50 Dim y As Integer = 50 Dim width As Integer = 150 Dim height As Integer = 150 Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, _ units) ' Create rectangle for adjusted image. Dim destRect2 As New Rectangle(100, 175, 450, 150) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, _ height, units, imageAttr, imageCallback, imageCallbackData) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback6(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageRect4IntAtrribAbortData(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback6); IntPtr imageCallbackData = new IntPtr(1); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback6( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageRect4IntAtrribAbortData( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback6 ); IntPtr imageCallbackData = IntPtr(1); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying original image. Rectangle destRect1 = Rectangle(100,25,450,150); // Create coordinates of rectangle for source image. int x = 50; int y = 50; int width = 150; int height = 150; GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units ); // Create rectangle for adjusted image. Rectangle destRect2 = Rectangle(100,175,450,150); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド

名前 | 説明 |
---|---|
Graphics.DrawImage (Image, Point) | 指定した位置に、指定した Image を元の物理サイズで描画します。 |
Graphics.DrawImage (Image, Point[]) | 指定した Image を指定した場所に指定した形状とサイズで描画します。 |
Graphics.DrawImage (Image, PointF) | 指定した位置に、指定した Image を元の物理サイズで描画します。 |
Graphics.DrawImage (Image, PointF[]) | 指定した Image を指定した場所に指定した形状とサイズで描画します。 |
Graphics.DrawImage (Image, Rectangle) | 指定した位置に指定したサイズで、指定した Image を描画します。 |
Graphics.DrawImage (Image, RectangleF) | 指定した位置に指定したサイズで、指定した Image を描画します。 |
Graphics.DrawImage (Image, Int32, Int32) | 指定したイメージを座標ペアで指定された位置に元の物理サイズで描画します。 .NET Compact Framework によってサポートされています。 |
Graphics.DrawImage (Image, Single, Single) | 指定した位置に、指定した Image を元の物理サイズで描画します。 |
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Rectangle, GraphicsUnit) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 .NET Compact Framework によってサポートされています。 |
Graphics.DrawImage (Image, RectangleF, RectangleF, GraphicsUnit) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Int32, Int32, Int32, Int32) | 指定した位置に指定したサイズで、指定した Image を描画します。 |
Graphics.DrawImage (Image, Int32, Int32, Rectangle, GraphicsUnit) | イメージの一部を指定の位置に描画します。 .NET Compact Framework によってサポートされています。 |
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes) | 指定した位置に、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Single, Single, RectangleF, GraphicsUnit) | イメージの一部を指定の位置に描画します。 |
Graphics.DrawImage (Image, Single, Single, Single, Single) | 指定した位置に指定したサイズで、指定した Image を描画します。 |
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, Int32) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 .NET Compact Framework によってサポートされています。 |
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |
Graphics.DrawImage (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr) | 指定した位置に指定したサイズで、指定した Image の指定した部分を描画します。 |

Graphics.DrawImage メソッド (Image, PointF[])
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As Graphics Dim image As Image Dim destPoints As PointF() instance.DrawImage(image, destPoints)


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
image オブジェクトによって表されるイメージは、destPoints パラメータで指定される平行四辺形の形状に合わせてスケーリングされ、傾斜が設定されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
平行四辺形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
Public Sub DrawImageParaF(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing image. Dim ulCorner As New PointF(100.0F, 100.0F) Dim urCorner As New PointF(550.0F, 100.0F) Dim llCorner As New PointF(150.0F, 250.0F) Dim destPara As PointF() = {ulCorner, urCorner, llCorner} ' Draw image to screen. e.Graphics.DrawImage(newImage, destPara) End Sub
public void DrawImageParaF(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing image. PointF ulCorner = new PointF(100.0F, 100.0F); PointF urCorner = new PointF(550.0F, 100.0F); PointF llCorner = new PointF(150.0F, 250.0F); PointF[] destPara = {ulCorner, urCorner, llCorner}; // Draw image to screen. e.Graphics.DrawImage(newImage, destPara); }
public: void DrawImageParaF( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing image. PointF ulCorner = PointF(100.0F,100.0F); PointF urCorner = PointF(550.0F,100.0F); PointF llCorner = PointF(150.0F,250.0F); array<PointF>^ destPara = {ulCorner,urCorner,llCorner}; // Draw image to screen. e->Graphics->DrawImage( newImage, destPara ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Single, _ srcY As Single, _ srcWidth As Single, _ srcHeight As Single, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Single Dim srcY As Single Dim srcWidth As Single Dim srcHeight As Single Dim srcUnit As GraphicsUnit instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit)
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit )
public: void DrawImage ( Image^ image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit )
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : float, srcY : float, srcWidth : float, srcHeight : float, srcUnit : GraphicsUnit )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
描画先の四角形の位置によって画面上のイメージの位置が決まり、抽出元および描画先の四角形のサイズによって描画イメージのスケーリングが決まり、抽出元の四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageRect4Float(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim destRect As New Rectangle(100, 100, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Single = 50.0F Dim y As Single = 50.0F Dim width As Single = 150.0F Dim height As Single = 150.0F Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, destRect, x, y, width, height, _ units) End Sub
public void DrawImageRect4Float(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying image. Rectangle destRect = new Rectangle(100, 100, 450, 150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units); }
public: void DrawImageRect4Float( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying image. Rectangle destRect = Rectangle(100,100,450,150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, destRect, x, y, width, height, units ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destPoints As PointF(), _ srcRect As RectangleF, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes _ )
Dim instance As Graphics Dim image As Image Dim destPoints As PointF() Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr)
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr )
public: void DrawImage ( Image^ image, array<PointF>^ destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr )
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr )
public function DrawImage ( image : Image, destPoints : PointF[], srcRect : RectangleF, srcUnit : GraphicsUnit, imageAttr : ImageAttributes )


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの PointF 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
描画する image オブジェクトの四角形部分を指定する srcRect パラメータ。この部分は、destPoints パラメータで指定された平行四辺形の内側に収まるようにスケーリングされ、傾斜が設定されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
元の未調整の描画先の平行四辺形では、その位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まり、四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageParaFRectFAttrib(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing original image. Dim ulCorner1 As New PointF(100.0F, 100.0F) Dim urCorner1 As New PointF(325.0F, 100.0F) Dim llCorner1 As New PointF(150.0F, 250.0F) Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1} ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New PointF(325.0F, 100.0F) Dim urCorner2 As New PointF(550.0F, 100.0F) Dim llCorner2 As New PointF(375.0F, 250.0F) 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(4.0F) ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr) End Sub
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); }
void DrawImageParaFRectFAttrib( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing original image. PointF ulCorner1 = PointF(100.0F,100.0F); PointF urCorner1 = PointF(325.0F,100.0F); PointF llCorner1 = PointF(150.0F,250.0F); array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1}; // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Create parallelogram for drawing adjusted image. PointF ulCorner2 = PointF(325.0F,100.0F); PointF urCorner2 = PointF(550.0F,100.0F); PointF llCorner2 = PointF(375.0F,250.0F); array<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 = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Single, Single, RectangleF, GraphicsUnit)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ x As Single, _ y As Single, _ srcRect As RectangleF, _ srcUnit As GraphicsUnit _ )
Dim instance As Graphics Dim image As Image Dim x As Single Dim y As Single Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit instance.DrawImage(image, x, y, srcRect, srcUnit)
public function DrawImage ( image : Image, x : float, y : float, srcRect : RectangleF, srcUnit : GraphicsUnit )


Image は、ピクセル幅の値および水平方向の解像度 (dpi) の値を格納します。イメージの物理的な幅 (インチ) は、ピクセル幅を水平解像度で割った値です。たとえば、幅が 360 ピクセルで、水平解像度が 72 dpi のイメージの物理的な幅は 5 インチになります。ピクセルの高さと物理的な高さについても同様です。
このメソッドは物理サイズを使用してイメージの一部を描画するため、イメージのその部分は表示デバイスの解像度 (dpi) に関係なく、インチで指定された正しいサイズで描画されます。たとえば、幅が 216 ピクセルで、水平解像度が 72 dpi であるイメージの一部を想定します。このメソッドを呼び出して、96 dpi (1 インチあたりのドット数) の解像度のデバイスにそのイメージの部分を描画すると、レンダリングされたイメージの幅は (216/72)*96 = 288 (ピクセル) になります。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
抽出元の四角形のサイズによって、スケーリングされない元のイメージのどの部分が画面に描画されるかが決まります。
Public Sub DrawImage2FloatRectF(ByVal 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 = 100.0F Dim y As Single = 100.0F ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw image to screen. e.Graphics.DrawImage(newImage, x, y, srcRect, units) End Sub
public void DrawImage2FloatRectF(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; // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.Graphics.DrawImage(newImage, x, y, srcRect, units); }
public: void DrawImage2FloatRectF( 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; // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Draw image to screen. e->Graphics->DrawImage( newImage, x, y, srcRect, units ); }
public void DrawImage2FloatRectF(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create coordinates for upper-left corner of image. float x = 100; float y = 100; // Create rectangle for source image. RectangleF srcRect = new RectangleF(50, 50, 150, 150); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. e.get_Graphics().DrawImage(newImage, x, y, srcRect, units); } //DrawImage2FloatRectF

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle)
アセンブリ: System.Drawing (system.drawing.dll 内)




次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
四角形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズと四角形のサイズによって描画イメージのスケーリングが決まります。
Public Sub DrawImageRect(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying image. Dim destRect As New Rectangle(100, 100, 450, 150) ' Draw image to screen. e.Graphics.DrawImage(newImage, destRect) End Sub

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Single, _ srcY As Single, _ srcWidth As Single, _ srcHeight As Single, _ srcUnit As GraphicsUnit, _ imageAttrs As ImageAttributes _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Single Dim srcY As Single Dim srcWidth As Single Dim srcHeight As Single Dim srcUnit As GraphicsUnit Dim imageAttrs As ImageAttributes instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs)
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs )
public: void DrawImage ( Image^ image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes^ imageAttrs )
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : float, srcY : float, srcWidth : float, srcHeight : float, srcUnit : GraphicsUnit, imageAttrs : ImageAttributes )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
元の未調整の描画先の四角形では、その位置によって画面上のイメージの位置が決まり、抽出元および描画先の四角形のサイズによって描画イメージのスケーリングが決まり、抽出元の四角形のサイズによって画面に描画する元のイメージの部分が決まります。
Public Sub DrawImageRect4FloatAttrib(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying original image. Dim destRect1 As New Rectangle(100, 25, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Single = 50.0F Dim y As Single = 50.0F Dim width As Single = 150.0F Dim height As Single = 150.0F Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, _ height, units) ' Create rectangle for adjusted image. Dim destRect2 As New Rectangle(100, 175, 450, 150) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, _ units, imageAttr) End Sub
public void DrawImageRect4FloatAttrib(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); // Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr); }
public: void DrawImageRect4FloatAttrib( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying original image. Rectangle destRect1 = Rectangle(100,25,450,150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units ); // Create rectangle for adjusted image. Rectangle destRect2 = Rectangle(100,175,450,150); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Point)
アセンブリ: System.Drawing (system.drawing.dll 内)



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

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
Public Sub DrawImagePoint(ByVal 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

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Point[])
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As Graphics Dim image As Image Dim destPoints As Point() instance.DrawImage(image, destPoints)


destPoints パラメータは、平行四辺形の 3 つの点を指定します。3 つの Point 構造体は、平行四辺形の左上隅、右上隅、および左下隅を表します。初めの 3 つの点から 4 番目の点を推定して、平行四辺形を形成します。
image パラメータによって表されるイメージは、destPoints パラメータで指定される平行四辺形の形状に合わせてスケーリングされ、傾斜が設定されます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
平行四辺形の位置によって画面上のイメージの位置が決まり、元のイメージのサイズおよび平行四辺形のサイズと形状によって描画イメージのスケーリングと傾斜が決まります。
Public Sub DrawImagePara(ByVal e As PaintEventArgs) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing image. Dim ulCorner As New Point(100, 100) Dim urCorner As New Point(550, 100) Dim llCorner As New Point(150, 250) Dim destPara As Point() = {ulCorner, urCorner, llCorner} ' Draw image to screen. e.Graphics.DrawImage(newImage, destPara) End Sub
public void DrawImagePara(PaintEventArgs e) { // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing image. Point ulCorner = new Point(100, 100); Point urCorner = new Point(550, 100); Point llCorner = new Point(150, 250); Point[] destPara = {ulCorner, urCorner, llCorner}; // Draw image to screen. e.Graphics.DrawImage(newImage, destPara); }
public: void DrawImagePara( PaintEventArgs^ e ) { // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing image. Point ulCorner = Point(100,100); Point urCorner = Point(550,100); Point llCorner = Point(150,250); array<Point>^ destPara = {ulCorner,urCorner,llCorner}; // Draw image to screen. e->Graphics->DrawImage( newImage, destPara ); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Int32, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As Graphics Dim image As Image Dim x As Integer Dim y As Integer instance.DrawImage(image, x, y)


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

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
Public Sub DrawImage2Int(ByVal 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
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); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Single, _ srcY As Single, _ srcWidth As Single, _ srcHeight As Single, _ srcUnit As GraphicsUnit, _ imageAttrs As ImageAttributes, _ callback As DrawImageAbort, _ callbackData As IntPtr _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Single Dim srcY As Single Dim srcWidth As Single Dim srcHeight As Single Dim srcUnit As GraphicsUnit Dim imageAttrs As ImageAttributes Dim callback As DrawImageAbort Dim callbackData As IntPtr instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, callback, callbackData)
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData )
public: void DrawImage ( Image^ image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes^ imageAttrs, DrawImageAbort^ callback, IntPtr callbackData )
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : float, srcY : float, srcWidth : float, srcHeight : float, srcUnit : GraphicsUnit, imageAttrs : ImageAttributes, callback : DrawImageAbort, callbackData : IntPtr )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。
callback パラメータおよび callbackData パラメータを指定したオーバーロードによって、アプリケーションにより決定された基準とデータに従って開始されたイメージの描画を停止する手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の描画先の四角形では、その位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の四角形のサイズと形状によって描画イメージのスケーリングが決まります。
この例では callBackData パラメータを渡すオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは false を返します。これにより、DrawImage メソッドは続行し、調整済みイメージが画面に描画されます。
Private Function DrawImageCallback8(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageRect4FloatAttribAbortData(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback8) Dim imageCallbackData As New IntPtr(1) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying original image. Dim destRect1 As New Rectangle(100, 25, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Single = 50.0F Dim y As Single = 50.0F Dim width As Single = 150.0F Dim height As Single = 150.0F Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, _ height, units) ' Create rectangle for adjusted image. Dim destRect2 As New Rectangle(100, 175, 450, 150) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) ' Draw adjusted image to screen. Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, _ height, units, imageAttr, imageCallback, imageCallbackData) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback8(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageRect4FloatAttribAbortData(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback8); IntPtr imageCallbackData = new IntPtr(1); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); // Draw adjusted image to screen. try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback8( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageRect4FloatAttribAbortData( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback8 ); IntPtr imageCallbackData = IntPtr(1); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying original image. Rectangle destRect1 = Rectangle(100,25,450,150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units ); // Create rectangle for adjusted image. Rectangle destRect2 = Rectangle(100,175,450,150); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); // Draw adjusted image to screen. try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }
// Define DrawImageAbort callback method. private boolean DrawImageCallback8(IntPtr callBackData) { // Test for call that passes callBackData parameter. if (callBackData.Equals( IntPtr.Zero)) { // If no callBackData passed, abort DrawImage method. return true ; } else { // If callBackData passed, continue DrawImage method. return false ; } } //DrawImageCallback8 public void DrawImageRect4FloatAttribAbortData(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort( DrawImageCallback8); IntPtr imageCallbackData = new IntPtr(1); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. float x = 50; float y = 50; float width = 150; float height = 150; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.get_Graphics().DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4); try { // Draw adjusted image to screen. e.get_Graphics().DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData); } catch(System.Exception ex) { e.get_Graphics().DrawString(ex.ToString(), new Font("Arial", 8), Brushes.get_Black(), new PointF(0, 0)); } } //DrawImageRect4FloatAttribAbortData

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort)
アセンブリ: System.Drawing (system.drawing.dll 内)

Public Sub DrawImage ( _ image As Image, _ destRect As Rectangle, _ srcX As Single, _ srcY As Single, _ srcWidth As Single, _ srcHeight As Single, _ srcUnit As GraphicsUnit, _ imageAttrs As ImageAttributes, _ callback As DrawImageAbort _ )
Dim instance As Graphics Dim image As Image Dim destRect As Rectangle Dim srcX As Single Dim srcY As Single Dim srcWidth As Single Dim srcHeight As Single Dim srcUnit As GraphicsUnit Dim imageAttrs As ImageAttributes Dim callback As DrawImageAbort instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, callback)
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback )
public: void DrawImage ( Image^ image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes^ imageAttrs, DrawImageAbort^ callback )
public void DrawImage ( Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback )
public function DrawImage ( image : Image, destRect : Rectangle, srcX : float, srcY : float, srcWidth : float, srcHeight : float, srcUnit : GraphicsUnit, imageAttrs : ImageAttributes, callback : DrawImageAbort )


srcX、srcY、srcWidth、srcHeight の各パラメータは、描画する image オブジェクトの四角形部分を指定します。四角形は、ソース イメージの左上隅を起点とします。この部分は、destRect パラメータで指定された四角形の内側に収まるようにスケーリングされます。
callback パラメータを指定したオーバーローによって、アプリケーションにより決定された基準に従って開始されたイメージの描画を停止するための手段が提供されます。たとえば、アプリケーションが大きなイメージの描画を開始したため、ユーザーがそのイメージをスクロールして画面の外に出すことがあります。この場合、アプリケーションは描画を中断できます。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは、まず Graphics.DrawImageAbort デリゲートのコールバック メソッドを定義します。その定義は単純で、DrawImage メソッドが null 値の callBackData パラメータで呼び出しを行うかどうかをテストするだけです。この例の本文は、次の処理を実行します。
元の未調整の描画先の四角形では、その位置によって画面上のイメージの位置が決まり、抽出元の四角形のサイズおよび描画先の四角形のサイズと形状によって描画イメージのスケーリングが決まります。
この例では callBackData パラメータを渡さないオーバーロードを使用するため、Graphics.DrawImageAbort コールバックは true を返します。これにより、DrawImage メソッドは終了し、例に含まれる例外処理コードは、イメージを描画せずに、例外テキストを出力します。
Private Function DrawImageCallback7(ByVal callBackData As IntPtr) As Boolean ' Test for call that passes callBackData parameter. If callBackData.Equals(IntPtr.Zero) Then ' If no callBackData passed, abort DrawImage method. Return True Else ' If callBackData passed, continue DrawImage method. Return False End If End Function Public Sub DrawImageRect4FloatAttribAbort(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback7) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create rectangle for displaying original image. Dim destRect1 As New Rectangle(100, 25, 450, 150) ' Create coordinates of rectangle for source image. Dim x As Single = 50.0F Dim y As Single = 50.0F Dim width As Single = 150.0F Dim height As Single = 150.0F Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, _ height, units) ' Create rectangle for adjusted image. Dim destRect2 As New Rectangle(100, 175, 450, 150) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destRect2, x, y, width, _ height, units, imageAttr, imageCallback) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback7(IntPtr callBackData) { // Test for call that passes callBackData parameter. if(callBackData==IntPtr.Zero) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public void DrawImageRect4FloatAttribAbort(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback7); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create rectangle for displaying original image. Rectangle destRect1 = new Rectangle(100, 25, 450, 150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit.Pixel; // Draw original image to screen. e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units); // Create rectangle for adjusted image. Rectangle destRect2 = new Rectangle(100, 175, 450, 150); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback7( IntPtr callBackData ) { // Test for call that passes callBackData parameter. if ( callBackData == IntPtr::Zero ) { // If no callBackData passed, abort DrawImage method. return true; } else { // If callBackData passed, continue DrawImage method. return false; } } public: void DrawImageRect4FloatAttribAbort( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback7 ); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create rectangle for displaying original image. Rectangle destRect1 = Rectangle(100,25,450,150); // Create coordinates of rectangle for source image. float x = 50.0F; float y = 50.0F; float width = 150.0F; float height = 150.0F; GraphicsUnit units = GraphicsUnit::Pixel; // Draw original image to screen. e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units ); // Create rectangle for adjusted image. Rectangle destRect2 = Rectangle(100,175,450,150); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Graphics.DrawImage メソッド (Image, Single, Single)
アセンブリ: System.Drawing (system.drawing.dll 内)

Dim instance As Graphics Dim image As Image Dim x As Single Dim y As Single instance.DrawImage(image, x, y)


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

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。
Public Sub DrawImage2Float(ByVal 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 = 100.0F Dim y As Single = 100.0F ' Draw image to screen. e.Graphics.DrawImage(newImage, x, y) End Sub
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); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- Graphics.DrawImageのページへのリンク