From 88b54772dbcf5ecab1e2316e4e4626ac901b8908 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期二, 22 一月 2019 15:58:24 +0800 Subject: [PATCH] 邀请码添加返回状态 --- fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java | 156 +++++++++++++++++++++++++++++++--------------------- 1 files changed, 93 insertions(+), 63 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 402fb29..c080a66 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 { @@ -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); @@ -572,37 +573,43 @@ g2d.setStroke(new BasicStroke(2.0f)); g2d.drawLine(70 + 20, 674, 90 + 10 + textLength, 674); - // 鐢诲埜鍙充晶 - 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(), - null); + 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")); + quanRight = zoomInImage(quanRight, 12, 60); + g2d.setColor(new Color(241, 66, 66)); + g2d.drawImage(quanRight, topX + 630 - quanRight.getWidth(), topY + 630 - quanRight.getHeight(), + null); - // 鐢诲埜鐨勫唴瀹� - g2d.setColor(new Color(229, 0, 93)); + // 鐢诲埜鐨勫唴瀹� + g2d.setColor(new Color(229, 0, 93)); - String quanString = " " + MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()) + "鍏冨埜 "; + quanString = " " + withNoZera + "鍏冨埜 "; - font = font.deriveFont(36.0f); - g2d.setFont(font); - fm = g2d.getFontMetrics(font); - textLength = fm.stringWidth(quanString); + font = font.deriveFont(36.0f); + g2d.setFont(font); + fm = g2d.getFontMetrics(font); + textLength = fm.stringWidth(quanString); - g2d.fillRect(topX + 630 - quanRight.getWidth() - textLength, topY + 630 - quanRight.getHeight(), - textLength, quanRight.getHeight()); + g2d.fillRect(topX + 630 - quanRight.getWidth() - textLength, topY + 630 - quanRight.getHeight(), + textLength, quanRight.getHeight()); - g2d.setColor(Color.WHITE); - g2d.drawString(quanString, topX + 630 - quanRight.getWidth() - textLength, - topY + 630 + 42 - quanRight.getHeight()); + g2d.setColor(Color.WHITE); + g2d.drawString(quanString, topX + 630 - quanRight.getWidth() - textLength, + topY + 630 + 42 - quanRight.getHeight()); - // 鐢诲埜宸︿晶 - 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); + // 鐢诲埜宸︿晶 + 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); + } } else { // 璁$畻宸︿笂瑙掑潗鏍� @@ -638,39 +645,46 @@ // 鐢诲埜 - // 鐢诲埜鍙充晶 - 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(), - null); + 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")); + quanRight = zoomInImage(quanRight, 8, 40); + g2d.setColor(new Color(241, 66, 66)); + g2d.drawImage(quanRight, topX + 315 - quanRight.getWidth(), topY + 315 - quanRight.getHeight(), + null); - // 鐢诲埜鐨勫唴瀹� - g2d.setColor(new Color(229, 0, 93)); + // 鐢诲埜鐨勫唴瀹� + g2d.setColor(new Color(229, 0, 93)); + + quanString = " " + withNoZera + "鍏冨埜 "; + + font = font.deriveFont(24.0f); + g2d.setFont(font); + FontMetrics fm = g2d.getFontMetrics(font); + int textLength = fm.stringWidth(quanString); - String quanString = " " + MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()) + "鍏冨埜 "; + g2d.fillRect(topX + 315 - quanRight.getWidth() - textLength, topY + 315 - quanRight.getHeight(), + textLength, quanRight.getHeight()); - font = font.deriveFont(24.0f); - g2d.setFont(font); - FontMetrics fm = g2d.getFontMetrics(font); - int textLength = fm.stringWidth(quanString); + g2d.setColor(Color.WHITE); - g2d.fillRect(topX + 315 - quanRight.getWidth() - textLength, topY + 315 - quanRight.getHeight(), - textLength, quanRight.getHeight()); + g2d.setFont(font); + g2d.drawString(quanString, topX + 315 - quanRight.getWidth() - textLength, + topY + 315 + 28 - quanRight.getHeight()); - g2d.setColor(Color.WHITE); - - g2d.setFont(font); - g2d.drawString(quanString, topX + 315 - quanRight.getWidth() - textLength, - topY + 315 + 28 - quanRight.getHeight()); - - // 鐢诲埜宸︿晶 - 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); + // 鐢诲埜宸︿晶 + 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); + } + } } @@ -687,7 +701,11 @@ // 鐢诲ご鍍� if (portrait != null) { BufferedImage portraitImg = ImageIO.read(portrait); - portraitImg = zoomInImage(portraitImg, 40, 40); + // 鏀剧缉澶у皬 + 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); } @@ -698,15 +716,27 @@ // g2d.drawString("杩斿埄鍒告彁閱掓偍", 312, 1118 + 40); g2d.setColor(new Color(102, 102, 102)); - g2d.drawString("闀挎寜璇嗗埆浜岀淮鐮侀鍙栦紭鎯犲埜", 312, 1118 + 77); + g2d.drawString("闀挎寜璇嗗埆浜岀淮鐮佸厤璐归鍒�", 312, 1150); + + g2d.setColor(new Color(102, 102, 102)); + g2d.drawString("鍏�", 1000, 1150); + + + g2d.setColor(new Color(229, 0, 93)); + g2d.drawString(goodsList.size()+"", 1055, 1150); + + + g2d.setColor(new Color(102, 102, 102)); + g2d.drawString("涓晢鍝�", 1090, 1150); + + // 鎻愮ず璇� + BufferedImage tips = ImageIO + .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/share/tips1.png")); + 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()); @@ -1044,7 +1074,7 @@ gs.dispose(); return image; } - + public static int saveToImgByInputStream(InputStream inputStream, String imgPath, String imgName) { int stateInt = 1; try { -- Gitblit v1.8.0