From 8853292babb2ad94de4a3207966f1e83b767cd2d Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Sun, 17 Sep 2023 16:38:34 +0800
Subject: [PATCH] 新增流程节点进程查询接口
---
src/main/java/org/springblade/common/utils/QRCodeUtil.java | 65 +++++++++++++++++++++++++++++++-
1 files changed, 62 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/springblade/common/utils/QRCodeUtil.java b/src/main/java/org/springblade/common/utils/QRCodeUtil.java
index f7cdd3a..17e951f 100644
--- a/src/main/java/org/springblade/common/utils/QRCodeUtil.java
+++ b/src/main/java/org/springblade/common/utils/QRCodeUtil.java
@@ -23,6 +23,8 @@
import java.net.URL;
import java.util.HashMap;
+import static com.google.zxing.client.j2se.MatrixToImageConfig.BLACK;
+import static com.google.zxing.client.j2se.MatrixToImageConfig.WHITE;
import static org.bouncycastle.asn1.x500.style.RFC4519Style.cn;
/**
@@ -221,12 +223,69 @@
*/
public static byte[] getQRCodeImage(String text, int width, int height) throws WriterException, IOException {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
- BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
+
+ HashMap<EncodeHintType, Object> hints = new HashMap<>();
+ hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
+
+ BitMatrix bitMatrix =qrCodeWriter.encode(text,BarcodeFormat.QR_CODE, width, height,hints);
+ //删除白边
+// BufferedImage bufferedImage = deleteWhite(bitMatrix);
+
+ //BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "JPG", pngOutputStream);
- byte[] pngData = pngOutputStream.toByteArray();
- return pngData;
+ //返回
+ return pngOutputStream.toByteArray();
}
+ /**
+ * 去白边的话,调用这个方法
+ * @param matrix
+ * @return
+ */
+ private static BufferedImage deleteWhite(BitMatrix matrix) {
+ int[] rec = matrix.getEnclosingRectangle();
+ int resWidth = rec[2] + 1;
+ int resHeight = rec[3] + 1;
+
+ BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
+ resMatrix.clear();
+ for (int i = 0; i < resWidth; i++) {
+ for (int j = 0; j < resHeight; j++) {
+ if (matrix.get(i + rec[0], j + rec[1]))
+ resMatrix.set(i, j);
+ }
+ }
+
+ int width = resMatrix.getWidth();
+ int height = resMatrix.getHeight();
+ BufferedImage image = new BufferedImage(width, height,
+ BufferedImage.TYPE_INT_RGB);
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ image.setRGB(x, y, resMatrix.get(x, y) ? BLACK
+ : WHITE);
+ }
+ }
+ return image;
+ }
+
+
+// private static BitMatrix deleteWhite(BitMatrix matrix) {
+// int[] rec = matrix.getEnclosingRectangle();
+// int resWidth = rec[2] + 1;
+// int resHeight = rec[3] + 1;
+//
+// BitMatrix resMatrix = new BitMatrix(resWidth, resHeight);
+// resMatrix.clear();
+// for (int i = 0; i < resWidth; i++) {
+// for (int j = 0; j < resHeight; j++) {
+// if (matrix.get(i + rec[0], j + rec[1]))
+// resMatrix.set(i, j);
+// }
+// }
+// return resMatrix;
+// }
+
}
--
Gitblit v1.9.3