java graphics dispose_Graphics.Dispose 方法 (System.Drawing) | Microsoft Docs

釋放這個 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.

適用於

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值