admin
2020-06-10 271ae63c20fcbe28d29c47f1881138ff6551a2a1
fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -43,6 +43,243 @@
public class ImageUtil {
   /**
    * 分析海报图
    * @param qrcode
    * @param portraitStream
    * @param goods
    * @return
    */
   public static InputStream drawGoodsQuickhShare(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");
         if (os.toLowerCase().startsWith("win")) {
            fontPath = "D:/PingFang_Medium.ttf";
         }
         String fontBoldPath = "/usr/share/fonts/PingFang_Heavy_0.ttf";
         if (os.toLowerCase().startsWith("win")) {
            fontBoldPath = "D:/PingFang_Heavy_0.ttf";
         }
         Font font24 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(24.0f);
         Font font26 = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(26.0f);
         Font boldFont36 = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
         int px = 640; // 图片宽度
         // 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);// 抗锯齿 (抗锯齿总开关)  
         mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 文字抗锯齿 
         final Graphics2D g2d = (Graphics2D) targetImg.getGraphics();
         g2d.setRenderingHints(mapH);
         g2d.setColor(Color.WHITE);
         g2d.fillRect(0, 0, px, py);
         int x = 640;
         int y = 640;
         int spacing = 20; // 右边距
         // 1、画商品主图
         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);
         // 2、画来源图标
         int length = 10;
         int row1 = 450;
         int iconWidth = 72;
         String source = "";
         InputStream icon = null;
         int goodsType = goods.getGoodsType();
         if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
            source = "淘宝";
            if (goods.getShopType() == 10) {
               icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_tb.png");
            } else {
               icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_tm.png");
            }
         } else if (goodsType == Constant.SOURCE_TYPE_JD) {
            source = "京东";
            icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_jd.png");
         } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
            source = "拼多多";
            length = 9;
            row1 = row1 - 26;
            iconWidth = iconWidth + 28;
            icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_pdd.png");
         } else {
            return null;
         }
         g2d.drawImage(ImageIO.read(icon), spacing, y + 20, iconWidth, 34, null);
         // 3、商品标题内容
         int row = 0;
         String title = goods.getTitle();
         length = ImageUtil.getTextLengthByWidth(g2d, font26, title, row1, length);
         g2d.setFont(font26);
         g2d.setColor(new Color(0, 0, 0));
         g2d.drawString(title.substring(0, length), spacing + iconWidth + 5, y + 45 + row * 36);
         row++;
         title = title.substring(length);
         int length2 = ImageUtil.getTextLengthByWidth(g2d, font26, title, 600, 11);
         if (length2 > 24) {
            g2d.drawString(title.substring(0, 21) + "...", spacing, y + 45 + row * 36);
         } else {
            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.drawString("¥ ", spacing, y + 125);
            g2d.setFont(boldFont36);
            g2d.drawString(MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()).toString(), spacing + 21, y + 125);
         } else {
            // 券后价
            g2d.setFont(font26);
            g2d.setColor(new Color(229, 0, 92));
            g2d.drawString("券后价  ¥ ", spacing, y + 125);
            g2d.setFont(boldFont36);
            String couponPrice = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponPrice()).toString();
            g2d.drawString(couponPrice, spacing + 116, y + 125);
            FontMetrics fm2 = g2d.getFontMetrics(boldFont36);
            int textLength1 = 116 + fm2.stringWidth(couponPrice);
            // 渠道原价
            g2d.setColor(new Color(153, 153, 153));
            g2d.setFont(font24);
            g2d.drawString(goods.getPriceName() + " ¥ " + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()),
                  spacing + textLength1 + 10, y + 125);
            // 券字
            InputStream quan = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_quan.png");
            g2d.drawImage(ImageIO.read(quan), spacing, y + 140, 47, 40, null);
            // 券面额
            String quanAmount = "¥ " + goods.getCouponInfo().getAmount();
            FontMetrics fm = g2d.getFontMetrics(font26);
            int textLength = fm.stringWidth(quanAmount);
            g2d.setFont(font26);
            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) {
            ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
            g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
         } else if (goods.isBaoyou()) {
            ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png");
            g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
         }
         // 销量
         String sale = null;
         int salesType = goods.getSalesType();
         if (salesType == 1) {
            sale = "月销";
         } else if (salesType == 2) {
            sale = "2小时销量";
         } else if (salesType == 3) {
            sale = "今日销量";
         } else if (salesType == 4) {
            sale = "总销量";
         } else {
            sale = "月销";
         }
         sale = sale + " " + goods.getSalesCount();
         FontMetrics fm = g2d.getFontMetrics(font24);
         int textLength = fm.stringWidth(sale);
         g2d.setFont(font24);
         g2d.setColor(new Color(153, 153, 153));
         g2d.drawString(sale, spacing + 605 - textLength, y + 125);
         // 下单提示
         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);
         // 二维码图框
         InputStream codeFrame = ImageUtil.class.getClassLoader()
               .getResourceAsStream("image/share/qr_code_frame01.png");
         g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 200, 200, 203, null);
         // 画二维码
         int codeSize = 170;
         int pX = spacing + 422;
         int pY = y + 217;
         g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null);
         int portraitSize = 200 * 5 / 23;
         int pPX = pX + codeSize / 2 - portraitSize / 2;
         int pPY = pY + codeSize / 2 - portraitSize / 2;
         // 头像白色边框
         g2d.setColor(Color.WHITE);
         g2d.fillRoundRect(pPX - 4, pPY - 4, portraitSize + 8, portraitSize + 8, 5, 5);
         g2d.setRenderingHints(mapH);
         // 画头像
         BufferedImage portraitImg = ImageIO.read(portraitStream);
         portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
         portraitImg = ImageUtil.roundImage(portraitImg, 10);
         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.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;
   }
   // 画商品分享图
   public static InputStream drawGoodsShareXCX(InputStream qrcode, UserInfo user, GoodsDetailVO goods) {
      try {
@@ -195,7 +432,8 @@
         // 二维码图框
         g2d.setColor(Color.WHITE);
         InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/qr_code_frame_xcx.png");
         InputStream codeFrame = ImageUtil.class.getClassLoader()
               .getResourceAsStream("image/share/qr_code_frame_xcx.png");
         g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 20, 200, 220, null);
         // 画二维码
         int codeSize = 170;
@@ -208,9 +446,10 @@
         } catch (Exception e) {
            e.printStackTrace();
         }
         if (portraitStream == null) {
            portraitStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_default_head.jpg");
            portraitStream = ImageUtil.class.getClassLoader()
                  .getResourceAsStream("image/official_default_head.jpg");
         }
         BufferedImage portraitImg = ImageIO.read(portraitStream);
         BufferedImage zoomInImage = ImageUtil.zoomInImage(portraitImg, 84, 84);
@@ -240,7 +479,7 @@
      }
      return null;
   }
   /**
    * 分析海报图
    * @param qrcode
@@ -248,7 +487,8 @@
    * @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");
@@ -265,7 +505,7 @@
         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>();
@@ -282,10 +522,11 @@
         int spacing = 20; // 右边距
         // 1、画商品主图
         InputStream picStream = HttpUtil.getAsInputStream(goods.getPicUrl().replace("https://", "http://"));
//         InputStream picStream  = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/test_pic1.jpg");
         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);
         // 2、画来源图标
         int length = 10;
         int row1 = 450;
@@ -330,8 +571,7 @@
         } else {
            g2d.drawString(title.substring(0, length2), spacing, y + 45 + row * 36);
         }
         int baoYouLength = spacing;
         if (!goods.isHasCoupon()) {
            // 无券
@@ -344,14 +584,14 @@
            g2d.setFont(font26);
            g2d.setColor(new Color(229, 0, 92));
            g2d.drawString("券后价  ¥ ", spacing, y + 125);
            g2d.setFont(boldFont36);
            String couponPrice = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponPrice()).toString();
            g2d.drawString(couponPrice, spacing + 116,   y + 125);
            g2d.drawString(couponPrice, spacing + 116, y + 125);
            FontMetrics fm2 = g2d.getFontMetrics(boldFont36);
            int textLength1 = 116 + fm2.stringWidth(couponPrice);
            // 渠道原价
            g2d.setColor(new Color(153, 153, 153));
            g2d.setFont(font24);
@@ -371,18 +611,19 @@
            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;
            baoYouLength = spacing + 42 + textLength + 20 + 20;
         }
         // 自营 、包邮
         InputStream ziying = null;
         if (goods.getShopType() == 21) {
            ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
            g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
         } else if (goods.isBaoyou()) {
            ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_baoyou.png");
            g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
         }
         g2d.drawImage(ImageIO.read(ziying), baoYouLength, y + 150, 60, 30, null);
         // 销量
         String sale = null;
@@ -404,26 +645,25 @@
         g2d.setFont(font24);
         g2d.setColor(new Color(153, 153, 153));
         g2d.drawString(sale, spacing + 605 - textLength, y + 125);
         // 下单提示
         InputStream downTip = null;
         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);
         // 二维码图框
         InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream("image/share/qr_code_frame01.png");
         InputStream codeFrame = ImageUtil.class.getClassLoader()
               .getResourceAsStream("image/share/qr_code_frame01.png");
         g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 200, 200, 203, null);
         // 画二维码
         int codeSize = 190;
         int pX =  spacing + 411;
         int pY =  y + 207;
         int codeSize = 170;
         int pX = spacing + 422;
         int pY = y + 217;
         g2d.drawImage(ImageIO.read(qrcode), pX, pY, codeSize, codeSize, null);
         int portraitSize = 200 * 5 / 23;
@@ -438,28 +678,34 @@
         portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
         portraitImg = ImageUtil.roundImage(portraitImg, 10);
         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();
         ByteArrayOutputStream aos = new ByteArrayOutputStream();
@@ -474,7 +720,7 @@
         }
      }
      return null;
   }
   /**
@@ -1563,9 +1809,9 @@
               // 画券
               BigDecimal withNoZera = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount());
               if (withNoZera != null && withNoZera.compareTo(new BigDecimal(0)) > 0) {
//                  // 画透明背景
//                  g2d.setColor(new Color(255, 255, 255, 210));
//                  g2d.fillRect(topX + 8, topY + 240, 300, 65);
                  // // 画透明背景
                  // g2d.setColor(new Color(255, 255, 255, 210));
                  // g2d.fillRect(topX + 8, topY + 240, 300, 65);
                  g2d.setRenderingHints(mapH);
@@ -1573,7 +1819,7 @@
                  int size = withNoZera.toString().length() * 22;
                  int place = withNoZera.toString().length() * 22;
//                  // 券红色底部
                  // // 券红色底部
                  int quanBGWidht = topX + 170 - place;
                  int quanBGHeight = topY + 220;
                  g2d.setColor(new Color(229, 0, 92));
@@ -2382,4 +2628,385 @@
      out.close();
   }
   public static InputStream drawAlipayImage(InputStream bg, String recieveTime, String money, String orderNo,
         String ttf) {
      try {
         String fontPath = "/usr/share/fonts/PingFang_Medium.ttf";
         String os = System.getProperty("os.name");
         if (os.toLowerCase().startsWith("win")) {
            fontPath = ttf;
         }
         String fontBoldPath = "/usr/share/fonts/PingFang_Heavy_0.ttf";
         if (os.toLowerCase().startsWith("win")) {
            fontBoldPath = "D:/PingFang_Heavy_0.ttf";
         }
         int px = 1080; // 图片宽度
         int py = 2340; // 图片高度
         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);// 抗锯齿 (抗锯齿总开关)  
         mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 文字抗锯齿 
         final Graphics2D g2d = (Graphics2D) targetImg.getGraphics();
         g2d.setRenderingHints(mapH);
         g2d.setColor(Color.decode("#333333"));
         g2d.fillRect(0, 0, px, py);
         BufferedImage bgImage = ImageIO.read(bg);
         g2d.drawImage(bgImage, null, 0, 0);
         Font font = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(87.0f);
         g2d.setFont(font);
         // 画金额
         FontMetrics fm = g2d.getFontMetrics(font);
         fm.stringWidth(money);
         g2d.drawString(money, (px - fm.stringWidth(money)) / 2, 359 + 65);
         // 画创建时间
         // 画订单
         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;
   }
   public static InputStream drawSimpleImage(InputStream bg, int width, int height, InputStream imgStream,
         int imgWidth, int imgHeight, int px, int py) {
      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("#333333"));
         g2d.fillRect(0, 0, px, py);
         BufferedImage bgImage = ImageIO.read(bg);
         g2d.drawImage(bgImage, null, 0, 0);
         BufferedImage img = zoomInImage(ImageIO.read(imgStream), imgWidth, imgHeight);
         g2d.drawImage(img, px, py, null);
         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;
   }
   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);
         // 画logo
         g2d.drawImage(zoomInImage(
               ImageIO.read(ImageUtil.class.getClassLoader().getResource("image/activityShare/icon_logo.png")), 59,
               59), 346, 17, null);
         // 画banner背景
         g2d.setColor(Color.decode("#FFFFFF"));
         g2d.fillRect(30, 94, 692, bannerHeight + 22);
         // 画banner
         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++;
      }
   }
}