c # Pick up text and insert over the image

0

I have a pictureBox, and I need the user to be able to "mark" the image. For example, the image is a human body, I need the user to click on the photo where the arm is, for example, there is a drawing drawn written "arm". When you click on the leg, a little icon appears where he clicked and a text above written "leg" and so on.

I already have several checkboxes in the form, where each one already has all the texts that should appear in the image, like arm, legs, head. You would need a way to get this checkbox.Text by clicking on the checkbox, and entering that text in the photo exactly where the user clicked.

It is necessary that all this is saved in the bank, that is, when he clicks save, these markings in the photo tmb have to be saved.

I've been using CreateGraphics () and DrawLine () so far for the user to circulate the body parts, but does not save the scratches on top of the photo, and is very limited only to circulate with the drawline, I wanted a text in the photo.

Is it possible? I do not even know how to do a better search. Can someone help?

    
asked by anonymous 31.07.2017 / 20:36

1 answer

0

You need to get Graphics from the image, not the controls or form:

var g =  Graphics.FromImage(pictureBox1.Image);

This is a method I use to draw a circle over the image:

    private void Circulo(MouseEventArgs e)
    {
        var g = Graphics.FromImage(pic1.Image);
        g.Clear(Color.Transparent);
        SolidBrush br = new SolidBrush(panelColor.BackColor);
        Pen p = new Pen(br);
        p.Width = (float)tam;

        int W = e.Location.X - mouseDownPosition.X;
        int H = e.Location.Y - mouseDownPosition.Y;
        if (W > 0 && H > 0)
            g.DrawEllipse(p, mouseDownPosition.X, mouseDownPosition.Y, W, H);
        else if (W > 0 && H < 0)
        {
            H *= -1;
            g.DrawEllipse(p, mouseDownPosition.X, e.Location.Y, W, H);
        }
        else if (W < 0 && H > 0)
        {
            W *= -1;
            g.DrawEllipse(p, e.Location.X, mouseDownPosition.Y, W, H);
        }
        else
        {
            W *= -1;
            H *= -1;
            g.DrawEllipse(p, e.Location.X, e.Location.Y, W, H);
        }

        RefreshPictureBox();
        g.Dispose();
        p.Dispose();
        br.Dispose();
    }

and to call it:

        private void pictureBoxView_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
                Circulo(e);
        }

The Part of writing the text in the image:

g.DrawString("SEU TEXTO", new Font("Verdana", 10F, FontStyle.Regular), Brushes.Red, new PointF(0, 0));

where g is the Graphics object, of course

    
31.07.2017 / 21:24