package com.thhy.general.utils; 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 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; } }