tags:

views:

53

answers:

2

Hi all

I need to parse an XML file of coordinates and create a .png (from scratch) in which I draw paths between the coordinates. I also need to be able to smooth the corners when paths change direction (maybe using beziers).

How can I do this programmatically in C#?

Thanks

+3  A: 

C# doesn't have any notion of graphics—you'll need a choose a vector graphics library to do the work for you. Since you're already in .NET, I'd suggest WPF to construct the image, and the Bitmap classes to export the final result as a PNG.

You can find a great introduction to WPF vector graphics here.

starkos
+2  A: 

You can paint into a bitmap using the Graphics object and DrawBezier method: http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawbezier.aspx

And then use the Save method to store it as png.

I can't paste you code right now because I don't have a dev environment to make a sample, but it should be something like:

  1. Create a Bitmap with the size you need:

    Bitmap bitmap = new Bitmap(width,height);
    
  2. Get a Graphics object from your bitmap :

    Graphics graphics= Graphics.FromImage(bitmap);
    
  3. Use the graphics object to draw (with DrawBezier if it's your case)

    graphics.DrawBezier(pen, a,b,c);
    
  4. Call to Save method indicating png format:

    bitmap.Save(path,ImageFormat.Png);
    
jmservera