我从 Apache PNG 转码器得到了一个 org.apache.batik.bridge.BridgeException。

huangapple go评论99阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年4月5日 22:28:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/61044170.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定