4
Answers

draw a ellipse on an image

shameer pv

shameer pv

15y
8.4k
1
hai...
in my project , we need to draw an ellipse on an  image. the project is coded in c#. how can i draw an ellipse on an image . i hope reply soon
thanks in advance 
Answers (4)
0
Amit Choudhary
NA 27.7k 3m 15y

hi friend,
use below code to draw ellipse on image:
Graphics xGraph;
int k;
int r; 
int x, y; 
Bitmap DrawArea;
DrawArea = new Bitmap(Width,Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

xGraph = Graphics.FromImage(DrawArea);

Random rnd = new Random((int)DateTime.Now.Ticks); // seeded with ticks
Pen myPen = new Pen(Color.Red);
// Drawing random circles in the bitmap image area
myPen.Color = Color.FromArgb(
(rnd.Next(0, 255)),
(rnd.Next(0, 255)),
(rnd.Next(0, 255)));
System.Drawing.Image image= System.Drawing.Image.FromFile("C:\abc.jpg");
xGraph.DrawImage(image, 0, 0, DrawArea.Width, DrawArea.Height, System.Drawing.GraphicsUnit.Pixel);
xGraph.DrawEllipse(myPen, x - r, y - r, r, r); 

DrawArea.Save("C:\\abc.bmp");
xGraph.Dispose();
DrawArea.Dispose();



Please mark as answer if it helps.
Accepted
0
ffvc  ret
NA 4 0 10y
have you checked this image drawing tutorial, not only it can help me draw ellipse but also other graphics on image and document page. it worked well for me. besides you can add ellipse annotation.
0
shameer pv
NA 17 53.4k 15y
thanx for ur  reply.........
when executing this i have an error . the error msg is "A Graphics object cannot be created from an image that has an indexed pixel format".
i'm trying to draw ellipse on a binary image.
i hope u will reply soon
thanx in advance
0
Aleksandar Ilioski
NA 448 0 15y

Here is some example code: how to draw eclipse on image..  hope it will help you.. 
{
  Image img = Image.FromFile("d:\\img.jpg");
  gr = Graphics.FromImage(img);
  gr.DrawEllipse(Pens.Black, 0, 0, 200, 100);
  img.Save("d:\\newImg.jpg");
}