删除 yem-base/yem-base-common/src/main/java/yem/base/common/utils/QRCodeToolUtil.java
This commit is contained in:
parent
916ba9c81c
commit
5b65962537
@ -1,52 +0,0 @@
|
||||
package yem.base.common.utils;
|
||||
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
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 com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
|
||||
/**
|
||||
* @BelongsProject: yem-cosmic
|
||||
* @BelongsPackage: yem.base.common.utils
|
||||
* @ClassName QRCodeToolUtil
|
||||
* @Author: LiuHB
|
||||
* @CreateTime: 2025-01-08 15:32
|
||||
*/
|
||||
public class QRCodeToolUtil {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String qrCodeText = "这里为二维码要展示内容文本";
|
||||
String filePath = "D:/1fileTest/qrcode1111.png";
|
||||
String fileType = "png";//文件类型
|
||||
int size = 250;//长宽
|
||||
createQRImage(qrCodeText, filePath, fileType, size);
|
||||
|
||||
}
|
||||
|
||||
private static void createQRImage(String qrCodeText, String filePath, String fileType, int size) {
|
||||
File qrFile = new File(filePath);
|
||||
try {
|
||||
Map<EncodeHintType, Object> hintMap = new HashMap<>();
|
||||
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
|
||||
hintMap.put(EncodeHintType.CHARACTER_SET, "utf-8");
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(qrCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
|
||||
MatrixToImageWriter.writeToPath(bitMatrix, fileType, qrFile.toPath());
|
||||
} catch (WriterException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user