2016-07-07 94 views
0

我試圖把一個.SVG文件轉換成的.jpgpng格式文件生成SVG JPG。現在我正在嘗試使用Apache Batik TranscoderLink)。使用Apache蠟染

這是我的代碼現在:(從here官方代碼)

// Create a JPEG transcoder 
JPEGTranscoder t = new JPEGTranscoder(); 

// Set the transcoding hints. 
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 
    new Float(.8)); 

// Create the transcoder input. 
String svgURI = new File("C:/test.svg").toURL().toString(); 
TranscoderInput input = new TranscoderInput(svgURI); 

// Create the transcoder output. 
OutputStream ostream = new FileOutputStream("C:/out.jpg"); 
TranscoderOutput output = new TranscoderOutput(ostream); 

// Save the image. 
t.transcode(input, output); 

// Flush and close the stream. 
ostream.flush(); 
ostream.close(); 
System.exit(0); 

但它給我這個錯誤:

Exception in thread "main" org.apache.batik.transcoder.TranscoderException: null

Enclosed Exception:

null

at org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown Source)

at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)

at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)

at SaveAsJPEG.main(SaveAsJPEG.java:27)

我不知道該怎麼辦,因爲這是他們網站(!)的代碼。所以,如果你知道如何解決它或有另一種想法,我可以如何將我的.svg圖片轉換爲.jpg和.png的讓我知道。

+0

你是否熟悉JMagick(基於ImageMagick)? – Yaron

+0

文件「C:/ test.svg「存在嗎? –

+0

@ErwinBolwidt是的存在 – JetStream

回答

1

嗯,我現在已經找到了解決我的問題。好像蠟染1.8(我都用)不能正常工作(或至少不,他們說他們的API頁面的方式工作。

我現在用蠟染1.7至極的作品就好了。所以現在一切都很好,對每個想要使用Batik的人來說:我建議你使用1.7,因爲文檔不是1.8左右。

+0

你正在使用的Java版本? –