private void Draw(){
int width = Screen.PrimaryScreen.Bounds.Width;
int height = Screen.PrimaryScreen.Bounds.Height;
Bitmap image= new Bitmap(width, height);
Graphics gr = Graphics.FromImage(image);
gr.CopyFromScreen(0, 0, 0, 0, new Size(width, height));
Random rnd = new Random();
gr.DrawEllipse(new Pen(Color.Red, rnd.Next(100)), rnd.Next(300), rnd.Next(100), rnd.Next(600), rnd.Next(1000));
Point[] p = new Point[3];
p[0] = new Point(rnd.Next(30), rnd.Next(60));
p[1] = new Point(rnd.Next(100), rnd.Next(260));
p[2] = new Point(rnd.Next(30), rnd.Next(10));
gr.DrawPolygon(Pens.AliceBlue, p);
gr.DrawBeziers(Pens.Yellow, p);
pcImageBox.Image = image;
}
当我每 300 毫秒使用Timer
并调用该Draw()
方法时,一切正常,但是当我查看进程管理器时,我的项目使用更多内存(内存每 300 毫秒增加一次)
也许我应该使用垃圾收集器或使用p = null;
等。我该如何解决这个问题?
谢谢你的帮助,对不起我的英语不好..