Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a circle on an image

I have a program for image segmentation in WinForms Application C#, and I have an image loaded in a pictureBox. I need to draw a small circle(or an ellipse, it does not matter) on that image (inside a region of interest, and allowing it to grow outwards until it reaches the desired boundary).

And the question is how can I draw that circle anywhere on that image? (and if it`s possible to draw that circle in a different color, red for example)

Thank you.

like image 349
Bosco Avatar asked Oct 27 '25 21:10

Bosco


1 Answers

Sure take the graphic instance of the control anddraw on it . It will be reflected only when its repainted or Invalidated. Use DrawEllipse Method of Graphic Class to draw circle.

here is the code:

Graphics gf = picturebox1.CreateGraphics();
//A circle with Red Color and 2 Pixel wide line
gf.DrawEllipse(new Pen(Color.Red, 2),new Rectangle(0, 0, 200, 200));

Invalidate it to actually draw it on the control (picturebox)

picturebox1.Invalidate();

It will draw a circle 200 pixel in diameter

like image 161
Shekhar_Pro Avatar answered Oct 30 '25 11:10

Shekhar_Pro