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"]
产生
所以
ExportString
至少会为 GIF 生成一个有效的字符串。我没有 window ,所以我无法测试 EMF。
关于wolfram-mathematica - 使用 ExportString 转换图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755810/