您当前的位置: 首页 >  Java

彭世瑜

暂无认证

  • 0浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Java:com.google.zxing:javase生成二维码

彭世瑜 发布时间:2020-12-25 10:02:33 ,浏览量:0

依赖



    com.google.zxing
    javase
    3.3.0

代码示例

package com.demo.qrcode;


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 main(String[] args) throws WriterException, IOException {
        // 设置参数
        String text = "Hello World";
        int width = 350;
        int height = 350;

        Path path = FileSystems.getDefault().getPath("demo.png");

        // 生成二维码
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);

        MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);


    }
}

在这里插入图片描述

参考 几行代码,轻松带你实现Java生成二维码功能!

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.2514s