Graphics.Dispose 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
释放此 Graphics使用的所有资源。
public:
virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
实现
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse
,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
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 使用的资源重新分配为其他目的。