-
Echarts 介绍 点我
-
通过事件跳转到JS函数
-
通过全局
echarts
DOM实例得到图片
是被加密过的img = myChart.getDataURL({ pixelRatio: 2, // double pixel backgroundColor: '#fff' });
-
Base64位图片传到服务器
-
base64
位图片直接传到服务器,会被http
协议转换掉,具体是空格
变+
号
String base64Str = request.getParameter("img"); base64Str = base64Str.replaceAll(" ", "+");
- js 加密
imgStr = encodeURIComponent(img);
这个加密后,不用Java是不用decode的,原因是
request.getParameter()
是会自动解密。 -
-
去除
Base64
协议类型头base64Str = base64Str.split("base64,")[1];
-
保存图片
/** * base64字符串转化成图片 * * @Author Mangodai * @Date 9/18/2017 6:10 PM * @param imgStr * @param imgFile * @return */ public static boolean GenerateImage(String imgStr, File imgFile) { //对字节数组字符串进行Base64解码并生成图片 if (imgStr == null) //图像数据为空 return false; BASE64Decoder decoder = new BASE64Decoder(); try { //Base64解码 byte[] b = decoder.decodeBuffer(imgStr); OutputStream out = new FileOutputStream(imgFile); out.write(b); out.flush(); out.close(); return true; } catch (Exception e) { return false; } }
网友评论