From 1cba2635de31d32dbe629304c1e5a4cc1ebda529 Mon Sep 17 00:00:00 2001 From: ZQN <364596817@qq.com> Date: 星期四, 15 八月 2024 09:53:34 +0800 Subject: [PATCH] 企业二维码样式修改 --- project-common/src/main/java/com/project/common/utils/qrcode/QRCodeUtil.java | 38 +++++++++++++++++++++----------------- 1 files changed, 21 insertions(+), 17 deletions(-) diff --git a/project-common/src/main/java/com/project/common/utils/qrcode/QRCodeUtil.java b/project-common/src/main/java/com/project/common/utils/qrcode/QRCodeUtil.java index b34ffe2..cd4b4aa 100644 --- a/project-common/src/main/java/com/project/common/utils/qrcode/QRCodeUtil.java +++ b/project-common/src/main/java/com/project/common/utils/qrcode/QRCodeUtil.java @@ -143,11 +143,11 @@ //浜岀淮鐮佸浘涓婂甫瀛� public static void contextLoads2(String content, String name, String filePathStr) { - int qrCodeWidth = 700; - int qrCodeHeight = 700; - int textPadding = 5; // 鏂囨湰涓庝簩缁寸爜涔嬮棿鐨勯棿璺� - int textSize = 30; // 鏂囨湰瀛椾綋澶у皬 - int totalHeight = qrCodeHeight + 300; + int qrCodeWidth = 350; + int qrCodeHeight = 350; + int textPadding = 2; // 鏂囨湰涓庝簩缁寸爜涔嬮棿鐨勯棿璺� + int textSize = 10; // 鏂囨湰瀛椾綋澶у皬 + int totalHeight = 380; try { // 鐢熸垚浜岀淮鐮佺殑BitMatrix @@ -158,26 +158,30 @@ // 鍒涘缓涓�涓柊鐨凚ufferedImage鏉ュ绾充簩缁寸爜鍜屾枃鏈� BufferedImage combinedImage = new BufferedImage( - qrCodeWidth, 900, BufferedImage.TYPE_INT_RGB); + qrCodeWidth, totalHeight, BufferedImage.TYPE_INT_RGB); // 缁樺埗浜岀淮鐮佸埌鏂扮殑BufferedImage涓� Graphics2D g2d = combinedImage.createGraphics(); g2d.setColor(Color.WHITE); - g2d.fillRect(0, 0, qrCodeWidth, 900); - g2d.drawImage(qrCodeImage, 0, 0, null); + g2d.fillRect(0, 0, qrCodeWidth, totalHeight); + g2d.drawImage(qrCodeImage, -5, -10,360,360, null); - // 璁剧疆鏂囨湰鏍峰紡 - Font font = new Font("BLACK", Font.PLAIN, textSize); - g2d.setFont(font); - g2d.setColor(Color.BLACK); // 鏂囨湰棰滆壊 + // 缁樺埗鏂囨湰鍒板浘鐗囦笅鏂� - FontMetrics metrics = g2d.getFontMetrics(); + Font font = new Font("Black", Font.BOLD, 20); + FontMetrics metrics = g2d.getFontMetrics(font); int textX = (qrCodeWidth - metrics.stringWidth("娌堜笜鎯犱紒鎵ф硶")) / 2; - int textX1 = (qrCodeWidth - metrics.stringWidth(name)) / 2; - int textY = qrCodeHeight + textPadding; - g2d.drawString("娌堜笜鎯犱紒鎵ф硶", textX, textY); - g2d.drawString(name, textX1, textY+50); + // 璁剧疆鏂囨湰鏍峰紡 + g2d.setFont(font); + g2d.setColor(Color.BLACK); // 鏂囨湰棰滆壊 + g2d.drawString("娌堜笜鎯犱紒鎵ф硶", textX, 330); + Font font1 = new Font("Serif", Font.PLAIN, 15); + FontMetrics metrics1 = g2d.getFontMetrics(font1); + int textX1 = (360 - metrics1.stringWidth(name)) / 2; + g2d.setFont(font1); + g2d.setColor(Color.BLACK); // 鏂囨湰棰滆壊 + g2d.drawString(name, textX1, 355); g2d.dispose(); -- Gitblit v1.9.1