if u want to draw something on a picture u can use microsoft paint, but if you want do it by ur c# code, i think this article will help you.
i make a win form application to draw by mouse. u can select the pensize as u wish. It is only a tricks between three mouse event on a picture they are
- mouse up
- mouse down
- mouse move
to use the software to u have to insert an image to picture box then chose color and size of brush. then start to draw by mouse press on image. like below image
after inserting u can draw as u like
the coding is fairly easy, u have to check mouse event is pressed or not, the write a rectangle in mouse position. like below
bool draw = false; int s = 3; Color color = Color.Red; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { draw = true; Graphics g = Graphics.FromImage(mainimage); Pen pen1 = new Pen(color, 4); g.DrawRectangle(pen1, e.X, e.Y, 2, 2); g.Save(); pictureBox1.Image = mainimage; } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { draw = false; } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (draw) { Graphics g = Graphics.FromImage(mainimage); SolidBrush brush = new SolidBrush(color); g.FillRectangle(brush, e.X, e.Y, s, s); g.Save(); pictureBox1.Image = mainimage; } }
Pingback: C# tips : How to draw on a picturebox image using mouse by c# … | Learn Visual Studio
this code help me very much to complete my project
thank u
Hi,Your Blog is great it features some the best in depth coding articles.I have a coding problem can you please help me out.
I’m trying to implement a image editor,i want to draw an image on top of existing image on a picture box.I have achieved it using Graphics.DrawImage and using the MouseEventArguments point.But the problem is i want a selection rectangle drawn on top of the image being drawn when the mouse is clicked over it and it should be redrawn at a new position obtained by on click and drag by the mouse(without selection rectangle).The rending of the image at the new position is slow and lots of memory is consumed so i use GC.collect.Please help me to implement the selection.
thank you kishore
Can I ask why the drawing point isn’t the exact mouse pointer location? On mine, it draws a couple of pixels ‘off’… Any help would be appreciated 🙂 Thanks
Hi, is there another location from the code? I couldn´t download it from the source you post.
Thanx
Yes, is there another location for this code? I couldn’t download it either and it looks like it would be very helpful. Thanks.
Hi, I couldn’t download it either. Is there another location for the code?
thanx a lot ! this wz too easy..but wont hv been possible w/o your guidance… 🙂
thanks. But what is mainimage ?
Image mainimage = pictureBox1.Image;
c quoi le mainimage
Thanks for that code, it helps me a lot.
Now i’ve written a code which make my camera view visible into one picturebox. I want to know how to do the same on that video (draw a line, a rectangle or things like that). Thank you