.NETLink 图形生成 PNG 而不是 EMF [英] .NETLink Graphics producing PNG instead of EMF

查看:26
本文介绍了.NETLink 图形生成 PNG 而不是 EMF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的 C# 代码应该产生一个 EMF,但是查看输出(在 Vim 中)显示它是一个 PNG.也许有人在 S.O.知道一个好的变通办法或解决方案.

The C# code below should produce an EMF, but viewing the output (in Vim) shows it to be a PNG. Perhaps someone on S.O. knows a good work-around or solution.

MathKernel k = new MathKernel();
k.CaptureGraphics = true;
k.GraphicsFormat = "Metafile";
k.Compute("Show[Graphics[{Thick, Blue, Circle[{#, 0}] & /@ Range[4], Black, Dashed, Line[{{0, 0}, {5, 0}}]}]]");
k.Graphics[0].Save("C:\\Temp\\file.emf", System.Drawing.Imaging.ImageFormat.Emf);

到目前为止,我正在考虑将 Show[Graphics...] 包装在 ExportString[... , "EMF"] 中并使用 MathKernel Result 属性收集结果.

So far I'm considering wrapping Show[Graphics...] in ExportString[... , "EMF"] and collecting the result using the MathKernel Result property.

附录

MathKernel.Graphics 属性 [1] 显然是一种 .Net Graphics 方法,它仅处理位图等图像文件,而不处理基于矢量图形的增强元文件.

The MathKernel.Graphics property[1] is apparently a .Net Graphics method which only handles image files such as bitmaps, not vector graphic based enhanced metafiles.

  1. http://reference.wolfram.com/legacy/v7/NETLink/ref/net/Wolfram.NETLink.MathKernel.Graphics.html

增强型元文件可以通过 .NETLink 一次传输一个,方式如下:

Enhanced metafiles can be transferred through .NETLink one at a time though, in the following manner:

using System;
using System.IO;
using Wolfram.NETLink;

public class Example
{
    public static void Main(String[] args)
    {
        MathKernel k = new MathKernel();
        k.Compute("ExportString[Graphics[{Disk[]}], {\"Base64\", \"EMF\"}]");
        byte[] decodedBytes = Convert.FromBase64String(k.Result.ToString());
        // The transferred EMF can be used or simply written out to file.
        File.WriteAllBytes("C:\\Temp\\file.emf", decodedBytes);
    }
}

推荐答案

这是一个可行的解决方案:

Here is a working solution:

using System;
using Wolfram.NETLink;

public class Example {

 public static void Main(String[] args) {

  MathKernel k = new MathKernel();
  k.Compute("Export[\"c:/users/arnoudb/out.emf\", Graphics[{Disk[]}], \"EMF\"]");
  }

} 

我不知道你为什么考虑这个部分:

I am not sure why you consider this part:

k.Graphics[0].Save("C:\\Temp\\file.emf", System.Drawing.Imaging.ImageFormat.Emf);

一个 Mathematica 错误,因为 k.Graphics[0] 是一个纯 C# System.Drawing.Image 类.也许你可以澄清一下这部分?

a Mathematica bug, since k.Graphics[0] is a pure C# System.Drawing.Image class. Perhaps you can clarify this part a bit?

这篇关于.NETLink 图形生成 PNG 而不是 EMF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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