LiuHB 二维码生成器
This commit is contained in:
parent
ceb644f750
commit
4b4e6a8c49
@ -2,15 +2,15 @@ Manifest-Version: 1.0
|
|||||||
Jar-Id:
|
Jar-Id:
|
||||||
Project-Name: yem-base-common
|
Project-Name: yem-base-common
|
||||||
Build-Tool: Gradle 7.6.3
|
Build-Tool: Gradle 7.6.3
|
||||||
Build-Date: 2024-12-12 18:59:17
|
Build-Date: 2024-12-24 11:20:33
|
||||||
Built-By: Kingdee Cosmic Developer Tools
|
Built-By: Kingdee Cosmic Developer Tools
|
||||||
Build-Num: 20241212185917122
|
Build-Num: 20241224112033348
|
||||||
App-Name:
|
App-Name:
|
||||||
Git-Branch:
|
Git-Branch: yem_rabbit_lhb
|
||||||
Cloud-Name:
|
Cloud-Name:
|
||||||
Group-Name: yem.cosmic
|
Group-Name: yem.cosmic
|
||||||
Bundle-Version: 1.0.0
|
Bundle-Version: 1.0.0
|
||||||
Git-Commit-Hash:
|
Git-Commit-Hash: ceb644f750beebd3189008d35096dff52aa0ccd9
|
||||||
Build-Image:
|
Build-Image:
|
||||||
Build-Jdk: 1.8.0_201
|
Build-Jdk: 1.8.0_201
|
||||||
|
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
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