简体   繁体   English

如何创建写入图形对象的.PS,.SVG和.PNG?

[英]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. 我想通过写入Graphics对象来创建不同的矢量和栅格文件。 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? 有没有一种方法可以在其中提供一个我可以建立相同图形对象并获取每个输出的Graphics对象?

(Java has this built around the Graphics2D object, I'm hoping .NET has the same.) (Java具有围绕Graphics2D对象构建的对象,我希望.NET具有相同的对象。)

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). “ cairo”开放源代码库始终是在这些前提下构建的-尽管您必须为栅格和矢量输出构建一个单独的对象(具有不同的绘制上下文),但在两个上下文中绘制的API都是相同的(因此,您只需要复制所有绘图调用)。

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 我从未尝试过将其绑定到.net,但我认为它们是可以的: https ://forums.dotnetfoundation.org/t/the-cairo-c-binding-has-been-ported-to-net-core / 2075https://github.com/zwcloud/CairoSharp

You could use a Bitmap object for raster graphics. 您可以将Bitmap对象用于栅格图形。 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. 您可能需要为每种矢量图形格式查找库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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