英文:
I get an org.apache.batik.bridge.BridgeException from apache png transcoder
问题
以下是您要求的代码翻译部分:
try {
PNGTranscoder coder = new PNGTranscoder();
StringReader reader = new StringReader(getSVG());
TranscoderInput input = new TranscoderInput(reader);
FileOutputStream outputStream = new FileOutputStream("tmp/tmp.png");
TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
try {
coder.transcode(input, transcoderOutput);
} finally {
reader.close();
outputStream.close();
}
} catch (Exception e) {
ErrorHandler.getInstance().handle(e);
}
请注意,上述代码片段只是提供了您要求的部分翻译内容,不包含其他任何回答或额外内容。如果您有任何其他问题或需要进一步帮助,请随时提问。
英文:
I want to generate a png from a svg string with this code:
try {
PNGTranscoder coder = new PNGTranscoder();
StringReader reader = new StringReader(getSVG());
TranscoderInput input = new TranscoderInput(reader);
FileOutputStream outputStream = new FileOutputStream("tmp/tmp.png");
TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
try{
coder.transcode(input, transcoderOutput);
}finally{
reader.close();
outputStream.close();
}
} catch (Exception e) {
ErrorHandler.getInstance().handle(e);
}
But if i run the code, i get an exception because an uri cant be opend because it is corrup or unsupported:
org.apache.batik.bridge.BridgeException: null:0
The URI "https://cdn.discordapp.com/avatars/xxx/xxx.png"
on element <image> can't be opened because:
JDK URL is corrupt or unsupported variant
at org.apache.batik.bridge.UserAgentAdapter.getBrokenLinkDocument(UserAgentAdapter.java:449)
at org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(SVGImageElementBridge.java:604)
at org.apache.batik.bridge.SVGImageElementBridge.createImageGraphicsNode(SVGImageElementBridge.java:327)
at org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(SVGImageElementBridge.java:177)
at org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(SVGImageElementBridge.java:119)
[...]
While converting this svg: https://hastebin.com/mamudofira.xml
The image url is replaced for privacy but its working!
答案1
得分: 0
我通过首先将图像下载为Base64字符串,然后将其设置为SVG中的xlink:href
,自行解决了这个问题。
英文:
I fixed it myself by first downloading the image as base64 string and then setting it as xlink:href
in the svg.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论