From b6c37e4bc38db88a360d0f2c6099183f9bb75bdc Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期一, 22 四月 2019 14:31:59 +0800 Subject: [PATCH] 券推送插入 --- fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java | 119 +++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 74 insertions(+), 45 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 074b2da..69ca7ad 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java @@ -27,11 +27,12 @@ import javax.imageio.ImageIO; +import org.yeshi.utils.HttpUtil; + import com.yeshi.fanli.entity.bus.activity.RecommendActivityTaoBaoGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.util.taobao.TaoBaoUtil; -import org.yeshi.utils.HttpUtil; public class ImageUtil { @@ -445,7 +446,7 @@ font = font.deriveFont(50.0f); g2d.setFont(font); g2d.setColor(new Color(229, 0, 93)); -// g2d.drawString("杩斿埄鍒告彁閱掓偍", 312, 1118 + 40); + // g2d.drawString("杩斿埄鍒告彁閱掓偍", 312, 1118 + 40); g2d.setColor(new Color(102, 102, 102)); g2d.drawString("闀挎寜璇嗗埆浜岀淮鐮侀鍙栦紭鎯犲埜", 312, 1118 + 77); @@ -471,7 +472,7 @@ return null; } - + /** * 缁樺埗澶х殑鍟嗗搧鍔ㄦ�佸垎浜浘 * @@ -526,7 +527,7 @@ } g2d.setFont(font); try { -// g2d.setColor(new Color(153, 153, 153)); + // g2d.setColor(new Color(153, 153, 153)); // 鐢荤涓�寮� for (int i = 0; i < goodsList.size(); i++) { TaoBaoGoodsBrief goods = goodsList.get(i); @@ -555,14 +556,14 @@ g2d.drawString("楼", 70, 650); boldFont = boldFont.deriveFont(42.0f); g2d.setFont(boldFont); - g2d.drawString(couplePrice+"", 90, 650); + g2d.drawString(couplePrice + "", 90, 650); // 鐢诲師浠� g2d.setColor(new Color(102, 102, 102)); font = font.deriveFont(24.0f); g2d.setFont(font); - String zkPrice = new BigDecimal((couplePrice+"").replace("楼", "")).add(goods.getCouponAmount()) + String zkPrice = new BigDecimal((couplePrice + "").replace("楼", "")).add(goods.getCouponAmount()) .toString(); g2d.drawString("楼 " + zkPrice, 70, 650 + 33); @@ -574,12 +575,12 @@ String quanString = ""; BigDecimal withNoZera = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()); - + if (!withNoZera.toString().endsWith("0")) { - + // 鐢诲埜鍙充晶 - BufferedImage quanRight = ImageIO - .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_right.png")); + BufferedImage quanRight = ImageIO.read( + ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_right.png")); quanRight = zoomInImage(quanRight, 12, 60); g2d.setColor(new Color(241, 66, 66)); g2d.drawImage(quanRight, topX + 630 - quanRight.getWidth(), topY + 630 - quanRight.getHeight(), @@ -603,8 +604,8 @@ topY + 630 + 42 - quanRight.getHeight()); // 鐢诲埜宸︿晶 - BufferedImage quanLeft = ImageIO - .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_left.png")); + BufferedImage quanLeft = ImageIO.read( + ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_left.png")); quanLeft = zoomInImage(quanLeft, 12, 60); g2d.drawImage(quanLeft, topX + 630 - quanRight.getWidth() - textLength - quanLeft.getWidth(), topY + 630 - quanRight.getHeight(), null); @@ -646,12 +647,12 @@ String quanString = ""; BigDecimal withNoZera = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()); - + if (!withNoZera.toString().endsWith("0")) { - + // 鐢诲埜鍙充晶 - BufferedImage quanRight = ImageIO - .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_right.png")); + BufferedImage quanRight = ImageIO.read( + ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_right.png")); quanRight = zoomInImage(quanRight, 8, 40); g2d.setColor(new Color(241, 66, 66)); g2d.drawImage(quanRight, topX + 315 - quanRight.getWidth(), topY + 315 - quanRight.getHeight(), @@ -659,9 +660,9 @@ // 鐢诲埜鐨勫唴瀹� g2d.setColor(new Color(229, 0, 93)); - + quanString = " " + withNoZera + "鍏冨埜 "; - + font = font.deriveFont(24.0f); g2d.setFont(font); FontMetrics fm = g2d.getFontMetrics(font); @@ -677,13 +678,13 @@ topY + 315 + 28 - quanRight.getHeight()); // 鐢诲埜宸︿晶 - BufferedImage quanLeft = ImageIO - .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_left.png")); + BufferedImage quanLeft = ImageIO.read( + ImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_left.png")); quanLeft = zoomInImage(quanLeft, 8, 40); g2d.drawImage(quanLeft, topX + 315 - quanRight.getWidth() - textLength - quanLeft.getWidth(), topY + 315 - quanRight.getHeight(), null); } - + } } @@ -700,7 +701,11 @@ // 鐢诲ご鍍� if (portrait != null) { BufferedImage portraitImg = ImageIO.read(portrait); + // 鏀剧缉澶у皬 portraitImg = zoomInImage(portraitImg, 40, 40); + // 鍦嗚 + portraitImg = roundImage(portraitImg, 10); + g2d.drawImage(portraitImg, 70 + (qrcodeImage.getWidth() - portraitImg.getWidth()) / 2, 1092 + (qrcodeImage.getHeight() - portraitImg.getHeight()) / 2, null); } @@ -708,37 +713,28 @@ font = font.deriveFont(50.0f); g2d.setFont(font); g2d.setColor(new Color(229, 0, 93)); -// g2d.drawString("杩斿埄鍒告彁閱掓偍", 312, 1118 + 40); + // g2d.drawString("杩斿埄鍒告彁閱掓偍", 312, 1118 + 40); g2d.setColor(new Color(102, 102, 102)); - g2d.drawString("闀挎寜璇嗗埆浜岀淮鐮佸厤璐归鍒�", 312, 1142); - + g2d.drawString("闀挎寜璇嗗埆浜岀淮鐮佸厤璐归鍒�", 312, 1150); + g2d.setColor(new Color(102, 102, 102)); - g2d.drawString("鍏�", 1000, 1142); - - + g2d.drawString("鍏�", 1000, 1150); + g2d.setColor(new Color(229, 0, 93)); - g2d.drawString(goodsList.size()+"", 1055, 1142); - - + g2d.drawString(goodsList.size() + "", 1055, 1150); + g2d.setColor(new Color(102, 102, 102)); - g2d.drawString("涓晢鍝�", 1090, 1142); - + g2d.drawString("涓晢鍝�", 1090, 1150); + // 鎻愮ず璇� BufferedImage tips = ImageIO .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/share/tips1.png")); - tips = zoomInImage(tips,850, 65); - //g2d.setColor(new Color(255, 250, 250)); - g2d.drawImage(tips, 312,1180, null); - + tips = zoomInImage(tips, 850, 65); + g2d.drawImage(tips, 312, 1190, null); g2d.dispose(); - // OutputStream out = new ByteArrayOutputStream(); new - // FileOutputStream(new File(targetPath)); - // ImageIO.write(targetImg, "JPEG", out); - // out.flush(); - // out.close(); ByteArrayOutputStream aos = new ByteArrayOutputStream(); ImageIO.write(targetImg, "JPEG", aos); InputStream is = new ByteArrayInputStream(aos.toByteArray()); @@ -753,7 +749,6 @@ return null; } - // 鐢诲晢鍝佸垎浜浘 public static InputStream drawGoodsShareImgHCJ(InputStream qrcodeStream, InputStream portrait, @@ -996,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); } /** @@ -1012,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); @@ -1042,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