当前位置:网站首页>How to generate QR code

How to generate QR code

2022-06-21 09:05:00 No repair at night

public class QRCodeUtils {
    public static void createQRCode(String content){
        boolean[][]bs = getBooleansByTool(content);
        int width = 400;
        int height = 400;
        BufferedImage bufferedImage = new BufferedImage(width,height,1);
        Graphics2D gg = bufferedImage.createGraphics();
        gg.setBackground(Color.white);
        gg.fillRect(0,0,width,height);
        gg.setColor(Color.black);
        int lon = 3;
        for(int i=0;i<bs.length;i++){
            for(int j=0;j<bs.length;j++){
                if(bs[i][j]){
                    gg.fillRect(i*lon,j*lon,lon,lon);
                }
            }
        }
        String path="####";
        try {
            ImageIO.write(bufferedImage,"jpg",new File(path));
        } catch (
                IOException e) {
            e.printStackTrace();
        }
        System.out.println(" success ");

    }
    public static boolean [][] getBooleansByTool(String content){
        boolean [][] bs = null;
        Qrcode qrcode = new Qrcode();
        qrcode.setQrcodeEncodeMode('B');
        qrcode.setQrcodeErrorCorrect('M');
        qrcode.setQrcodeVersion(20);
        try {
            bs=qrcode.calQrcode(content.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return bs;
    }
}

path Just fill in your own path with the contents of , Concrete jar Package on my home page , You need to take it yourself QRCode rely on

原网站

版权声明
本文为[No repair at night]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221449345207.html