zoukankan      html  css  js  c++  java
  • Spring Boot项目开发(九)——生成二维码

    一、添加生成二维码相关依赖

    <!--生成二维码依赖-->
    <dependency>
        <groupId>com.google.zxing</groupId>
        <artifactId>javase</artifactId>
        <version>3.3.0</version>
    </dependency>

    二、编写生成二维码工具类

    package com.learn.mall.util;
    
    import com.google.zxing.BarcodeFormat;
    import com.google.zxing.WriterException;
    import com.google.zxing.client.j2se.MatrixToImageWriter;
    import com.google.zxing.common.BitMatrix;
    import com.google.zxing.qrcode.QRCodeWriter;
    
    import java.io.IOException;
    import java.nio.file.FileSystems;
    import java.nio.file.Path;
    
    /**
     * 生成二维码工具类
     */
    public class QRCodeGenerator {
        public static void generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException, IOException {
            QRCodeWriter qrCodeWriter = new QRCodeWriter();
            BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
            Path path = FileSystems.getDefault().getPath(filePath);
            MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
        }
    
        public static void main(String[] args) {
            try {
                generateQRCodeImage("code", 350, 350, "D:/files/mall-images/qrtest.png");
            } catch (WriterException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    POJ 1873 The Fortified Forest
    C语言中time函数获取系统时间
    回车符号与换行符号
    [转]NYOJ-511-移动小球
    C语言的inline
    C语言编译全过程
    linux下面安装配置mongoDB
    linux下面安装配置LAMP环境
    linux下面的解压缩文件的命令
    day23 正则,re模块
  • 原文地址:https://www.cnblogs.com/michealyang/p/14125135.html
Copyright © 2011-2022 走看看