问题描述
报错内容org.apache.batik.transcoder.TranscoderException:nullEnclosedException:Thecurrentdocumentisunabletocreateanelementoftherequestedtype(namespace:http://www.w3.org/2000/svg,name:point).atorg.apache.batik.transcoder.XMLAbstractTranscoder.transcode(UnknownSource)atorg.apache.batik.transcoder.SVGAbstractTranscoder.transcode(UnknownSource)atcom.test.Test.svgToJpg(Test.java:129)atcom.test.Test.convert(Test.java:92)atcom.test.Test.main(Test.java:37)代码:/***将svg转化为JPG**@paramsrc*@paramdest*/publicstaticvoidsvgToJpg(Stringsrc,Stringdest){FileOutputStreamjpgOut=null;FileInputStreamsvgStream=null;ByteArrayOutputStreamsvgOut=null;ByteArrayInputStreamsvgInputStream=null;ByteArrayOutputStreamjpg=null;try{//获取到svg文件Filesvg=newFile(src);svgStream=newFileInputStream(svg);svgOut=newByteArrayOutputStream();//获取到svg的streamintnoOfByteRead=0;while((noOfByteRead=svgStream.read())!=-1){svgOut.write(noOfByteRead);}ImageTranscoderit=newPNGTranscoder();it.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,newFloat(0.8));it.addTranscodingHint(ImageTranscoder.KEY_HEIGHT,newFloat(2000));it.addTranscodingHint(ImageTranscoder.KEY_WIDTH,newFloat(4000));jpg=newByteArrayOutputStream();svgInputStream=newByteArrayInputStream(svgOut.toByteArray());it.transcode(newTranscoderInput(svgInputStream),newTranscoderOutput(jpg));jpgOut=newFileOutputStream(dest);jpgOut.write(jpg.toByteArray());}catch(Exceptione){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(IOExceptione){e.printStackTrace();}}}
解决方案
解决方案二:
没做过类似的
解决方案三:
你至少先调一调啊,看看哪一步错了,分析下原因,实在弄不出来,你就调用在线的转换吧