【发布时间】:2016-09-06 08:09:29
【问题描述】:
我有一个带有 SVG 图像的 MulipartFile 对象。我想把它转换成 JPEG 格式。我怎样才能做到这一点?我尝试了以下方法,但由于系统找不到指定的文件而出现封闭异常。
JPEGTranscoder t = new JPEGTranscoder();
File f = new File("temp.svg");
multipartfile.transferTo(f);
// Create a JPEG transcoder
// Set the transcoding hints.
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,
new Float(.8));
// Create the transcoder input.
String svgURI = f.toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
// Create the transcoder output.
OutputStream ostream = new FileOutputStream("out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
// Save the image.
t.transcode(input, output);
// Flush and close the stream.
ostream.flush();
ostream.close();
【问题讨论】:
-
到目前为止您尝试过什么?
batik convert svg to jpeg在互联网搜索引擎中的第一个结果是xmlgraphics.apache.org/batik/tools/rasterizer.html。