java生成二维码输出到并前端
直接以图片形式返回给前端
public class QrCodeUtil {
private static final int BLACK = -16777216;
private static final int WHITE = -1;
public QrCodeUtil() {
}
public static BitMatrix createQrCode(String path) {
try {
Map<EncodeHintType, String> hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = (new MultiFormatWriter()).encode(path, BarcodeFormat.QR_CODE, 400, 400, hints);
return bitMatrix;
} catch (Exception var3) {
var3.printStackTrace();
return null;
}
}
static void writeToFile(BitMatrix matrix, String format, File file) throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, file)) {
throw new IOException("Could not write an image of format " + format