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

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

I get an org.apache.batik.bridge.BridgeException from apache png transcoder

问题

以下是您要求的代码翻译部分:

  1. try {
  2. PNGTranscoder coder = new PNGTranscoder();
  3. StringReader reader = new StringReader(getSVG());
  4. TranscoderInput input = new TranscoderInput(reader);
  5. FileOutputStream outputStream = new FileOutputStream("tmp/tmp.png");
  6. TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
  7. try {
  8. coder.transcode(input, transcoderOutput);
  9. } finally {
  10. reader.close();
  11. outputStream.close();
  12. }
  13. } catch (Exception e) {
  14. ErrorHandler.getInstance().handle(e);
  15. }

请注意,上述代码片段只是提供了您要求的部分翻译内容,不包含其他任何回答或额外内容。如果您有任何其他问题或需要进一步帮助,请随时提问。

英文:

I want to generate a png from a svg string with this code:

  1. try {
  2. PNGTranscoder coder = new PNGTranscoder();
  3. StringReader reader = new StringReader(getSVG());
  4. TranscoderInput input = new TranscoderInput(reader);
  5. FileOutputStream outputStream = new FileOutputStream("tmp/tmp.png");
  6. TranscoderOutput transcoderOutput = new TranscoderOutput(outputStream);
  7. try{
  8. coder.transcode(input, transcoderOutput);
  9. }finally{
  10. reader.close();
  11. outputStream.close();
  12. }
  13. } catch (Exception e) {
  14. ErrorHandler.getInstance().handle(e);
  15. }

But if i run the code, i get an exception because an uri cant be opend because it is corrup or unsupported:

  1. org.apache.batik.bridge.BridgeException: null:0
  2. The URI "https://cdn.discordapp.com/avatars/xxx/xxx.png"
  3. on element <image> can't be opened because:
  4. JDK URL is corrupt or unsupported variant
  5. at org.apache.batik.bridge.UserAgentAdapter.getBrokenLinkDocument(UserAgentAdapter.java:449)
  6. at org.apache.batik.bridge.SVGImageElementBridge.createRasterImageNode(SVGImageElementBridge.java:604)
  7. at org.apache.batik.bridge.SVGImageElementBridge.createImageGraphicsNode(SVGImageElementBridge.java:327)
  8. at org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(SVGImageElementBridge.java:177)
  9. at org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(SVGImageElementBridge.java:119)
  10. [...]

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:

确定