From a2e287f9bfec6f64bcd1dce4155b0139d1474cb7 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 10 六月 2019 12:15:57 +0800
Subject: [PATCH] 设备消息,用户消息总未读消息修改

---
 fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java |  305 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 304 insertions(+), 1 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 69ca7ad..7ecbde2 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -22,12 +22,15 @@
 import java.math.BigDecimal;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 
 import javax.imageio.ImageIO;
 
+import org.yeshi.utils.DateLunarUtil;
 import org.yeshi.utils.HttpUtil;
+import org.yeshi.utils.entity.DateInfo;
 
 import com.yeshi.fanli.entity.bus.activity.RecommendActivityTaoBaoGoods;
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
@@ -1091,7 +1094,7 @@
 		return originalImage;
 	}
 
-	static BufferedImage roundImage(BufferedImage srcImage, int cornerRadius) { // 鍗婂緞
+	public static BufferedImage roundImage(BufferedImage srcImage, int cornerRadius) { // 鍗婂緞
 		int width = srcImage.getWidth();
 		int height = srcImage.getHeight();
 		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
@@ -1172,4 +1175,304 @@
 		return new int[] { width, height };
 	}
 
+	
+	
+	/**
+	 * 澶村儚鍔犵櫧搴曞浘 閭�璇峰ソ鍙嬪浘鐗�
+	 * @param urlInputStream
+	 * @param portraitInputStream
+	 * @param erCodeInputStream
+	 * @param targetPath
+	 * @param inviteCode
+	 * @throws IOException
+	 */
+	public static void inviteFriendImgWhite(InputStream urlInputStream, InputStream portraitInputStream,
+			InputStream erCodeInputStream, String targetPath,String inviteCode) throws IOException {
+		inviteFriendImgWhite(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230, inviteCode);
+	}
+	
+	
+	/**
+	 * 澶村儚鍔犵櫧搴曞浘 閭�璇峰ソ鍙嬪浘鐗�  -鑷畾涔変簩缁寸爜浣嶇疆
+	 * @param urlInputStream
+	 * @param portraitInputStream
+	 * @param erCodeInputStream
+	 * @param targetPath
+	 * @param inviteCode
+	 * @throws IOException
+	 */
+	public static void inviteFriendImgWhitecustom(InputStream urlInputStream, InputStream portraitInputStream,
+			InputStream erCodeInputStream, String targetPath, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException {
+		inviteFriendImgWhite(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, pX, pY, size, inviteCode);
+	}
+	
+	
+	/**
+	 * 閭�璇峰ソ鍙嬪浘鐗囧姞涓婂ご鍍忓姞涓婄櫧搴�
+	 */
+	public static void inviteFriendImgWhite(InputStream urlInputStream, InputStream portraitInputStream,
+			InputStream erCodeInputStream, String targetPath, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException {
+		
+		if (pX == null) {
+			pX = 260;
+		}
+		
+		if (pY == null) {
+			pY = 908;		
+		}
+				
+		if (size == null) {
+			size = 230;
+		}
+
+		
+		BufferedImage bgImage = ImageIO.read(urlInputStream);
+		final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
+				BufferedImage.TYPE_INT_RGB);
+		HashMap<Key, Object> mapH = new HashMap<Key, Object>();
+		mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 鎶楅敮榻柯狅紙鎶楅敮榻挎�诲紑鍏筹級聽聽
+		mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 鏂囧瓧鎶楅敮榻柯�
+
+		// 鐢� 鑳屾櫙鍥剧墖
+		final Graphics2D g2d = targetImg.createGraphics();
+		g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
+		g2d.setRenderingHints(mapH);
+		
+		// 鐢� 浜岀淮鐮�
+		BufferedImage qrCodeImage = ImageIO.read(erCodeInputStream);
+		qrCodeImage = ImageUtil.qrCodeImage(g2d, qrCodeImage, pX, pY, size, size);
+	
+		int portraitSize = size * 5 / 23;
+		int pPX = pX + size / 2 - portraitSize / 2;
+		int pPY = pY + size / 2 - portraitSize / 2;
+		
+		// 澶村儚鐧借壊杈规
+		g2d.fillRoundRect(pPX-4, pPY-4,portraitSize+8, portraitSize + 8, 5, 5);
+		g2d.setRenderingHints(mapH);
+		// 鐢� 澶村儚
+		BufferedImage portraitImg = ImageIO.read(portraitInputStream);
+		portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
+		portraitImg = ImageUtil.roundImage(portraitImg, 10);
+		g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
+
+		
+		// 鐢婚個璇风爜(閭�璇风爜鐨勫ぇ灏忎笌瀛椾綋鍥哄畾)
+		if (!StringUtil.isNullOrEmpty(inviteCode)) {
+			String st = "閭�璇风爜锛�" + inviteCode;
+			String os = System.getProperty("os.name");
+			String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
+			if (os.toLowerCase().startsWith("win")) {
+				fontBoldPath = "C:/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.getFontMetrics(boldFont);
+			g2d.setColor(new Color(0, 0, 0));
+			
+			int ax = pX - 30;
+			int ay = pY + size +  118;
+			
+			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();
+		out.close();
+	}
+	
+	
+	/**
+	 * 缁樺埗閭�璇烽棶鍊欏浘
+	 * @param bgPigInStream  鑳屾櫙鍥�
+	 * @param portraitInStream  鐢ㄦ埛澶村儚
+	 * @param erCodeInStream    浜岀淮鐮�
+	 * @param targetPath    璺緞
+	 * @param inviteCode    閭�璇风爜
+	 * @param content       鏂囧瓧鍐呭
+	 * @param date			鏄剧ず鏃ュ巻
+	 * @throws IOException
+	 */
+	public static void drawInviteToGreet(InputStream bgPigInStream, InputStream portraitInStream,
+			InputStream erCodeInStream, String targetPath, String inviteCode, String content, Date date)
+			throws IOException {
+		// 鑳屾櫙鍥剧墖
+		BufferedImage bgImage = ImageIO.read(bgPigInStream);
+		final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
+				BufferedImage.TYPE_INT_RGB);
+		
+		HashMap<Key, Object> mapH = new HashMap<Key, Object>();
+		mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 鎶楅敮榻柯狅紙鎶楅敮榻挎�诲紑鍏筹級聽聽
+		mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 鏂囧瓧鎶楅敮榻柯�
+
+		// 鐢� 鑳屾櫙鍥剧墖
+		final Graphics2D g2d = targetImg.createGraphics();
+		g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
+		g2d.setRenderingHints(mapH);
+		g2d.setBackground(Color.WHITE);
+		
+		// 鐢� 钂欏眰
+		BufferedImage mengCeng = ImageIO
+				.read(ImageUtil.class.getClassLoader().getResourceAsStream("image/invite/mc.png"));
+		g2d.drawImage(mengCeng, 0, bgImage.getHeight() / 2, bgImage.getWidth(), bgImage.getHeight() / 2, null);
+
+		int width = bgImage.getWidth();
+		int height = bgImage.getHeight();
+
+		int pX = width - 250;
+		int pY = height - 290; // 320
+		int size = 210; // 230
+		// 鐢� 浜岀淮鐮�
+		BufferedImage qrCodeImage = ImageIO.read(erCodeInStream);
+		qrCodeImage = qrCodeImage(g2d, qrCodeImage, pX, pY, size, size); // 浜岀淮鐮侀暱瀹�
+		// 230*230
+
+		// 鐢� 澶村儚
+		int portraitSize = size * 5 / 23;
+		int pPX = pX + size / 2 - portraitSize / 2;
+		int pPY = pY + size / 2 - portraitSize / 2;
+		
+		// 澶村儚鐧借壊杈规
+		g2d.fillRoundRect(pPX-4, pPY-4,portraitSize+8, portraitSize + 8, 5, 5);
+		g2d.setRenderingHints(mapH);
+		
+		BufferedImage portraitImg = ImageIO.read(portraitInStream);
+		portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
+		portraitImg = ImageUtil.roundImage(portraitImg, 10);
+		g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
+		
+
+		// 瀛椾綋鐧借壊
+		Color color = new Color(255, 255, 255);
+		String os = System.getProperty("os.name");
+		String fontBoldPath = "/usr/share/fonts/yahei.ttf";
+		if (os.toLowerCase().startsWith("win")) {
+			fontBoldPath = "C:/yahei.ttf";
+		}
+		
+
+		Font boldFont = null;
+		// 鐢婚個璇风爜(閭�璇风爜鐨勫ぇ灏忎笌瀛椾綋鍥哄畾)
+		if (!StringUtil.isNullOrEmpty(inviteCode)) {
+			String st = "閭�璇风爜锛�" + inviteCode;
+			try {
+				boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(32.0f);
+			} catch (FontFormatException e) {
+				e.printStackTrace();
+			}
+			g2d.setFont(boldFont);
+			g2d.setColor(new Color(255, 255, 255));
+
+			FontMetrics fm = g2d.getFontMetrics(boldFont);
+			int textLength = fm.stringWidth(st);
+
+			int ax = (width - textLength) - 30;
+			int ay = bgImage.getHeight() - 50 + boldFont.getSize() / 2 - 5;
+
+			g2d.setColor(new Color(255, 255, 255));
+			g2d.drawString(st, ax, ay);
+		}
+
+		// 宸﹁竟璺�
+		int padding_left = 30;
+
+		// 鏃ュ巻
+		try {
+			if (date == null) {
+				date = new Date();
+			}
+
+			boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
+			g2d.setFont(boldFont);
+			g2d.setColor(color);
+			g2d.setRenderingHints(mapH);
+
+			DateInfo dateInfo = DateLunarUtil.getDateInfo(date);
+			// 鍐滃巻
+			g2d.drawString(dateInfo.getLunar_month() + dateInfo.getLunar_day(), padding_left, height - 80);
+			// 澶╁共鍦版敮
+			g2d.drawString(dateInfo.getAgenary_month() + " " + dateInfo.getAgenary_day(), padding_left, height - 140);
+
+			// 褰撳墠鏃ユ湡
+			Font boldFontMax = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(100.0f);
+			g2d.setFont(boldFontMax);
+
+			if (dateInfo.getDay() < 10) {
+				g2d.drawString("0" + dateInfo.getDay().toString(), padding_left, height - 200);
+			} else {
+				g2d.drawString(dateInfo.getDay().toString(), padding_left, height - 200);
+			}
+
+			String theDate = "";
+			if (dateInfo.getMonth() < 10) {
+				theDate = "/0";
+			} else {
+				theDate = "/";
+			}
+			theDate += dateInfo.getMonth() + "/" + dateInfo.getYear() + " " + dateInfo.getWeekDay();
+			g2d.setFont(boldFont);
+			g2d.drawString(theDate, padding_left + boldFontMax.getSize() + 15, height - 200);
+
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+		if (!StringUtil.isNullOrEmpty(content)) {
+			// 鏂囧瓧鍐呭
+			try {
+				boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
+				g2d.setFont(boldFont);
+				g2d.setColor(color);
+				g2d.setRenderingHints(mapH);
+
+				int lineHeight = 70;
+				int lineTextLength = 19;
+
+				if (content.length() <= lineTextLength) {
+					g2d.drawString(content, padding_left, height - 350);
+				} else {
+					String text = "";
+					int mod = content.length() % lineTextLength;
+					if (mod == 0) {
+						text = content.substring(content.length() - lineTextLength, content.length());
+						content = content.substring(0, content.length() - lineTextLength);
+					} else {
+						text = content.substring(content.length() - mod, content.length());
+						content = content.substring(0, content.length() - mod);
+					}
+					g2d.drawString(text, padding_left, height - 350);
+
+					int i = 1;
+					while (true) {
+						if (content.length() <= 17) {
+							g2d.drawString(content, padding_left, height - 350 - lineHeight * i);
+							break;
+						} else {
+							text = content.substring(content.length() - lineTextLength, content.length());
+							content = content.substring(0, content.length() - lineTextLength);
+							g2d.drawString(text, padding_left, height - 350 - lineHeight * i);
+							i++;
+						}
+					}
+				}
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		}
+
+		OutputStream out = new FileOutputStream(new File(targetPath));
+		ImageIO.write(targetImg, "JPEG", out);
+		out.flush();
+		out.close();
+	}
+	
 }

--
Gitblit v1.8.0