I have a PictureBox which display an image and I want to draw some lines on this image like this , and save it after the drawing , How can I achieve that ?
Asked
Active
Viewed 174 times
1

Anas Saradar
- 130
- 7
-
1"I want to draw some line" Is a very big scope. You need to define exactly how you want to draw lines? From codes or with some tools like MS paint? – Rahatur May 18 '22 at 11:19
-
Study [this](https://stackoverflow.com/questions/27337825/picturebox-paintevent-with-other-method/27341797#27341797) - For a more complex solution look [here](https://stackoverflow.com/questions/49290951/creating-different-brush-patterns-in-c-sharp/49298313#49298313) – TaW May 18 '22 at 14:45
1 Answers
0
The simplest option would be to use Graphics.FromImage. I.e.
- Create a new bitmap
- Create a graphics object
- Draw the original image
- Draw your line(s)
- Dispose graphics
- Save bitmap
- optionally replace the image in the pictureBox
If you want realtime feedback you might want to create your own PictureBox derived class and override OnPaint to show the lines. And only create a bitmap when you want to save.

JonasH
- 28,608
- 2
- 10
- 23
-
I tried that , I loaded my photo and display it in the picture box , then draw some lines using graphics = picBox.CreateGraphics(); and some mouse Event method But when I get the image from the picBox it was the same no changes and no lines ... Can U help me with that ? – Anas Saradar May 18 '22 at 13:29
-
1@SARADAR21 do not use `.CreateGraphics`. Either draw on a bitmap with GraphicsFromImage, override OnPaint, or attach an eventhandler to the Paint-event. – JonasH May 18 '22 at 13:44