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();
            }
        }
    }
  • 相关阅读:
    promise的终止调用方法:
    (五)浅谈测试用例
    (四)一个bug的生命周期
    (三)趣谈软件需求分析
    (二)软件测试分类
    (一) 软件测试实质
    【转载—“光荣之路”公众号】Bug预防体系(上千bug分析后总结的最佳实践)
    <MFC>FILE的操作
    <CAN>测试的原理
    <C++>消息循环
  • 原文地址:https://www.cnblogs.com/michealyang/p/14125135.html
Copyright © 2011-2022 走看看