邱宇豪
2023-11-01 9100d3fa53c50ba5c5ca3972724a9f8ad905eea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.thhy.materials.modules.biz.rebarprint.controller;
 
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
 
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
 
public class ImageUtils {
    public static BufferedImage createQr(String content){
        Map<EncodeHintType, Object> hints = new HashMap();// 二维码参数
        hints.put(EncodeHintType.MARGIN, 0);
        //content = prefix+"/checkQr/checkQr?qrcontent="+content;
        BitMatrix bitMatrix = null;
        try {
            bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 500, 500, hints);
        } catch (WriterException e) {
            throw new RuntimeException(e);
        }
        BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
        return bufferedImage;
    }
}