【问题标题】:Apache Batik No WriteAdapter is available?Apache Batik 没有 WriteAdapter 可用?
【发布时间】:2017-07-26 13:50:35
【问题描述】:

我正在编写将 SVG 转换为 PNG 的代码:

package com.example;

import java.io.*;
import java.nio.file.Paths;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.SVGAbstractTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

public class Main {

    public static void main(String [] args) throws Exception {

        // read the input SVG document into TranscoderInput
        String svgURI = Paths.get(args[0]).toUri().toURL().toString();
        TranscoderInput input = new TranscoderInput(svgURI);
        // define OutputStream to PNG Image and attach to TranscoderOutput
        OutputStream ostream = new FileOutputStream("out.png");
        TranscoderOutput output = new TranscoderOutput(ostream);
        // create a JPEG transcoder
        PNGTranscoder t = new PNGTranscoder();
        // set the transcoding hints
        t.addTranscodingHint(SVGAbstractTranscoder.KEY_HEIGHT, new Float(600));
        t.addTranscodingHint(SVGAbstractTranscoder.KEY_WIDTH, new Float(600));
        // convert and write output
        t.transcode(input, output);
        // flush and close the stream then exit
        ostream.flush();
        ostream.close();
    }
}

使用各种 SVG 执行它时出现以下异常:

Exception in thread "main" org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
Could not write PNG file because no WriteAdapter is availble
    at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:132)
    at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)
    at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)
    at com.example.Main.main(Main.java:26)

蜡染版(Maven报道):

version=1.9
groupId=org.apache.xmlgraphics
artifactId=batik-transcoder

我在使用 Batik 1.7 时遇到同样的错误。

建议?

【问题讨论】:

标签: svg batik


【解决方案1】:

Peter Coppens 在 xmlgraphics-batik-users 邮件列表中解决了这个问题。问题是 Batik 1.9 的 Maven 存储库缺少依赖项,可以通过添加到 pom.xml 来解决:

<dependency>
    <groupId>org.apache.xmlgraphics</groupId>
    <artifactId>batik-codec</artifactId>
    <version>1.9</version>
</dependency>

这个神秘的异常消失了,代码按预期运行。这被报告为 Batk 1.7 (https://bz.apache.org/bugzilla/show_bug.cgi?id=44682) 的一个错误。

【讨论】:

  • 在哪里可以找到 pom.xml ?
  • 我的 pom.xml 的依赖节点包括:org.apache.xmlgraphicsbatik-transcoder1.9org.apache.xmlgraphicsbatik-codec1.9 希望有帮助。
  • 我在 1.10 版也遇到过同样的问题
  • 同1.11版
  • 在 1.13 中还是一样
猜你喜欢
  • 1970-01-01
  • 2016-11-09
  • 2018-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 2019-10-03
  • 2016-08-30
相关资源
最近更新 更多