擦除在PictureBox中的图像上的线条,这些线条是通过鼠标单击绘制的 [英] Erase lines over Image in PictureBox which were drawn on Mouse Click

查看:109
本文介绍了擦除在PictureBox中的图像上的线条,这些线条是通过鼠标单击绘制的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我正在使用图片框中的图像上的(DrawLines)绘制线,我可以使用下面的代码绘制线,,但是我想当用户单击按钮(在图片框下提供)时,用户在图像上绘制的所有线应该被删除.

谢谢,,,,



Hello friends,,

I am working on drawing Lines using (DrawLines) over Image in picturebox,I am able to draw lines using below code,,But i want when user click on Button (provided below picture box) all the lines which user have drawn over the image should be Erased .

Thanks,,,,,



private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
                 
 
            pointArray[iNumberofClicks].X = e.X;
            pointArray[iNumberofClicks].Y = e.Y;
            Pen PenSpikes = new Pen(Color.Green);
            SolidBrush solidBrush = new SolidBrush(Color.Blue);
 
            if(iNumberofClicks==0)
            {
                 a = e.X;
                 b = e.Y;
            }
 
            iNumberofClicks++;
            if (iNumberofClicks > 1)
            {
                Point[] CurrentpointArray = new Point[iNumberofClicks];
 
                for (int aa = 0; aa < iNumberofClicks; aa++)
                {
                    CurrentpointArray[aa].X = pointArray[aa].X;
                    CurrentpointArray[aa].Y = pointArray[aa].Y;
 
                }
 
               
               Graphics offScreenDC = Graphics.FromImage(pictureBox1.Image);
                offScreenDC.DrawLines(PenSpikes, CurrentpointArray);
                offScreenDC.Dispose();
                pictureBox1.Refresh();
                
               
}
}
for (int j = 1; j < CurrentpointArray.Length;j++ )
              {
                  if ((Convert.ToInt16(CurrentpointArray[j].X) == a && Convert.ToInt16(CurrentpointArray[j].Y) == b) )
                  {
                      MessageBox.Show("alert");
                      break;
                  }
              }

推荐答案

在绘制第一行之前,需要将原始图像缓存在内存中.像这样的东西:

Before you draw the first line you need to cache the original image in memory. Something like this:

MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms)



然后,当您要清除线条时,请重新加载原始图像.同样是这样的:



Then when you want to clear the lines you reload the original image. Again something like this:

Image img = new Image(ms);
pictureBox1.Image = img;


这篇关于擦除在PictureBox中的图像上的线条,这些线条是通过鼠标单击绘制的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆