From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java |  288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 288 insertions(+), 0 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 aed7789..ebbcd09 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -2484,4 +2484,292 @@
 		return null;
 	}
 
+	public static InputStream drawActivityShareImg(InputStream banner, float bannerRate, String title, String desc,
+			InputStream erCode) {
+		// 璁$畻楂樺害
+
+		int width = 750;
+		int height = 116;
+		int bannerWidth = 640;
+		int bannerHeight = (int) (bannerWidth / bannerRate);
+		height += bannerHeight;
+		height += 524;
+
+		try {
+			final BufferedImage targetImg = new BufferedImage(width, height, 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 = (Graphics2D) targetImg.getGraphics();
+			g2d.setRenderingHints(mapH);
+			g2d.setColor(Color.decode("#FF6940"));
+			g2d.fillRect(0, 0, width, height);
+
+			// 鐢籰ogo
+			g2d.drawImage(zoomInImage(
+					ImageIO.read(ImageUtil.class.getClassLoader().getResource("image/activityShare/icon_logo.png")), 59,
+					59), 346, 17, null);
+			// 鐢籦anner鑳屾櫙
+
+			g2d.setColor(Color.decode("#FFFFFF"));
+			g2d.fillRect(30, 94, 692, bannerHeight + 22);
+
+			// 鐢籦anner
+			g2d.drawImage(roundImage( zoomInImage(ImageIO.read(banner), bannerWidth, bannerHeight),20), 55, 116, null);
+
+			// 鐢讳簩缁寸爜鑳屾櫙
+			g2d.drawImage(
+					ImageIO.read(
+							ImageUtil.class.getClassLoader().getResource("image/activityShare/qrcode_content_bg.png")),
+					27, bannerHeight + 116, null);
+			// 鐢讳簩缁寸爜
+			g2d.drawImage(zoomInImage(ImageIO.read(erCode), 230, 230), 260, 116 + bannerHeight + 171, null);
+
+			// 鐢绘枃瀛�
+			g2d.setColor(Color.decode("#F03143"));
+			String fontBoldPath = "/usr/share/fonts/yahei_bold.ttf";
+			String os = System.getProperty("os.name");
+			if (os.toLowerCase().startsWith("win")) {
+				fontBoldPath = "C:/Users/Administrator/Desktop/fonts/yahei_bold.ttf";
+			}
+
+			String fontPath = "/usr/share/fonts/yahei.ttf";
+			if (os.toLowerCase().startsWith("win")) {
+				fontPath = "C:/Users/Administrator/Desktop/fonts/yahei.ttf";
+			}
+
+			Font boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(48.0f);
+			g2d.setFont(boldFont);
+			FontMetrics fm = g2d.getFontMetrics(boldFont);
+			int textLength = fm.stringWidth(title);
+
+			g2d.drawString(title, (width - textLength) / 2, 116 + bannerHeight + 50 + 45);
+
+			textLength = fm.stringWidth(desc);
+
+			g2d.drawString(desc, (width - textLength) / 2, 116 + bannerHeight + 50 + 50 + 45);
+
+			Font font = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(24.0f);
+			g2d.setFont(font);
+			g2d.setColor(Color.decode("#666666"));
+			fm = g2d.getFontMetrics(font);
+			textLength = fm.stringWidth("闀挎寜璇嗗埆浜岀淮鐮� 鏌ョ湅璇︽儏");
+
+			g2d.drawString("闀挎寜璇嗗埆浜岀淮鐮� 鏌ョ湅璇︽儏", (width - textLength) / 2, 116 + bannerHeight + 428+10);
+
+			g2d.dispose();
+
+			ByteArrayOutputStream aos = new ByteArrayOutputStream();
+			ImageIO.write(targetImg, "JPEG", aos);
+			return new ByteArrayInputStream(aos.toByteArray());
+		} catch (Exception e) {
+			e.printStackTrace();
+			try {
+				LogHelper.errorDetailInfo(e);
+			} catch (Exception e1) {
+				e1.printStackTrace();
+			}
+		}
+		return null;
+	}
+	
+	
+	
+	/**
+	 * 瀹夊崜-鏀粯瀹濈敾鍥�
+	 * @param money
+	 * @param orderNo
+	 * @param time
+	 * @param targetPath
+	 * @return
+	 * @throws IOException
+	 */
+	public static InputStream drawAlipayAndroid(BigDecimal money, String orderNo, String time) throws IOException {
+		String bgpic = "image/alipay/android.png";
+		BufferedImage bgImage = ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(bgpic));
+		
+		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.setRenderingHints(mapH);
+		g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
+		g2d.setBackground(Color.BLACK);
+		
+		// 瀛椾綋
+		String os = System.getProperty("os.name");
+		String fontRob0to = "/usr/share/fonts/ROBOTO-REGULAR.TTF";
+		String fontBahnschrift = "/usr/share/fonts/BAHNSCHRIFT.TTF";
+		if (os.toLowerCase().startsWith("win")) {
+			fontRob0to = "D:/ROBOTO-REGULAR.TTF";
+			fontBahnschrift = "D:/BAHNSCHRIFT.TTF";
+		}
+		
+		// 瀛椾綋澶у皬
+		Font font40 = null;
+		Font font42 = null;
+		Font font86 = null;
+		try {
+			font40 = Font.createFont(Font.PLAIN, new File(fontRob0to)).deriveFont(40.00f);
+			font42 = Font.createFont(Font.PLAIN, new File(fontBahnschrift)).deriveFont(42.00f);
+			font86 = Font.createFont(Font.PLAIN, new File(fontRob0to)).deriveFont(86.68f);
+		} catch (FontFormatException e) {
+			e.printStackTrace();
+		}
+		
+		
+		/*  鏃堕棿淇℃伅   */
+		g2d.setFont(font42);
+		g2d.setColor(new Color(247, 247, 247));
+		g2d.drawString(TimeUtil.formatHHMM_12H(new Date()), 134, 67);
+		
+		
+		/*  璧勯噾淇℃伅   */
+		String moneyInfo = "+" + money.setScale(2);
+		// 璁$畻闀垮害
+		FontMetrics fm = g2d.getFontMetrics(font86);
+		int textLength = fm.stringWidth(moneyInfo);
+		// 灞呬腑浣嶇疆
+		int x_money =  (bgImage.getWidth() - textLength) / 2 ;
+		// 鐢婚噾棰�
+		g2d.setFont(font86);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(moneyInfo, x_money, 420);
+
+		
+		/*  鍒涘缓鏃堕棿淇℃伅   */
+		FontMetrics fm2 = g2d.getFontMetrics(font40);
+		int l_time = fm2.stringWidth(time);
+		int x_time =  bgImage.getWidth() - l_time -41  ;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(time, x_time, 972);
+
+		/*  鍒涘缓鏃堕棿淇℃伅   */
+		int l_order = fm2.stringWidth(orderNo);
+		int x_order =  bgImage.getWidth() - l_order -41  ;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(orderNo, x_order, 1072);
+		g2d.dispose();
+
+		ByteArrayOutputStream aos = new ByteArrayOutputStream();
+		ImageIO.write(targetImg, "png", aos);
+		
+		return new ByteArrayInputStream(aos.toByteArray());
+	}
+
+	
+	
+	/**
+	 * IOS 鏀粯瀹濈敾鍥�
+	 * @param money
+	 * @param orderNo
+	 * @param time
+	 * @param targetPath
+	 * @return
+	 * @throws IOException
+	 */
+	public static InputStream drawAlipayIOS(BigDecimal money, String orderNo, String time)
+			throws IOException {
+		String bgpic = "image/alipay/ios.png";
+		BufferedImage bgImage = ImageIO.read(ImageUtil.class.getClassLoader().getResourceAsStream(bgpic));
+
+		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.setRenderingHints(mapH);
+		g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
+		g2d.setBackground(Color.BLACK);
+
+		// 瀛椾綋
+		String os = System.getProperty("os.name");
+		String fontHeiTi = "/usr/share/fonts/AdobeHeiTiStd.otf";
+		String fontSquare = "/usr/share/fonts/SquareHeitiStd.TTF";
+		if (os.toLowerCase().startsWith("win")) {
+			fontHeiTi = "D:/AdobeHeiTiStd.otf";
+			fontSquare = "D:/SquareHeitiStd.TTF";
+		}
+		
+		// 瀛椾綋澶у皬
+		Font font40 = null;
+		Font font44 = null;
+		Font font92 = null;
+		try {
+			font44 = Font.createFont(Font.PLAIN, new File(fontHeiTi)).deriveFont(44.18f);
+			font40 = Font.createFont(Font.PLAIN, new File(fontSquare)).deriveFont(40.00f);
+			font92 = Font.createFont(Font.PLAIN, new File(fontSquare)).deriveFont(92.03f);
+		} catch (FontFormatException e) {
+			e.printStackTrace();
+		}
+		/* 鏃堕棿淇℃伅 */
+		g2d.setFont(font44);
+		g2d.setColor(new Color(16, 16, 16));
+		MyDrawString(TimeUtil.formatHHMM_12H(new Date()), 82, 82, font44, g2d);
+ 
+	        
+		/* 璧勯噾淇℃伅 */
+		String moneyInfo = "+" + money.setScale(2);
+		// 璁$畻闀垮害
+		FontMetrics fm = g2d.getFontMetrics(font92);
+		int textLength = fm.stringWidth(moneyInfo);
+		// 灞呬腑浣嶇疆
+		int x_money = (bgImage.getWidth() - textLength) / 2;
+		// 鐢婚噾棰�
+		g2d.setFont(font92);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(moneyInfo, x_money, 480);
+
+		/* 鍒涘缓鏃堕棿淇℃伅 */
+		FontMetrics fm2 = g2d.getFontMetrics(font40);
+		int l_time = fm2.stringWidth(time);
+		int x_time = bgImage.getWidth() - l_time - 41;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(time, x_time, 1052);
+		
+		/* 鍒涘缓鏃堕棿淇℃伅 */
+		int l_order = fm2.stringWidth(orderNo);
+		int x_order = bgImage.getWidth() - l_order - 41;
+		g2d.setFont(font40);
+		g2d.setColor(new Color(51, 51, 51));
+		g2d.drawString(orderNo, x_order, 1160);
+
+		g2d.dispose();
+
+		ByteArrayOutputStream aos = new ByteArrayOutputStream();
+		ImageIO.write(targetImg, "png", aos);
+		return new ByteArrayInputStream(aos.toByteArray());
+	}
+
+	public static void MyDrawString(String str,int x,int y, Font font40, Graphics2D g2d){
+		int i = 0;
+		int x_next = x;
+		String tempStr= null;
+		while(str.length()>0)
+		{
+			tempStr=str.substring(0, 1);
+			str=str.substring(1, str.length());
+			g2d.drawString(tempStr, x_next, y);
+			
+			if (i == 1) {
+				x_next += 3 +  22;
+			} else if (i == 2) {
+				x_next += 10;
+			} else {
+				x_next += 0 + 22;
+			}
+			i++;
+		}
+	}
+
 }

--
Gitblit v1.8.0