简体   繁体   中英

How can I create a .PS, .SVG, & .PNG writing to a Graphics object?

I want to create different vector and raster files by writing to a Graphics object. Is there a way to do this where it will provide a Graphics object I can build up the same and get each of these outputs?

(Java has this built around the Graphics2D object, I'm hoping .NET has the same.)

The "cairo" open source library was always built on these premises - although you'd have to build a separate object (with a different drawing context) for both raster and vector outputs, the API for drawing in both contexts is identical (so, you just have to duplicate all drawing calls).

I had never tried its bindings to .net, though, but I supose they are ok: https://forums.dotnetfoundation.org/t/the-cairo-c-binding-has-been-ported-to-net-core/2075 , https://github.com/zwcloud/CairoSharp

You could use a Bitmap object for raster graphics. For example

using(Bitmap bitmap = new Bitmap(100,100))
{
    using(Graphics g = Graphics.FromImage(bitmap))
    {
        // draw to graphics object
        ...
        // save the image. the second parameter specifies the format
        // you can use bmp, emf, gif, png, jpeg, ...
        bitmap .Save("pathToFile",ImageFormat.Bmp)

    }
}

Vector graphics are more complicated. You will probably need to look for libraries for each vector graphics format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM