zoukankan      html  css  js  c++  java
  • google 生成二维码

    maven依赖

    <!--google 二维码-->
    <dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>javase</artifactId>
    <version>${google-zxing}</version>
    </dependency>
    <dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>core</artifactId>
    <version>${google-zxing}</version>
    </dependency>
    <properties>
      <google-zxing>3.2.1</google-zxing>
    </properties>

    代码

    //生成二维码
    //1 定义一个json格式字符串
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("company", "www.baidu.com");
    jsonObject.put("name", "百度");
    String content = String.valueOf(jsonObject);

    int width = 200;
    int hight = 200;
    //2 编码格式设置等
    Map<EncodeHintType, Object> map = new HashMap<EncodeHintType, Object>();
    map.put(EncodeHintType.CHARACTER_SET, "UTF-8");

    //3 创建一个二维矩阵对象
    BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, hight, map);


    //矩阵 格式(jpj) 路径
    //4 生成的路径
    String filePath = "D://";
    String fileName = "QRCode.jpg";
    Path path = FileSystems.getDefault().getPath(filePath, fileName);
    //5 将矩阵对象转成图片
    MatrixToImageWriter.writeToPath(bitMatrix, "jpg", path);
  • 相关阅读:
    权限系统设计-day02
    权限系统设计-day01
    SSH集成(Struts+Spring+Hibernate)
    Spring-day03
    Spring-day02
    神经网络与深度学习
    深度学习概述
    结构化机器学习项目
    无监督学习方法
    《2018自然语言处理研究报告》整理(附报告)
  • 原文地址:https://www.cnblogs.com/draymond/p/11211278.html
Copyright © 2011-2022 走看看