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);
  • 相关阅读:
    基于Diff机制的多个状态合并
    do_mmap解读
    Linux对用户态的动态内存管理
    我的WordPress站点
    使用Bochs学习硬件原理
    inode的若干锚
    Use sed and awk to prettify json
    IO完成端口
    如何使用iText制作中文PDF
    Font and PDF
  • 原文地址:https://www.cnblogs.com/draymond/p/11211278.html
Copyright © 2011-2022 走看看