//图表保存图片:重写提交方法 Ext.draw.engine.ImageExporter.generate = function(surface, config) { config = config || {}; var me = this, type = config.type; if (Ext.Array.indexOf(me.supportedTypes, type) === -1) { return false; } var form = Ext.getBody().createChild({ tag: ‘form‘, method: ‘POST‘, action: ‘../statis.do?action=svgtoimage‘, cls: me.formCls, children: [{ tag: ‘input‘, type: ‘hidden‘, name: config.typeParam || me.typeParam, value: type },{ tag: ‘input‘, type: ‘hidden‘, name: ‘filename‘, value: config.filename }, { tag: ‘input‘, type: ‘hidden‘, name: config.svgParam || me.svgParam }] }); form.last(null, true).value = Ext.draw.engine.SvgExporter.generate(surface); form.dom.submit(); form.remove(); return true; };
Java方法
/** * 将SVG转换成图片 * @param fileName 下载图片文件名称 * @param type 类型 * @param svg SVG 数据 * @param response * @return */ public String exportChartToImage(String fileName,String type,String svg,HttpServletResponse response){ String prefix = type.equals("image/png")?".png":".jpg"; response.setContentType(type); try { OutputStream os = response.getOutputStream(); response.addHeader("Content-Disposition","attachment;filename="+new String((fileName + prefix).trim().getBytes("gb2312"),"ISO8859-1")); StringReader reader = new StringReader(svg); TranscoderInput input = new TranscoderInput(reader); TranscoderOutput output = new TranscoderOutput(os); Transcoder t = null; if("image/png".equals(type)){ t = new PNGTranscoder(); }else if("image/jpeg".equals(type)){ t = new JPEGTranscoder(); } t.transcode(input, output); os.flush(); os.close(); } catch (IOException e) { e.printStackTrace(); } catch (TranscoderException e) { e.printStackTrace(); } return ""; }
本文出自 “RayGaditer” 博客,请务必保留此出处http://raygaditer.blog.51cto.com/9212738/1688481
原文地址:http://raygaditer.blog.51cto.com/9212738/1688481