zoukankan      html  css  js  c++  java
  • 二维码图片流转base64

    @RequestMapping(value = "/weChatImage",method = RequestMethod.GET)
    public Response weChatimage(@RequestParam(required=false) int width,@RequestParam(required=false) int height,@RequestParam(required = false) String redirect, HttpServletResponse response) throws Exception{

    String code = java.util.UUID.randomUUID().toString();
    String code_url = SystemProperties.getValue("ucenter.out.url")+"/weChat/scanCode?state="+code;
    //String code_url = "http://localhost:8080/weChat/scanCode?state="+code;
    Map<String,Object> map1 = new HashMap<>();
    map1.put("redirect",redirect);
    redis.opsForValue().set(code,JSON.toJSONString(map1),7,TimeUnit.DAYS);

    if(width == 0){
    width = 200;//宽度
    }
    if(height == 0){
    height = 200;//高度
    }

    Map<EncodeHintType,Object> hints = new HashMap<>();
    hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");

    //生成矩阵
    BitMatrix bitMatrix = new MultiFormatWriter().encode(code_url, BarcodeFormat.QR_CODE, width, height, hints);

    //字节数组输出流
    ByteArrayOutputStream imageOut = new ByteArrayOutputStream();
    MatrixToImageWriter.writeToStream(bitMatrix, "png", imageOut);

    //字节数组输入流
    ByteArrayInputStream imageIn = new ByteArrayInputStream(imageOut.toByteArray());
    BufferedImage bImage = ImageIO.read(imageIn);

    ByteArrayOutputStream bs =new ByteArrayOutputStream();
    ImageIO.write(bImage, "png", bs);

    String base64 = "data:image/png;base64,"+Base64.byteArrayToBase64(bs.toByteArray());
    Map<String,Object> map = new HashMap<>();
    map.put("base64",base64);
    map.put("url",code_url);
    map.put("code",code);

    return Response.newInstance().setStatus(Response.SUCCESS).setBody(map);
    }
  • 相关阅读:
    为什么大多Virtual Globe程序纵向旋转效率比较低
    惠普卖印刷服务 GIS卖什么?
    OpenLayers的新功能:矢量支持
    Google部分开源GMap API
    为OpenLayers 2.3添加Overview窗口
    从Grid控件到GIS软件
    GIS(数据)浏览器的点点滴滴
    ArcGIS 9.3和ArcGIS 10,一点感想
    关注:Pitney Bowes以4.08亿美金收购Mapinfo
    ArcGIS Server安装的几个问题
  • 原文地址:https://www.cnblogs.com/zjdeblog/p/10001408.html
Copyright © 2011-2022 走看看