From 864a952fed0b9c4fce5ba91e9dd99ba7a8789742 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 18 四月 2019 09:40:29 +0800
Subject: [PATCH] 分享二维码增加邀请码

---
 fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
index 0aed515..69ca7ad 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -991,8 +991,8 @@
 
 	// 閭�璇峰ソ鍙嬪浘鐗�
 	public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
-			InputStream erCodeInputStream, String targetPath) throws IOException {
-		inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230);
+			InputStream erCodeInputStream, String targetPath,String inviteCode) throws IOException {
+		inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230, inviteCode);
 	}
 
 	/**
@@ -1007,11 +1007,14 @@
 	 *            -浜岀淮鐮佺殑绾靛潗鏍�
 	 * @param size
 	 *            -浜岀淮鐮佺殑灏哄
+	 * @param inviteCode
+	 *            -閭�璇风爜
 	 * @throws IOException
 	 */
 	// 閭�璇峰ソ鍙嬪浘鐗�
 	public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
-			InputStream erCodeInputStream, String targetPath, int pX, int pY, int size) throws IOException {
+			InputStream erCodeInputStream, String targetPath, int pX, int pY, int size, String inviteCode)
+			throws IOException {
 		BufferedImage bgImage = ImageIO.read(urlInputStream);
 		final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
 				BufferedImage.TYPE_INT_RGB);
@@ -1037,6 +1040,37 @@
 		int pPY = pY + size / 2 - portraitSize / 2;
 		portraitImg = ImageUtil.portraitImg(g2d, portraitImg, pPX, pPY, portraitSize, portraitSize);// 澶村儚闀垮
 
+		// 鐢婚個璇风爜(閭�璇风爜鐨勫ぇ灏忎笌瀛椾綋鍥哄畾)
+		if (!StringUtil.isNullOrEmpty(inviteCode)) {
+			String st = "閭�璇风爜锛�" + inviteCode;
+			int width = bgImage.getWidth();
+			String os = System.getProperty("os.name");
+			String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
+			if (os.toLowerCase().startsWith("win")) {
+				fontBoldPath = "D:/PingFang_Medium.ttf";
+			}
+
+			Font boldFont = null;
+			try {
+				boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
+			} catch (FontFormatException e) {
+				e.printStackTrace();
+			}
+
+			g2d.setFont(boldFont);
+			g2d.setColor(new Color(0, 0, 0));
+
+			FontMetrics fm = g2d.getFontMetrics(boldFont);
+			int textLength = fm.stringWidth(st);
+
+			int ax = (width - textLength) / 2;
+			int ay = bgImage.getHeight() - 92 + boldFont.getSize() / 2 - 5;
+
+			g2d.setColor(new Color(0, 0, 0));
+			g2d.drawString(st, ax, ay);
+
+		}
+
 		OutputStream out = new FileOutputStream(new File(targetPath));
 		ImageIO.write(targetImg, "JPEG", out);
 		out.flush();

--
Gitblit v1.8.0