Graphics.Dispose メソッド

定義

この Graphics によって使用されているすべてのリソースを解放します。

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

実装

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • Imageサンプル ディレクトリに SampImag.jpg グラフィックス ファイルから を作成します。

  • から を Graphics 作成します Image

  • 画像内の四角形を塗りつぶして画像を変更します。

  • Image 画面に描画します。

  • 作成 Graphicsした を解放します。

private:
   void FromImageImage1( PaintEventArgs^ e )
   {
      // Create image.
      Image^ imageFile = Image::FromFile( "SampImag.jpg" );

      // Create graphics object for alteration.
      Graphics^ newGraphics = Graphics::FromImage( imageFile );

      // Alter image.
      newGraphics->FillRectangle( gcnew SolidBrush( Color::Black ), 100, 50, 100, 100 );

      // Draw image to screen.
      e->Graphics->DrawImage( imageFile, PointF(0.0F,0.0F) );

      // Release graphics object.
      delete newGraphics;
   }
private void FromImageImage1(PaintEventArgs e)
{
    // Create image.
    Image imageFile = Image.FromFile("SampImag.jpg");
             
    // Create graphics object for alteration.
    Graphics newGraphics = Graphics.FromImage(imageFile);
             
    // Alter image.
    newGraphics.FillRectangle(new SolidBrush(Color.Black), 100, 50, 100, 100);
             
    // Draw image to screen.
    e.Graphics.DrawImage(imageFile, new PointF(0.0F, 0.0F));
             
    // Release graphics object.
    newGraphics.Dispose();
}
Private Sub FromImageImage1(ByVal e As PaintEventArgs)

    ' Create image.
    Dim imageFile As Image = Image.FromFile("SampImag.jpg")

    ' Create graphics object for alteration.
    Dim newGraphics As Graphics = Graphics.FromImage(imageFile)

    ' Alter image.
    newGraphics.FillRectangle(New SolidBrush(Color.Black), 100, _
    50, 100, 100)

    ' Draw image to screen.
    e.Graphics.DrawImage(imageFile, New PointF(0.0F, 0.0F))

    ' Dispose of graphics object.
    newGraphics.Dispose()
End Sub

注釈

を呼び出 Dispose すと、この Graphics によって使用されるリソースを他の目的で再割り当てできます。

適用対象