【发布时间】:2011-06-28 08:43:29
【问题描述】:
我在图片框中加载了一个图像。我通过 mouseclick 事件对图像执行绘画操作。当鼠标在该点单击时,它会绘制一个黑色的小矩形区域。现在我想实现撤消此操作。当我单击按钮时,应撤消最后一次绘制操作。这是我的绘制操作代码..
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
rect.Width = 0;
rect.Height = 0;
pictureBox1.Invalidate();
int radius = 10; //Set the number of pixel you want to use here
//Calculate the numbers based on radius
int x0 = Math.Max(e.X - (radius / 2), 0),
y0 = Math.Max(e.Y - (radius / 2), 0),
x1 = Math.Min(e.X + (radius / 2), pictureBox1.Width),
y1 = Math.Min(e.Y + (radius / 2), pictureBox1.Height);
Bitmap bm = pictureBox1.Image as Bitmap; //Get the bitmap (assuming it is stored that way)
for (int ix = x0; ix < x1; ix++)
{
for (int iy = y0; iy < y1; iy++)
{
bm.SetPixel(ix, iy, Color.Black); //Change the pixel color, maybe should be relative to bitmap
}
}
pictureBox1.Refresh(); //Force refresh
}
请任何人帮助我如何撤消上一次执行的操作。
【问题讨论】: