我有一个像这样绘制位图的方法:
public void DrawGrid(){
GridBitMap = new Bitmap(x,y);
MyGraphic = Graphics.FromImage(GridBitMap);
MyGraphic.FillRectangle(BackGround, 0, 0, x, y);
//Then using loops I draw various lines like this
MyGraphic.DrawLine(Pen.Black,x,y,xx,yy);
//Then I add the Bitmap to a Picturebox
PictureBox.Image = GridBitMap;
}
我的问题是,每次调用该方法时。我使用越来越多的资源。如何在不引起太多闪烁的情况下释放位图和图形?并防止代码消耗越来越多的资源?