2016-07-07 29 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版本? –