From 2d5c3ba625332a480610480d5cadcef02636dabf Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Fri, 18 Mar 2022 18:21:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/commons/tools/utils/BarcodeUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java index dfdae4a097..1751ef4bc7 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/BarcodeUtils.java @@ -102,11 +102,11 @@ public class BarcodeUtils { Graphics2D g = outImage.createGraphics(); g.drawImage(image, 0, 0, imageW, imageH, null); g.setColor(QRCOLOR); - g.setFont(new Font("微软雅黑", Font.BOLD, FONTSIZE)); +// g.setFont(new Font("微软雅黑", Font.BOLD, FONTSIZE)); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setBackground(Color.white); // 获取文字数量 按照字节展示 - int size = pressText.getBytes("UTF-8").length; + int size = pressText.getBytes("GBK").length; // 获取一行最多能容纳多少文字 按照文字字节展示 int maxSize = (WIDTH / FONTSIZE - 2) * 2; if (size > maxSize) { @@ -121,7 +121,7 @@ public class BarcodeUtils { g.drawString(pressText, (WIDTH - (FONTSIZE * v)) / 2, startY); } } else { - g.drawString(pressText, (WIDTH - ((pressText.getBytes("UTF-8").length) / 2) * FONTSIZE) / 2, startY); + g.drawString(pressText, (WIDTH - ((pressText.getBytes("GBK").length) / 2) * FONTSIZE) / 2, startY); } g.dispose(); @@ -153,7 +153,7 @@ public class BarcodeUtils { private static String outStringByByte(String str, int len) throws IOException { - byte[] btf = str.getBytes("UTF-8"); + byte[] btf = str.getBytes("GBK"); int count = 0; for (int j = len - 1; j >= 0; j--) { @@ -165,9 +165,9 @@ public class BarcodeUtils { } if (count % 2 == 0) { - return new String(btf, 0, len, "UTF-8"); + return new String(btf, 0, len, "GBK"); } else { - return new String(btf, 0, len - 1, "UTF-8"); + return new String(btf, 0, len - 1, "GBK"); } }