2011-10-13 27 views
6

ExportString bir EMF veya GIF? Bu demo streamoutput.emf olarak nasılsa karıştırılmış olur:Grafiklerin ExportString ile dönüştürülmesi

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 ben NetLink, mesela yoluyla EMF aktarmak için kullanmak mümkün olabilir çalıştıysa

kernel.Compute("ExportString[Graphics[Rectangle[]], \"EMF\"]"); 
File.WriteAllText("C:\\Temp\\output.emf", kernel.Result.ToString()); 

Ek

çalışma olduğunu var. Çıktı dosyası "GIF.... yerine sadece GIF... gibi bir şeyle başlar yüzden bakılırsa

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

cevap

8

, Write, dize filestream yazma tırnak işareti içerir. Write yerine BinaryWrite kullanırken, işe yarıyor gibi görünüyor. Örneğin

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

en az GIF için geçerli bir dize üretir

streamoutput

Yani ExportString üretir. Pencerem yok, bu yüzden EMF için test yapamam.

+3

Bu çözümün Windows'ta EMF için de çalıştığını doğruladım. – WReach

+0

Teşekkürler, Heike. EMF de çalışıyor. –

İlgili konular