java batik svg转png报错,来人呢!!!!!

l677766 2014-08-07 09:01:47
报错内容
org.apache.batik.transcoder.TranscoderException: null
Enclosed Exception:
The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: point).
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown Source)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(Unknown Source)
at com.test.Test.svgToJpg(Test.java:129)
at com.test.Test.convert(Test.java:92)
at com.test.Test.main(Test.java:37)
代码:
/**
* 将svg转化为JPG
*
* @param src
* @param dest
*/
public static void svgToJpg(String src, String dest) {
FileOutputStream jpgOut = null;
FileInputStream svgStream = null;
ByteArrayOutputStream svgOut = null;
ByteArrayInputStream svgInputStream = null;
ByteArrayOutputStream jpg = null;
try {
// 获取到svg文件
File svg = new File(src);
svgStream = new FileInputStream(svg);
svgOut = new ByteArrayOutputStream();
// 获取到svg的stream
int noOfByteRead = 0;
while ((noOfByteRead = svgStream.read()) != -1) {
svgOut.write(noOfByteRead);
}
ImageTranscoder it = new PNGTranscoder();
it.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.8));
it.addTranscodingHint(ImageTranscoder.KEY_HEIGHT, new Float(2000));
it.addTranscodingHint(ImageTranscoder.KEY_WIDTH, new Float(4000));
jpg = new ByteArrayOutputStream();
svgInputStream = new ByteArrayInputStream(svgOut.toByteArray());
it.transcode(new TranscoderInput(svgInputStream),
new TranscoderOutput(jpg));
jpgOut = new FileOutputStream(dest);
jpgOut.write(jpg.toByteArray());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (svgInputStream != null) {
svgInputStream.close();
}
if (jpg != null) {
jpg.close();
}
if (svgStream != null) {
svgStream.close();
}
if (svgOut != null) {
svgOut.close();
}
if (jpgOut != null) {
jpgOut.flush();
jpgOut.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
...全文
1116 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
csucaicai 2014-08-07
  • 打赏
  • 举报
回复
你至少先调一调啊,看看哪一步错了,分析下原因,实在弄不出来,你就调用在线的转换吧
tony4geek 2014-08-07
  • 打赏
  • 举报
回复
没做过类似的

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧