c#emgucv,如何在绘制后删除矩形

时间:2018-05-28 07:20:11

标签: c# draw emgucv

现在我的目的是在画一个矩形之后我想清除它。但我不知道该怎么做!

所以我尝试搜索stackoverflow,但它们似乎不符合我的问题。 现在我的代码功能是在imagebox上绘制一个矩形,当鼠标按下时,它给矩形的起点也是鼠标移动的状态!当鼠标向上时,它将具有端点。 所以使用 {绘制(矩形,TColor,的Int32,线型的Int32);} 然后它会生成一个新的矩形; 但是我不知道如何在那之后删除矩形

这里是我的代码

 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)//mousedown
    {
        if (img != null)
        {

            mouseStatus = true;
            startPoint.X = e.X;
            startPoint.Y = e.Y;
            //A new rectangle resets in a new coordinate
            minStartX = e.X;
            minStartY = e.Y;
            maxEndX = e.X;
            maxEndY = e.Y;
        }
    }


    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)//mousemove
    {
        string StringX, StringY, StringSX, StringSY;

        if (mouseStatus)
        {

            endPoint.X = e.X;
            endPoint.Y = e.Y;
            //This section is to get the top and bottom left coordinates of the rectangle to be drawn. If not, the rectangle can only be drawn from the top left to the bottom right.

            int realStartX = Math.Min(startPoint.X, endPoint.X);
            int realStartY = Math.Min(startPoint.Y, endPoint.Y);
            int realEndX = Math.Max(startPoint.X, endPoint.X);
            int realEndY = Math.Max(startPoint.Y, endPoint.Y);

            minStartX = Math.Min(minStartX, realStartX);
            minStartY = Math.Min(minStartY, realStartY);
            maxEndX = Math.Max(maxEndX, realEndX);
            maxEndY = Math.Max(maxEndY, realEndY);
            currRect = new Rectangle(realStartX, realStartY, realEndX - realStartX, realEndY - realStartY);
            StringX = Convert.ToString(realStartX);
            StringY = Convert.ToString(realStartY);
            StringSX = Convert.ToString(realEndX - realStartX);
            StringSY = Convert.ToString(realEndY - realStartY);
            textBox1.Text = StringX;
            textBox2.Text = StringY;
            textBox3.Text = StringSX;
            textBox4.Text = StringSY;


        }
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)/mouseup
    {
        mouseStatus = false;
        endPoint.X = e.X;
        endPoint.Y = e.Y;
        img.Draw(currRect, new Bgr(Color.Red), 1);
        pictureBox1.Image = img.Bitmap;
    }

0 个答案:

没有答案