Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear ALL

I want to convert Graphics data in vector format.For that I have start from basic shape.Here i am trying To get path of Graphics object.For that draw one Ellipse and try to get path data.But when draw this data on screen it show the rectangle.Please let me know how to get angle of this pointor how to get angular point of my circle.In short i need whatever draw(Ignore Image) on Graphics it should be MoveTo,LineTo or Arc(angle) format.

I am using following code for that.

C#
private void Form1_Paint(object sender, PaintEventArgs e)
{
    Pen pen=new Pen(Color.Black);             
    GraphicsPath path = new GraphicsPath();       
    path.AddEllipse(10, 10, 50, 50);
    e.Graphics.DrawPath(pen, path);
   
    int icount = path.PointCount;
    PointF[] p = new PointF[icount];
    GraphicsPath Newpath = new GraphicsPath();            
    for (int k = 0; k < icount; k++)
    {
        p[k] = path.PathPoints[k];
        p[k].X += 50;
        p[k].Y += 50;                            
    }
    e.Graphics.DrawLines(pen, p);               
}

Please let me know how to solve it.
Is it any other way to get this information.

Thanks
Posted
Updated 3-Feb-12 23:54pm
v2

1 solution

Hi,

You have thousands examples on net about C# Graphics[^].
Here is the example how to draw ellipse:
C#
private void Form1_Paint(object sender, PaintEventArgs e)
       {
            System.Drawing.Graphics graphicsObj;

            graphicsObj = this.CreateGraphics();

            Pen myPen = new Pen(System.Drawing.Color.Green, 5);
            Rectangle myRectangle = new Rectangle(20, 20, 250, 200);
            graphicsObj.DrawEllipse(myPen, myRectangle);
       }

Here are some of them:
1. http://www.dotnettutorials.com/tutorials/graphics/winforms-drawing-cs.aspx[^]
2. http://www.techotopia.com/index.php/Drawing_Graphics_in_C_Sharp[^]
3. http://www.deitel.com/articles/csharp_tutorials/20051025/IntroTo2DGraphics.html[^]

Just google by keyword you need and I'm sure will find what you need...
 
Share this answer
 
Comments
GAJERA 6-Feb-12 1:49am    
Thanks for Quick reply.
Ok,I check your link and it helpful for me but problem is as it is.
Please check my Bold line which are explain detail.
My problem is mention with Underline text.


Pen pen=new Pen(Color.Black);
GraphicsPath path = new GraphicsPath();
//AddEllipse in Path
path.AddEllipse(10, 10, 50, 50);
//Count Number of point of Ellipse
int icount = path.PointCount;
//Take new temp point array
PointF[] p = new PointF[icount];
//Add all point of path with offset in Temp array
for (int k = 0; k < icount; k++)
{
//How to get this PathPoints as circular point ?
p[k] = path.PathPoints[k];
p[k].X += 50;
p[k].Y += 50;
}
//Draw All point as a line in Graphics
e.Graphics.DrawLines(pen, p);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900