Echarts 그림을 서버에 저장합니다.

1418 단어
  • 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);
    
    이 암호화 후 자바를 사용하지 않으면 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;
        }
    }
    
  • 좋은 웹페이지 즐겨찾기