我想使用 batik1.7 将 svg 文件转换为 png 格式,我的代码如下:
public static void convertSvgToPng(InputStream in, FileOutputStream fos) {
try {
PNGTranscoder t = new PNGTranscoder();
TranscoderInput input = new TranscoderInput(in);
TranscoderOutput output = new TranscoderOutput(fos);
t.transcode(input, output);
fos.flush();
fos.close();
} catch (IOException ex) {
Logger.getLogger(CreateFile.class.getName()).log(Level.SEVERE, null, ex);
} catch (TranscoderException ex) {
Logger.getLogger(CreateFile.class.getName()).log(Level.SEVERE, null, ex);
}
}
但是有些图像无法转换,并且出错了:
org.apache.batik.bridge.BridgeException: null:-1
The URI "#Unnamed_Pattern"
specified on the element <pattern> is invalidat org.apache.batik.bridge.SVGPatternElementBridge.extractPatternContent(SVGPatternElementBridge.java:260)
at org.apache.batik.bridge.SVGPatternElementBridge.createPaint(SVGPatternElementBridge.java:86)
at org.apache.batik.bridge.PaintServer.convertURIPaint(PaintServer.java:359)
at org.apache.batik.bridge.PaintServer.convertPaint(PaintServer.java:259)
at org.apache.batik.bridge.PaintServer.convertFillPaint(PaintServer.java:228)
at org.apache.batik.bridge.PaintServer.convertFillAndStroke(PaintServer.java:146)
at org.apache.batik.bridge.SVGShapeElementBridge.createShapePainter(SVGShapeElementBridge.java:117)
at org.apache.batik.bridge.SVGDecoratedShapeElementBridge.createFillStrokePainter(SVGDecoratedShapeElementBridge.java:58) ....
当我用 TXT 打开 svg 时,会有 mang “pattern” 标签。在我用程序删除所有“模式”后,转换成功,但失去了一些细节。我认为这不是解决这个问题的好方法。它还有其他方法可以解决这个问题吗?请帮我。
问题文件:</p>
jsfiddle.net/asdzheng/BtFbX/1/