admin
2019-06-14 1e92eff67b997263ecefa255c63eb6641c47b57f
fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
@@ -22,16 +22,20 @@
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.imageio.ImageIO;
import org.yeshi.utils.DateLunarUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.entity.DateInfo;
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 +449,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 +475,7 @@
      return null;
   }
   /**
    * 绘制大的商品动态分享图
    * 
@@ -526,7 +530,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 +559,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 +578,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 +607,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 +650,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 +663,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 +681,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 +704,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 +716,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());
@@ -754,7 +753,269 @@
      return null;
   }
   /**
    * 绘制大的商品动态分享图
    *
    * @param qrcodeStream
    * @param portrait
    * @param goods
    * @return
    */
   public static InputStream drawGoodsSharePicture(InputStream qrcodeStream, InputStream portrait,
         List<TaoBaoGoodsBrief> goodsList) {
      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";
      }
      final BufferedImage targetImg = new BufferedImage(1420, 1334, 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, 1420, 1334);
      Font font = null;
      try {
         font = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(30.0f);
      } catch (FontFormatException e1) {
         e1.printStackTrace();
      } catch (IOException e1) {
         e1.printStackTrace();
      }
      Font boldFont = null;
      try {
         boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(50.0f);
      } catch (FontFormatException e2) {
         e2.printStackTrace();
      } catch (IOException e2) {
         e2.printStackTrace();
      }
      g2d.setFont(font);
      try {
         // 画第一张
         for (int i = 0; i < goodsList.size(); i++) {
            TaoBaoGoodsBrief goods = goodsList.get(i);
            BigDecimal couplePrice = TaoBaoUtil.getAfterUseCouplePrice(goods);
            // 第一张图需要有价格信息
            if (i == 0) {
               int topX = 50;
               int topY = 50;
               // 画大图 起始点坐标为(50,50)
               int widht = 650;
               int height = 650;
               InputStream goodsPicture = TaoBaoHttpUtil.getAsInputStream(goods.getPictUrl().replace("_.webp", "").replace("_220x220", ""));
               BufferedImage picImage = ImageIO.read(goodsPicture);
               picImage = ImageUtil.zoomInImage(picImage, widht, height);
               g2d.drawImage(picImage, topX, topX, null);
               // 画边框
               g2d.setColor(new Color(224, 224, 224));
               g2d.setStroke(new BasicStroke(1.0f));
               g2d.drawRect(topX - 1, topY - 1, widht + 1, widht + 1);
               // 画透明背景
               g2d.setColor(new Color(255, 255, 255, 210));
               g2d.fillRect(10, height - 50, widht + 40, 100);
               // 画券后价金额
               boldFont = boldFont.deriveFont(42.0f);
               g2d.setFont(boldFont);
               g2d.setColor(new Color(229, 0, 92));
               g2d.drawString("¥", 70 + 10, height);
               g2d.drawString(couplePrice + "", 70 + 45, height);
               // 画原价
               g2d.setColor(new Color(102, 102, 102));
               font = font.deriveFont(24.0f);
               g2d.setFont(font);
               String zkPrice = new BigDecimal((couplePrice + "").replace("¥", "")).add(goods.getCouponAmount())
                     .toString();
               g2d.drawString("¥ " + zkPrice, 70 + 15, height + 30);
               // 画删除线
               FontMetrics fm = g2d.getFontMetrics(font);
               int textLength = fm.stringWidth(zkPrice);
               g2d.setStroke(new BasicStroke(2.0f));
               g2d.drawLine(70 + 20, height + 21, 90 + 10 + textLength, height + 21);
               BigDecimal withNoZera = MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount());
               if (withNoZera != null && withNoZera.compareTo(new BigDecimal(0)) > 0) {
                  g2d.setRenderingHints(mapH);
                  // 券值得长度
                  int size  = withNoZera.toString().length() * 22;
                  int place  = withNoZera.toString().length() * 22;
                  // 券红色底部
                  int quanBGWidht = widht-100 - place;
                  int quanBGHeight = height - 33;
                  g2d.setColor(new Color(229, 0, 92));
                  g2d.fillRoundRect(quanBGWidht, quanBGHeight, 130 + size, 70, 10, 10);
                  // 画券字
                  boldFont = boldFont.deriveFont(40.0f);
                  g2d.setFont(boldFont);
                  g2d.setColor(new Color(255, 255, 255));
                  g2d.drawString("券",quanBGWidht + 8, quanBGHeight + 48);
                  // 券白色底部
                  g2d.fillRoundRect(quanBGWidht + 55, quanBGHeight + 4 , 70 + size, 62, 10, 10);
                  // 画券面值
                  g2d.setFont(boldFont);
                  g2d.setColor(new Color(229, 0, 92));
                  g2d.drawString("¥ " + withNoZera + "", quanBGWidht + 70, quanBGHeight + 48);
               }
            } else {
               // 计算左上角坐标
               int topX = 0;
               int topY = 0;
               if (i == 1)
                  topX = 50 + (315 + 20) * 0;
               else if (i == 2 || i % 2 != 0)// 2,3,5,7
                  topX = 50 + (315 + 20) * (i % 2 + 1);
               else if (i % 2 == 0)// 4,6,8
                  topX = 50 + (315 + 20) * 3;
               if (i == 1 || i == 2)
                  topY = 50 + 650 + 20;
               else if (i == 3 || i == 4)
                  topY = 50;
               else if (i == 5 || i == 6)
                  topY = 50 + (315 + 20) * 1;
               else if (i == 7 || i == 8)
                  topY = 50 + (315 + 20) * 2;
               // 画大图
               InputStream goodsPicture = TaoBaoHttpUtil
                     .getAsInputStream(goods.getPictUrl().replace("_.webp", ""));
               BufferedImage picImage = ImageIO.read(goodsPicture);
               picImage = ImageUtil.zoomInImage(picImage, 315, 315);
               g2d.drawImage(picImage, topX, topY, null);
               g2d.setColor(new Color(224, 224, 224));
               // 画边框
               g2d.setStroke(new BasicStroke(1.0f));
               g2d.drawRect(topX - 1, topY - 1, 316, 316);
               // 画券
               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.setRenderingHints(mapH);
                  // 券值得长度
                  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));
                  g2d.fillRoundRect(quanBGWidht, quanBGHeight, 130 + size, 70, 10, 10);
                  // 画券字
                  boldFont = boldFont.deriveFont(40.0f);
                  g2d.setFont(boldFont);
                  g2d.setColor(new Color(255, 255, 255));
                  g2d.drawString("券",quanBGWidht + 8, quanBGHeight + 48);
                  // 券白色底部
                  g2d.fillRoundRect(quanBGWidht + 55, quanBGHeight + 4 , 70 + size, 62, 10, 10);
                  // 画券面值
                  g2d.setFont(boldFont);
                  g2d.setColor(new Color(229, 0, 92));
                  g2d.drawString("¥ " + withNoZera + "", quanBGWidht + 70, quanBGHeight + 48);
               }
            }
         }
         g2d.setColor(new Color(247, 247, 247));
         g2d.fillRect(50, 1070, 1320, 214);
         // 画二维码
         BufferedImage qrcodeImage = ImageIO.read(qrcodeStream);
         qrcodeImage = ImageUtil.zoomInImage(qrcodeImage, 170, 170);
         g2d.drawImage(qrcodeImage, 70, 1092, null);
         // 画头像
         if (portrait != null) {
            BufferedImage portraitImg = ImageIO.read(portrait);
            // 放缩大小
            portraitImg = ImageUtil.zoomInImage(portraitImg, 40, 40);
            // 圆角
            portraitImg = ImageUtil.roundImage(portraitImg, 10);
            g2d.drawImage(portraitImg, 70 + (qrcodeImage.getWidth() - portraitImg.getWidth()) / 2,
                  1092 + (qrcodeImage.getHeight() - portraitImg.getHeight()) / 2, null);
         }
         font = font.deriveFont(50.0f);
         g2d.setFont(font);
         g2d.setColor(new Color(229, 0, 93));
         g2d.setColor(new Color(102, 102, 102));
         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 = ImageUtil.zoomInImage(tips, 850, 65);
         g2d.drawImage(tips, 312, 1190, null);
         g2d.dispose();
         ByteArrayOutputStream aos = new ByteArrayOutputStream();
         ImageIO.write(targetImg, "JPEG", aos);
         InputStream is = new ByteArrayInputStream(aos.toByteArray());
         return is;
      } catch (Exception e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      return null;
   }
   // 画商品分享图
   public static InputStream drawGoodsShareImgHCJ(InputStream qrcodeStream, InputStream portrait,
         TaoBaoGoodsBrief goods) throws Exception {
@@ -996,8 +1257,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 +1273,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 +1306,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();
@@ -1062,7 +1357,7 @@
      return originalImage;
   }
   static BufferedImage roundImage(BufferedImage srcImage, int cornerRadius) { // 半径
   public static BufferedImage roundImage(BufferedImage srcImage, int cornerRadius) { // 半径
      int width = srcImage.getWidth();
      int height = srcImage.getHeight();
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
@@ -1143,4 +1438,304 @@
      return new int[] { width, height };
   }
   /**
    * 头像加白底图 邀请好友图片
    * @param urlInputStream
    * @param portraitInputStream
    * @param erCodeInputStream
    * @param targetPath
    * @param inviteCode
    * @throws IOException
    */
   public static void inviteFriendImgWhite(InputStream urlInputStream, InputStream portraitInputStream,
         InputStream erCodeInputStream, String targetPath,String inviteCode) throws IOException {
      inviteFriendImgWhite(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230, inviteCode);
   }
   /**
    * 头像加白底图 邀请好友图片  -自定义二维码位置
    * @param urlInputStream
    * @param portraitInputStream
    * @param erCodeInputStream
    * @param targetPath
    * @param inviteCode
    * @throws IOException
    */
   public static void inviteFriendImgWhitecustom(InputStream urlInputStream, InputStream portraitInputStream,
         InputStream erCodeInputStream, String targetPath, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException {
      inviteFriendImgWhite(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, pX, pY, size, inviteCode);
   }
   /**
    * 邀请好友图片加上头像加上白底
    */
   public static void inviteFriendImgWhite(InputStream urlInputStream, InputStream portraitInputStream,
         InputStream erCodeInputStream, String targetPath, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException {
      if (pX == null) {
         pX = 260;
      }
      if (pY == null) {
         pY = 908;
      }
      if (size == null) {
         size = 230;
      }
      BufferedImage bgImage = ImageIO.read(urlInputStream);
      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.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
      g2d.setRenderingHints(mapH);
      // 画 二维码
      BufferedImage qrCodeImage = ImageIO.read(erCodeInputStream);
      qrCodeImage = ImageUtil.qrCodeImage(g2d, qrCodeImage, pX, pY, size, size);
      int portraitSize = size * 5 / 23;
      int pPX = pX + size / 2 - portraitSize / 2;
      int pPY = pY + size / 2 - portraitSize / 2;
      // 头像白色边框
      g2d.fillRoundRect(pPX-4, pPY-4,portraitSize+8, portraitSize + 8, 5, 5);
      g2d.setRenderingHints(mapH);
      // 画 头像
      BufferedImage portraitImg = ImageIO.read(portraitInputStream);
      portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
      portraitImg = ImageUtil.roundImage(portraitImg, 10);
      g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
      // 画邀请码(邀请码的大小与字体固定)
      if (!StringUtil.isNullOrEmpty(inviteCode)) {
         String st = "邀请码:" + inviteCode;
         String os = System.getProperty("os.name");
         String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
         if (os.toLowerCase().startsWith("win")) {
            fontBoldPath = "C:/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.getFontMetrics(boldFont);
         g2d.setColor(new Color(0, 0, 0));
         int ax = pX - 30;
         int ay = pY + size +  118;
         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();
      out.close();
   }
   /**
    * 绘制邀请问候图
    * @param bgPigInStream  背景图
    * @param portraitInStream  用户头像
    * @param erCodeInStream    二维码
    * @param targetPath    路径
    * @param inviteCode    邀请码
    * @param content       文字内容
    * @param date         显示日历
    * @throws IOException
    */
   public static void drawInviteToGreet(InputStream bgPigInStream, InputStream portraitInStream,
         InputStream erCodeInStream, String targetPath, String inviteCode, String content, Date date)
         throws IOException {
      // 背景图片
      BufferedImage bgImage = ImageIO.read(bgPigInStream);
      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.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
      g2d.setRenderingHints(mapH);
      g2d.setBackground(Color.WHITE);
      // 画 蒙层
      BufferedImage mengCeng = ImageIO
            .read(ImageUtil.class.getClassLoader().getResourceAsStream("image/invite/mc.png"));
      g2d.drawImage(mengCeng, 0, bgImage.getHeight() / 2, bgImage.getWidth(), bgImage.getHeight() / 2, null);
      int width = bgImage.getWidth();
      int height = bgImage.getHeight();
      int pX = width - 250;
      int pY = height - 290; // 320
      int size = 210; // 230
      // 画 二维码
      BufferedImage qrCodeImage = ImageIO.read(erCodeInStream);
      qrCodeImage = qrCodeImage(g2d, qrCodeImage, pX, pY, size, size); // 二维码长宽
      // 230*230
      // 画 头像
      int portraitSize = size * 5 / 23;
      int pPX = pX + size / 2 - portraitSize / 2;
      int pPY = pY + size / 2 - portraitSize / 2;
      // 头像白色边框
      g2d.fillRoundRect(pPX-4, pPY-4,portraitSize+8, portraitSize + 8, 5, 5);
      g2d.setRenderingHints(mapH);
      BufferedImage portraitImg = ImageIO.read(portraitInStream);
      portraitImg = ImageUtil.zoomInImage(portraitImg, portraitSize, portraitSize);
      portraitImg = ImageUtil.roundImage(portraitImg, 10);
      g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
      // 字体白色
      Color color = new Color(255, 255, 255);
      String os = System.getProperty("os.name");
      String fontBoldPath = "/usr/share/fonts/yahei.ttf";
      if (os.toLowerCase().startsWith("win")) {
         fontBoldPath = "C:/yahei.ttf";
      }
      Font boldFont = null;
      // 画邀请码(邀请码的大小与字体固定)
      if (!StringUtil.isNullOrEmpty(inviteCode)) {
         String st = "邀请码:" + inviteCode;
         try {
            boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(32.0f);
         } catch (FontFormatException e) {
            e.printStackTrace();
         }
         g2d.setFont(boldFont);
         g2d.setColor(new Color(255, 255, 255));
         FontMetrics fm = g2d.getFontMetrics(boldFont);
         int textLength = fm.stringWidth(st);
         int ax = (width - textLength) - 30;
         int ay = bgImage.getHeight() - 50 + boldFont.getSize() / 2 - 5;
         g2d.setColor(new Color(255, 255, 255));
         g2d.drawString(st, ax, ay);
      }
      // 左边距
      int padding_left = 30;
      // 日历
      try {
         if (date == null) {
            date = new Date();
         }
         boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
         g2d.setFont(boldFont);
         g2d.setColor(color);
         g2d.setRenderingHints(mapH);
         DateInfo dateInfo = DateLunarUtil.getDateInfo(date);
         // 农历
         g2d.drawString(dateInfo.getLunar_month() + dateInfo.getLunar_day(), padding_left, height - 80);
         // 天干地支
         g2d.drawString(dateInfo.getAgenary_month() + " " + dateInfo.getAgenary_day(), padding_left, height - 140);
         // 当前日期
         Font boldFontMax = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(100.0f);
         g2d.setFont(boldFontMax);
         if (dateInfo.getDay() < 10) {
            g2d.drawString("0" + dateInfo.getDay().toString(), padding_left, height - 200);
         } else {
            g2d.drawString(dateInfo.getDay().toString(), padding_left, height - 200);
         }
         String theDate = "";
         if (dateInfo.getMonth() < 10) {
            theDate = "/0";
         } else {
            theDate = "/";
         }
         theDate += dateInfo.getMonth() + "/" + dateInfo.getYear() + " " + dateInfo.getWeekDay();
         g2d.setFont(boldFont);
         g2d.drawString(theDate, padding_left + boldFontMax.getSize() + 15, height - 200);
      } catch (Exception e) {
         e.printStackTrace();
      }
      if (!StringUtil.isNullOrEmpty(content)) {
         // 文字内容
         try {
            boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(36.0f);
            g2d.setFont(boldFont);
            g2d.setColor(color);
            g2d.setRenderingHints(mapH);
            int lineHeight = 70;
            int lineTextLength = 19;
            if (content.length() <= lineTextLength) {
               g2d.drawString(content, padding_left, height - 350);
            } else {
               String text = "";
               int mod = content.length() % lineTextLength;
               if (mod == 0) {
                  text = content.substring(content.length() - lineTextLength, content.length());
                  content = content.substring(0, content.length() - lineTextLength);
               } else {
                  text = content.substring(content.length() - mod, content.length());
                  content = content.substring(0, content.length() - mod);
               }
               g2d.drawString(text, padding_left, height - 350);
               int i = 1;
               while (true) {
                  if (content.length() <= 17) {
                     g2d.drawString(content, padding_left, height - 350 - lineHeight * i);
                     break;
                  } else {
                     text = content.substring(content.length() - lineTextLength, content.length());
                     content = content.substring(0, content.length() - lineTextLength);
                     g2d.drawString(text, padding_left, height - 350 - lineHeight * i);
                     i++;
                  }
               }
            }
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      OutputStream out = new FileOutputStream(new File(targetPath));
      ImageIO.write(targetImg, "JPEG", out);
      out.flush();
      out.close();
   }
}