我尝试过使用batik。但我得到的是空 png 文件。我还包含了所有必需的罐子。
我的代码是
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
public class TestSVG {
String filePath="";
TestSVG(String filePath) throws Exception {
this.filePath=filePath;
createImage();
}
public void createImage() throws Exception{
String svg_URI_input = new File("test.svg").toURL().toString();
TranscoderInput input_svg_image = new TranscoderInput(svg_URI_input);
//Step-2: Define OutputStream to PNG Image and attach to TranscoderOutput
OutputStream png_ostream = new FileOutputStream("chessboard.png");
TranscoderOutput output_png_image = new TranscoderOutput(png_ostream);
// Step-3: Create PNGTranscoder and define hints if required
PNGTranscoder my_converter = new PNGTranscoder();
// Step-4: Convert and Write output
System.out.println("It will print");
my_converter.transcode(input_svg_image, output_png_image);
System.out.println("It will not print");
png_ostream.flush();
png_ostream.close();
}
}
请在代码中给出系统输出。到第 3 步为止,一切正常。
您必须使用转码提示。
例如对于 PNG,您应该设置要使用的像素。
my_converter.addTranscodingHint(PNGTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER,0.084672F);
my_converter.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)