这个screenImage是一个图片,这个代码原理应该是每次只显示一个矩形框,可是现在是仍然保留着上次的矩形框,这是为什么
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
locationNewX = MousePosition.X;
locationNewY = MousePosition.Y;
Bitmap screen = new Bitmap(this.Width,this.Height);
screen = screenImage;
Graphics sIma = Graphics.FromImage(screen);
sIma.DrawRectangle(p, 100, 100, locationNewX - 100, locationNewY - 100);
pictureBox1.Image = screen;
}
现在一拖鼠标就会出现很多框,为什么会这样
我觉得应该先清空,然后再画上去。
现在的问题是,screen为什么运行起来像是screenImage的引用,而不是内容一样
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
//如果必要每次都用到srceenImage , 建议每次Copy一个srceenImage,然后修改显示,不改变原有的srceenImage
locationNewX = MousePosition.X;
locationNewY = MousePosition.Y;
Bitmap screen = new Bitmap(this.Width,this.Height);
screen = screenImage;//这里完全就是引用 screenImage 了。。所以,你实例化的new Bitmap()完全没用只是浪费了空间,去掉这句话,估计就好了
Graphics sIma = Graphics.FromImage(screen);
sIma.DrawRectangle(p, 100, 100, locationNewX - 100, locationNewY - 100);
pictureBox1.Image = screen;
}