wolfram-mathematica - 使用 ExportString 转换图形

标签 wolfram-mathematica

ExportString 可以导出 EMF 或 GIF 吗?在这个演示中,streamoutput.emf 不知何故被破坏了:

Quiet[DeleteFile["C:\\Temp\\thisworks.emf"]];
Quiet[DeleteFile["C:\\Temp\\streamoutput.emf"]];

graphic = Graphics[{Thick, Red, Circle[{#, 0}] & /@ Range[4],
    Black, Dashed, Line[{{0, 0}, {5, 0}}]}];
Export["C:\\Temp\\thisworks.emf", graphic, "EMF"];

file = ExportString[graphic, "EMF"];
stream = OpenWrite["C:\\Temp\\streamoutput.emf", BinaryFormat -> True];
Write[stream, file];
Close[stream];

如果 ExportString 有效,我可能可以使用它通过 NETLink 传输 EMF,例如
kernel.Compute("ExportString[Graphics[Rectangle[]], \"EMF\"]");
File.WriteAllText("C:\\Temp\\output.emf", kernel.Result.ToString());

附录

得到了工作。
kernel.Compute("ExportString[Graphics[Rectangle[]],{\"Base64\",\"EMF\"}]");
byte[] decodedBytes = Convert.FromBase64String(kernel.Result.ToString());
File.WriteAllBytes("C:\\Temp\\output.emf", decodedBytes);

最佳答案

看样子,Write包括字符串 file 的引号写信给 stream 时,所以输出文件以 "GIF.... 开头而不仅仅是 GIF... .使用时 BinaryWrite而不是 Write它似乎工作。例如

file = ExportString[graphic, "GIF"];
stream = OpenWrite["streamoutput.gif", BinaryFormat -> True];
BinaryWrite[stream, file];
Close[stream];
Import["streamoutput.gif"]

产生

streamoutput

所以ExportString至少会为 GIF 生成一个有效的字符串。我没有 window ,所以我无法测试 EMF。

关于wolfram-mathematica - 使用 ExportString 转换图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755810/

相关文章:

memory-management - SystemCache 和 MemoryInUse - 谁能解释这种行为?

sorting - 鸽子函数: where to insert x into a sorted list

wolfram-mathematica - Mathematica中的计算几何包和 “Nontensor object generated”

wolfram-mathematica - (MathLink) 正确处理从属内核生成的消息

python - 从 Mathematica 到 Python

interface - Mathematica 和 GAP : Is there an interface?

wolfram-mathematica - Mathematica 中是否有 "normal"EqualQ 函数?

graphics - 适合笔记本宽度 Mathematica 中的 ImageSize

wolfram-mathematica - $多变量假设

wolfram-mathematica - 从 Palette 操作获取包时出现阴影问题