C#:如何生成矢量图形 [英] C#: How to produce a vector graphic

查看:89
本文介绍了C#:如何生成矢量图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用c#图元文件类创建矢量图形.
以下代码仅生成光栅图形.

如何创建矢量图形?

I try to create a vector graphic with c# Metafile class.
The following code produces only raster graphics.

How a vector graphic can be created?

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;

class CreateMetafileMemory : Form
{
    MemoryStream ms = new MemoryStream();
    Graphics g;

    public static void Main()
    {
        Application.Run(new CreateMetafileMemory());

    }

    public CreateMetafileMemory()
    {
        Graphics grfx = CreateGraphics();
        MemoryStream ms = new MemoryStream();
        IntPtr ipHdc = grfx.GetHdc();

        Metafile mf = new Metafile(ms, ipHdc);
        grfx.ReleaseHdc(ipHdc);
        grfx.Dispose();
        grfx = Graphics.FromImage(mf);

        grfx.FillEllipse(Brushes.Gray, 0, 0, 100, 100);
        grfx.DrawEllipse(Pens.Black, 0, 0, 100, 100);
        grfx.DrawArc(new Pen(Color.Red, 10), 20, 20, 60, 60, 30, 120);
        grfx.Dispose();
        mf.Save(@"C:\file.emf", ImageFormat.Emf);
        mf.Save(@"C:\file.wmf", ImageFormat.Wmf);
    }
}



将要生成的所有两个文件都是PNG文件.您可以通过十六进制编辑器对此进行验证.



All the two files which will be produced are PNG-Files. You can verify this by an Hex-Editor.

推荐答案

WMF文件被分类为矢量图形格式,那么,这是什么使您说它正在生成Raster?图形?
A WMF file is classed as a Vector Graphics format, so what is it that makes you say it is producing Raster Graphics?


C#图像保存Methode仅支持保存在光栅图形中.不支持编写矢量图形.
解决方案是使用gdi32.dll的非托管代码.

遵循一些示例代码(德语wegsite)

写入WMF文件(将失去透明度)
http://mk85.de/?p=158

写入EMF文件(保持透明)
http://mk85.de/?p=165
C# Image save Methode does only support to save in raster graphics. No writing of vector graphics is supported.
The solution is to use unmanaged code of the gdi32.dll.

Following some example codes (german wegsite)

Write WMF-Files (will loose transparency)
http://mk85.de/?p=158

Write EMF-Files (hold transparency)
http://mk85.de/?p=165


这篇关于C#:如何生成矢量图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆