不是垃圾自动回收吗?干吗还要用 Graphics.Dispose()?
经常看到GDI+的例子中,Graphics 手动调用 Dispose(),有必要吗?写这句又会如何?
如下:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
DrawPerson();
//画一幅图像
Image curImage = Image.FromFile(@"e:\photo.jpg");
g.DrawImage(curImage, 0, 0, curImage.Width, curImage.Height);
g.Dispose();
}