| | |
| | | * @param goods |
| | | * @return |
| | | */ |
| | | public static InputStream drawGoodsPoster(InputStream qrcode, InputStream portraitStream, String inviteCode, GoodsDetailVO goods) { |
| | | public static InputStream drawGoodsPoster(InputStream qrcode, InputStream portraitStream, String inviteCode, |
| | | String mainPic, GoodsDetailVO goods) { |
| | | try { |
| | | String fontPath = "/usr/share/fonts/PingFang_Medium.ttf"; |
| | | String os = System.getProperty("os.name"); |
| | |
| | | Font boldFont36 = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f); |
| | | |
| | | int px = 640; // 图片宽度 |
| | | int py = 1154; // 图片高度 |
| | | // int py = 1154; // 图片高度 显示邀请码 |
| | | int py = 1060; // 图片高度 |
| | | final BufferedImage targetImg = new BufferedImage(px, py, BufferedImage.TYPE_INT_RGB); |
| | | HashMap<Key, Object> mapH = new HashMap<Key, Object>(); |
| | | mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 抗锯齿 (抗锯齿总开关) |
| | |
| | | int spacing = 20; // 右边距 |
| | | |
| | | // 1、画商品主图 |
| | | InputStream picStream = HttpUtil.getAsInputStream(goods.getPicUrl().replace("https://", "http://")); |
| | | InputStream picStream = HttpUtil.getAsInputStream(mainPic); |
| | | // InputStream picStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/test_pic1.jpg"); |
| | | g2d.drawImage(ImageIO.read(picStream), 0, 0, x, y, null); |
| | | |
| | |
| | | g2d.drawString(title.substring(0, length2), spacing, y + 45 + row * 36); |
| | | } |
| | | |
| | | |
| | | int baoYouLength = spacing; |
| | | if (!goods.isHasCoupon()) { |
| | | // 无券 |
| | | g2d.setColor(new Color(229, 0, 92)); |
| | |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | g2d.drawRoundRect(spacing + 42, y + 140, textLength + 20, 39, 10, 10); |
| | | g2d.drawString(quanAmount, spacing + 55, y + 170); |
| | | |
| | | baoYouLength =spacing + 42 + textLength + 20 + 20; |
| | | } |
| | | |
| | | // 自营 、包邮 |
| | | InputStream ziying = null; |
| | | if (goods.getShopType() == 21) { |
| | | InputStream ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png"); |
| | | g2d.drawImage(ImageIO.read(ziying), spacing + 180, y + 150, 60, 30, null); |
| | | ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png"); |
| | | g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null); |
| | | } else if (goods.isBaoyou()) { |
| | | InputStream ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png"); |
| | | g2d.drawImage(ImageIO.read(ziying), spacing + 180, y + 150, 60, 30, null); |
| | | ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png"); |
| | | g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null); |
| | | } |
| | | |
| | | |
| | | // 销量 |
| | | String sale = null; |
| | |
| | | int textLength = fm.stringWidth(sale); |
| | | g2d.setFont(font24); |
| | | g2d.setColor(new Color(153, 153, 153)); |
| | | g2d.drawString(sale, spacing + 580 - textLength, y + 125); |
| | | g2d.drawString(sale, spacing + 605 - textLength, y + 125); |
| | | |
| | | |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | g2d.setColor(new Color(255,222, 235)); |
| | | g2d.fillRoundRect(spacing, y + 200, 385, 203, 10, 10); |
| | | // 下单提示 |
| | | InputStream downTip = null; |
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { |
| | | downTip = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/down_tip_tb.png"); |
| | | } else { |
| | | downTip = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/down_tip_jd_pdd.png"); |
| | | } |
| | | g2d.drawImage(ImageIO.read(downTip), spacing, y + 200, 382, 203, null); |
| | | |
| | | Font font22 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(22.0f); |
| | | g2d.setFont(font22); |
| | | g2d.setColor(new Color(229,0, 92)); |
| | | g2d.drawString("如何下单?", spacing + 6, y + 245); |
| | | g2d.drawString("1.长按识别本图", spacing + 6, y + 290); |
| | | g2d.drawString("2.点击页面右上角[ ... ],选择[复制链接]", spacing + 6, y + 330); |
| | | g2d.drawString("3.打开"+source+"App,领券下单", spacing + 6, y + 370); |
| | | |
| | | // 二维码图框 |
| | | InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/qr_code_frame01.png"); |
| | |
| | | |
| | | // 画二维码 |
| | | int codeSize = 170; |
| | | int pX = spacing + 420; |
| | | int pY = y + 215; |
| | | int pX = spacing + 422; |
| | | int pY = y + 217; |
| | | g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null); |
| | | |
| | | int portraitSize = 200 * 5 / 23; |
| | |
| | | g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null); |
| | | |
| | | |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | g2d.setColor(new Color(255,231, 224)); |
| | | g2d.fillRoundRect(spacing, y + 420, 607, 79, 10, 10); |
| | | |
| | | InputStream banliStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/banlikuaisheng.png"); |
| | | g2d.drawImage(ImageIO.read(banliStream), spacing + 20, y + 440, 170, 38, null); |
| | | |
| | | inviteCode = "邀请码:" + inviteCode; |
| | | Font font26d28 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.28f); |
| | | FontMetrics fmcode = g2d.getFontMetrics(font26d28); |
| | | int codeLength = fmcode.stringWidth(inviteCode); |
| | | // 邀请码背景 |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | g2d.setColor(new Color(229,71, 27)); |
| | | g2d.fillRoundRect(spacing + (600 - (int)(codeLength * 1.1)), y + 440, 10 + codeLength, 37, 10, 10); |
| | | // 邀请码文字 |
| | | g2d.setFont(font26d28); |
| | | g2d.setColor(new Color(255, 255, 255)); |
| | | g2d.drawString(inviteCode, spacing + (600 - (int)(codeLength * 1.1) + 5), y + 468); |
| | | // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | // g2d.setColor(new Color(255,231, 224)); |
| | | // g2d.fillRoundRect(spacing, y + 420, 607, 79, 10, 10); |
| | | // |
| | | // InputStream banliStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/banlikuaisheng.png"); |
| | | // g2d.drawImage(ImageIO.read(banliStream), spacing + 20, y + 440, 170, 38, null); |
| | | // |
| | | // inviteCode = "邀请码:" + inviteCode; |
| | | // Font font26d28 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.28f); |
| | | // FontMetrics fmcode = g2d.getFontMetrics(font26d28); |
| | | // int codeLength = fmcode.stringWidth(inviteCode); |
| | | // // 邀请码背景 |
| | | // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | // g2d.setColor(new Color(229,71, 27)); |
| | | // g2d.fillRoundRect(spacing + (600 - (int)(codeLength * 1.1)), y + 440, 10 + codeLength, 37, 10, 10); |
| | | // // 邀请码文字 |
| | | // g2d.setFont(font26d28); |
| | | // g2d.setColor(new Color(255, 255, 255)); |
| | | // g2d.drawString(inviteCode, spacing + (600 - (int)(codeLength * 1.1) + 5), y + 468); |
| | | |
| | | g2d.dispose(); |
| | | |