釋放這個 Graphics 所使用的所有資源。Releases all resources used by this Graphics.
public:
virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
實作
範例
下列程式碼範例是設計用來搭配 Windows Forms 使用,它需要 PaintEventArgs e 是 Paint 事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此程式碼會執行下列動作:The code performs the following actions:
Image從範例目錄中的圖形檔案 SampImag.jpg 建立。Creates an Image from a graphics file SampImag.jpg in the example directory.
藉由填滿矩形內的矩形來改變影像。Alters the image by filling a rectangle within it.
將繪製 Image 到螢幕。Draws the Image to the screen.
Releases the created 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 供其他用途使用。Calling Dispose allows the resources used by this Graphics to be reallocated for other purposes.
適用於