mxgrapg的图片导出

mxgraph的xml 导出图片
以下2种后台的方法都有一个问题子,就是文字的字体样式不好使;但是如果是简单的使用还是可以的;要想样式好使,我采用的方法是前后台联合,即前台的到base64位的图片url ,然后后台再去处理(先提供一个思路,下回写);

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.imageio.ImageIO;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import com.mxgraph.canvas.mxGraphicsCanvas2D;
import com.mxgraph.canvas.mxICanvas2D;
import com.mxgraph.io.mxCodec;
import com.mxgraph.reader.mxSaxOutputHandler;
import com.mxgraph.util.mxCellRenderer;
import com.mxgraph.util.mxUtils;
import com.mxgraph.util.mxXmlUtils;
import com.mxgraph.view.mxGraph;

@RestController
public class ImageController {

private Logger logger = LoggerFactory.getLogger(getClass());
protected String attachmentPath = "D:"+File.separator+"lyq"+File.separator+"downDoc" ;


@RequestMapping(value = "export", method = RequestMethod.POST)
public void export(String filename, int w, int h, String xml) throws Exception {
	String path="";
	try {
		path = URLDecoder.decode(filename, "UTF-8");
		xml = URLDecoder.decode(xml, "UTF-8");
	} catch (UnsupportedEncodingException e1) {
		e1.printStackTrace();
	}
	String name=path.substring(0, path.lastIndexOf("."));
	
	  //将图片保存到本地
    try {
        logger.info(""+w+" "+h);
        logger.info(xml);
        logger.info(path);
        logger.info(name);
        xml="<mxGraphModel dx=\"608\" dy=\"591\" grid=\"1\" gridSize=\"10\" guides=\"1\" tooltips=\"1\" connect=\"1\" arrows=\"1\" fold=\"1\" page=\"1\" pageScale=\"1\" pageWidth=\"827\" pageHeight=\"1169\" background=\"none\">\n"
        		+ "  <root>\n"
        		+ "     <mxCell id=\"0\" />\n"
        		+ "    <mxCell id=\"1\" parent=\"0\" />\n"
        		+ "    <mxCell id=\"36\" value=\"\" style=\"rounded=0;whiteSpace=wrap;html=1;fillColor=#FFFFFF;fontSize=16;\" parent=\"1\" vertex=\"1\">\n"
        		+ "      <mxGeometry x=\"1240\" y=\"50\" width=\"960\" height=\"320\" as=\"geometry\" />\n"
        		+ "    </mxCell>\n"
        		+ "    <mxCell id=\"2\" value=\"\" style=\"rounded=0;w
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值