热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ApacheBatik没有WriteAdapter可用吗?

如何解决《ApacheBatik没有WriteAdapter可用吗?》经验,为你挑选了1个好方法。

我正在编写代码将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有同样的错误.

建议?



1> Al Pacifico..:

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


    org.apache.xmlgraphics
    batik-codec
    1.9

隐藏的异常消失了,代码按照预期的功能添加.据报道这是Batk 1.7的一个错误(https://bz.apache.org/bugzilla/show_bug.cgi?id=44682).


推荐阅读
author-avatar
无语我去_296
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有