菜鸟求助,关于图像清除的问题

小猪飞剑 2012-04-13 11:11:12
先贴个简单的代码
private void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(pictureBox1.Image);
Graphics g = Graphics.FromImage(bmp);
g.DrawLine(new Pen (Color .Red ,5) , 10, 10, 30, 30);
g.Dispose();
this.pictureBox1.Image = bmp;
}
就是说在picturebox里画了个线
然后。。。我想知道怎么点击另一个按钮的时候清除它
那个。。不要告诉我再用背景色画一次,那个方法太脑残了
谢谢了
...全文
119 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
小猪飞剑 2012-04-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
直接定义2个BMP就OK了啊,点按钮就把另一个BMP赋给PICTUREBOX。。。

Bitmap bmp = new Bitmap(pictureBox1.Image);
Bitmap bmp2 = new Bitmap(pictureBox1.Image);
private void button1_Click(object sender, EventArgs e)
{ ……
[/Quote]

代码错了。但是意思我懂了。谢谢哈
bdmh 2012-04-14
  • 打赏
  • 举报
回复
用底色重绘,如果底色是错综复杂的,那就可以去底图的一个区域,覆盖住这条线
或许还有其他更好的方法,google吧
orochiheart 2012-04-14
  • 打赏
  • 举报
回复
不懂!
画两条线,想清楚掉一条,这个时候用楼上的方法还能满足需求么?
stonespace 2012-04-14
  • 打赏
  • 举报
回复
用背景色再画一次是最简单并且效率最高的方法,并不是脑残的方法,你应该这么做,
badboyss 2012-04-13
  • 打赏
  • 举报
回复
直接定义2个BMP就OK了啊,点按钮就把另一个BMP赋给PICTUREBOX。。。

Bitmap bmp = new Bitmap(pictureBox1.Image);
Bitmap bmp2 = new Bitmap(pictureBox1.Image);
private void button1_Click(object sender, EventArgs e)
{
Graphics g = Graphics.FromImage(bmp);
g.DrawLine(new Pen (Color .Red ,5) , 10, 10, 30, 30);
g.Dispose();
this.pictureBox1.Image = bmp;
}
private void button2_Click(object sender, EventArgs e)
{
this.pictureBox1.Image = bmp2;
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧