| | |
| | | import org.yeshi.utils.entity.DateInfo;
|
| | |
|
| | | import com.yeshi.fanli.entity.bus.activity.RecommendActivityTaoBaoGoods;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | | import com.yeshi.fanli.vo.goods.GoodsDetailVO;
|
| | |
|
| | | public class ImageUtil {
|
| | |
|
| | | // 画商品分享图
|
| | | public static InputStream drawGoodsShareXCX(InputStream qrcode, UserInfo user, 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 = 1061; // 图片高度
|
| | | 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(goods.getPicUrl().replace("https://", "http://"));
|
| | | g2d.drawImage(ImageIO.read(picStream), 0, 0, x, y, null);
|
| | |
|
| | | // 2、画来源图标
|
| | | int length = 10;
|
| | | int row1 = 260;
|
| | | 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);
|
| | |
|
| | | title = title.substring(length);
|
| | | row++;
|
| | | // 判断标题内容是否画完,最多可画三行
|
| | | while (title.length() > 0 && row < 3) {
|
| | | length = ImageUtil.getTextLengthByWidth(g2d, font26, title, 320, 11);
|
| | | g2d.drawString(title.substring(0, length), spacing, y + 45 + row * 36);
|
| | | title = title.substring(length);
|
| | | row++;
|
| | | }
|
| | |
|
| | | String code_frame = "image/share/ic_qr_code_frame.png";
|
| | | if (!goods.isHasCoupon()) {
|
| | | // 无券
|
| | | code_frame = "image/share/ic_qr_code_frame_no_coupon.png";
|
| | | g2d.setColor(new Color(229, 0, 92));
|
| | | g2d.drawString("¥ ", spacing, y + 175);
|
| | | g2d.setFont(boldFont36);
|
| | | g2d.drawString(MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()).toString(), spacing + 21, y + 175);
|
| | | } else {
|
| | | // 券后价
|
| | | g2d.setFont(font26);
|
| | | g2d.setColor(new Color(229, 0, 92));
|
| | | g2d.drawString("券后价 ¥ ", spacing, y + 175);
|
| | | g2d.setFont(boldFont36);
|
| | | g2d.drawString(MoneyBigDecimalUtil.getWithNoZera(goods.getCouponPrice()).toString(), spacing + 116,
|
| | | y + 175);
|
| | |
|
| | | // 渠道原价
|
| | | g2d.setColor(new Color(153, 153, 153));
|
| | | g2d.setFont(font24);
|
| | | g2d.drawString(goods.getPriceName() + " ¥ " + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()),
|
| | | spacing, y + 210);
|
| | |
|
| | | // 券字
|
| | | InputStream quan = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_quan.png");
|
| | | g2d.drawImage(ImageIO.read(quan), spacing, y + 240, 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 + 240, textLength + 20, 39, 10, 10);
|
| | | g2d.drawString(quanAmount, spacing + 55, y + 270);
|
| | |
|
| | | }
|
| | |
|
| | | // 自营 、包邮
|
| | | if (goods.getShopType() == 21) {
|
| | | InputStream ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
|
| | | g2d.drawImage(ImageIO.read(ziying), spacing + 300, 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 + 300, 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 + 360 - textLength, y + 210);
|
| | |
|
| | | // 二维码图框
|
| | | g2d.setColor(Color.WHITE);
|
| | | InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream(code_frame);
|
| | | g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 20, 200, 220, null);
|
| | | // 画二维码
|
| | | int codeSize = 170;
|
| | | g2d.drawImage(ImageIO.read(qrcode), spacing + 420, y + 38, codeSize, codeSize, null);
|
| | |
|
| | | // 头像
|
| | | InputStream portraitStream = null;
|
| | | try {
|
| | | portraitStream = HttpUtil.getAsInputStream(user.getPortrait());
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | |
| | | if (portraitStream == null) {
|
| | | portraitStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png");
|
| | | }
|
| | | BufferedImage portraitImg = ImageIO.read(portraitStream);
|
| | | BufferedImage zoomInImage = ImageUtil.zoomInImage(portraitImg, 84, 84);
|
| | | BufferedImage roundImage = ImageUtil.roundImage(zoomInImage, 84);
|
| | | g2d.drawImage(roundImage, spacing, y + 310, 84, 84, null);
|
| | |
|
| | | g2d.setFont(font24);
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | | g2d.drawString(user.getNickName(), spacing + 84 + 17, y + 335);
|
| | |
|
| | | g2d.setFont(font24);
|
| | | g2d.setColor(new Color(153, 153, 153));
|
| | | g2d.drawString(source + "商品99%都有优惠或返利", spacing + 84 + 17, y + 385);
|
| | |
|
| | | 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 qrcode 二维码流
|
| | | * @param portrait 头像流
|
| | | * @param goods 商品信息
|
| | | * @return
|
| | | */
|
| | | public static InputStream drawGoodsShareSingle(InputStream qrcode, InputStream portrait, 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 = 1061; // 图片高度
|
| | | if (!goods.isHasCoupon()) {
|
| | | py = py - 131;
|
| | | }
|
| | |
|
| | | 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(goods.getPicUrl().replace("https://", "http://"));
|
| | | g2d.drawImage(ImageIO.read(picStream), 0, 0, x, y, null);
|
| | |
|
| | | // 2、画来源图标
|
| | | int length = 10;
|
| | | int row1 = 260;
|
| | | int iconWidth = 72;
|
| | | InputStream icon = null;
|
| | | int goodsType = goods.getGoodsType();
|
| | | if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
|
| | | 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) {
|
| | | icon = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_jd.png");
|
| | | } else if (goodsType == Constant.SOURCE_TYPE_PDD) {
|
| | | 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);
|
| | |
|
| | | title = title.substring(length);
|
| | | row++;
|
| | | // 判断标题内容是否画完,最多可画三行
|
| | | while (title.length() > 0 && row < 3) {
|
| | | length = ImageUtil.getTextLengthByWidth(g2d, font26, title, 320, 11);
|
| | | g2d.drawString(title.substring(0, length), spacing, y + 45 + row * 36);
|
| | | title = title.substring(length);
|
| | | row++;
|
| | | }
|
| | |
|
| | | String code_frame = "image/share/ic_qr_code_frame.png";
|
| | | if (!goods.isHasCoupon()) {
|
| | | // 无券
|
| | | code_frame = "image/share/ic_qr_code_frame_no_coupon.png";
|
| | |
|
| | | g2d.setColor(new Color(229, 0, 92));
|
| | | g2d.drawString("¥ ", spacing, y + 175);
|
| | | g2d.setFont(boldFont36);
|
| | | g2d.drawString(MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()).toString(), spacing + 21, y + 175);
|
| | | } else {
|
| | | // 券后价
|
| | | g2d.setFont(font26);
|
| | | g2d.setColor(new Color(229, 0, 92));
|
| | | g2d.drawString("券后价 ¥ ", spacing, y + 175);
|
| | | g2d.setFont(boldFont36);
|
| | | g2d.drawString(MoneyBigDecimalUtil.getWithNoZera(goods.getCouponPrice()).toString(), spacing + 116,
|
| | | y + 175);
|
| | |
|
| | | // 渠道原价(在售价)
|
| | | g2d.setColor(new Color(153, 153, 153));
|
| | | g2d.setFont(font24);
|
| | | g2d.drawString(goods.getPriceName() + " ¥ " + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice()),
|
| | | spacing, y + 210);
|
| | |
|
| | | // 券字
|
| | | InputStream quan = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_quan.png");
|
| | | g2d.drawImage(ImageIO.read(quan), spacing, y + 240, 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 + 240, textLength + 20, 39, 10, 10);
|
| | | g2d.drawString(quanAmount, spacing + 55, y + 270);
|
| | |
|
| | | // 提示语
|
| | | InputStream tipStream = ImageUtil.class.getClassLoader()
|
| | | .getResourceAsStream("image/share/tip_angle.png");
|
| | | g2d.drawImage(ImageIO.read(tipStream), spacing, y + 300, 601, 101, null);
|
| | | }
|
| | |
|
| | | // 自营 、包邮
|
| | | if (goods.getShopType() == 21) {
|
| | | InputStream ziying = ImageUtil.class.getClassLoader().getResourceAsStream("image/icon_ziying.png");
|
| | | g2d.drawImage(ImageIO.read(ziying), spacing + 300, 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 + 300, 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 + 360 - textLength, y + 210);
|
| | |
|
| | | // 二维码图框
|
| | | g2d.setColor(Color.WHITE);
|
| | | InputStream codeFrame = ImageUtil.class.getClassLoader().getResourceAsStream(code_frame);
|
| | | g2d.drawImage(ImageIO.read(codeFrame), spacing + 405, y + 20, 200, 261, null);
|
| | |
|
| | | // 画 二维码
|
| | | int codeSize = 170;
|
| | | g2d.drawImage(ImageIO.read(qrcode), spacing + 420, y + 38, codeSize, codeSize, null);
|
| | |
|
| | | // 画二维码中 头像
|
| | | int portraitSize = 40;
|
| | | int pPX = spacing + 425 + codeSize / 2 + -portraitSize / 2;
|
| | | int pPY = y + 35 + codeSize / 2 - portraitSize / 2;
|
| | | BufferedImage portraitImg = ImageIO.read(portrait);
|
| | | portraitImg = ImageUtil.roundImage(portraitImg, 10);
|
| | | // 头像白色边框
|
| | | g2d.fillRoundRect(pPX - 4, pPY - 4, portraitSize + 8, portraitSize + 8, 10, 10);
|
| | | // 头像
|
| | | g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, 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 drawGoodsShareImg(InputStream qrcodeStream, InputStream portrait,
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 绘制大的商品动态分享图
|
| | | *
|
| | |
| | | e2.printStackTrace();
|
| | | }
|
| | | g2d.setFont(font);
|
| | | |
| | | |
| | |
|
| | | try {
|
| | | boolean index = true;
|
| | | // 画第一张
|
| | |
| | | if (i == 0 || index) {
|
| | | int topX = 50;
|
| | | int topY = 50;
|
| | | |
| | | |
| | |
|
| | | // 画大图 起始点坐标为(50,50)
|
| | | int widht = 650;
|
| | | int height = 650;
|
| | | InputStream goodsPicture = TaoBaoHttpUtil.getAsInputStream(goods.getPicture().replace("_.webp", "").replace("_220x220", ""));
|
| | | InputStream goodsPicture = TaoBaoHttpUtil
|
| | | .getAsInputStream(goods.getPicture().replace("_.webp", "").replace("_220x220", ""));
|
| | | if (goodsPicture == null)
|
| | | continue;
|
| | | |
| | |
|
| | | 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);
|
| | |
|
| | |
| | | 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 size = withNoZera.toString().length() * 22;
|
| | | int place = withNoZera.toString().length() * 22;
|
| | |
|
| | | // 券红色底部
|
| | | int quanBGWidht = widht-100 - place;
|
| | | 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.drawString("券", quanBGWidht + 8, quanBGHeight + 48);
|
| | |
|
| | | // 券白色底部
|
| | | g2d.fillRoundRect(quanBGWidht + 55, quanBGHeight + 4 , 70 + size, 62, 10, 10);
|
| | | |
| | | g2d.fillRoundRect(quanBGWidht + 55, quanBGHeight + 4, 70 + size, 62, 10, 10);
|
| | |
|
| | | // 画券面值
|
| | | g2d.setFont(boldFont);
|
| | | g2d.setColor(new Color(229, 0, 92));
|
| | |
| | | }
|
| | |
|
| | | index = false;
|
| | | |
| | |
|
| | | } else {
|
| | | // 计算左上角坐标
|
| | | int topX = 0;
|
| | |
| | | topY = 50 + (315 + 20) * 2;
|
| | |
|
| | | // 画大图
|
| | | InputStream goodsPicture = TaoBaoHttpUtil.getAsInputStream(goods.getPicture().replace("_.webp", ""));
|
| | | InputStream goodsPicture = TaoBaoHttpUtil
|
| | | .getAsInputStream(goods.getPicture().replace("_.webp", ""));
|
| | | if (goodsPicture == null)
|
| | | continue;
|
| | | |
| | |
|
| | | BufferedImage picImage = ImageIO.read(goodsPicture);
|
| | | picImage = ImageUtil.zoomInImage(picImage, 315, 315);
|
| | | g2d.drawImage(picImage, topX, topY, null);
|
| | |
| | | // // 画透明背景
|
| | | // 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 size = withNoZera.toString().length() * 22;
|
| | | int place = withNoZera.toString().length() * 22;
|
| | |
|
| | | // // 券红色底部
|
| | | int quanBGWidht = topX + 170 - place;
|
| | | 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.drawString("券", quanBGWidht + 8, quanBGHeight + 48);
|
| | |
|
| | | // 券白色底部
|
| | | g2d.fillRoundRect(quanBGWidht + 55, quanBGHeight + 4 , 70 + size, 62, 10, 10);
|
| | | |
| | | g2d.fillRoundRect(quanBGWidht + 55, quanBGHeight + 4, 70 + size, 62, 10, 10);
|
| | |
|
| | | // 画券面值
|
| | | g2d.setFont(boldFont);
|
| | | g2d.setColor(new Color(229, 0, 92));
|
| | |
| | | ImageIO.write(targetImg, "JPEG", aos);
|
| | | InputStream is = new ByteArrayInputStream(aos.toByteArray());
|
| | | return is;
|
| | | |
| | |
|
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | // 画商品分享图
|
| | | public static InputStream drawGoodsShareImgHCJ(InputStream qrcodeStream, InputStream portrait,
|
| | | TaoBaoGoodsBrief goods) throws Exception {
|
| | |
| | |
|
| | | // 邀请好友图片
|
| | | public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
|
| | | InputStream erCodeInputStream, String targetPath,String inviteCode) throws IOException {
|
| | | InputStream erCodeInputStream, String targetPath, String inviteCode) throws IOException {
|
| | | inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230, inviteCode);
|
| | | }
|
| | |
|
| | |
| | | * @param portraitInputStream
|
| | | * @param erCodeInputStream
|
| | | * @param targetPath
|
| | | * @param pX
|
| | | * -二维码的横坐标
|
| | | * @param pY
|
| | | * -二维码的纵坐标
|
| | | * @param size
|
| | | * -二维码的尺寸
|
| | | * @param inviteCode
|
| | | * -邀请码
|
| | | * @param pX -二维码的横坐标
|
| | | * @param pY -二维码的纵坐标
|
| | | * @param size -二维码的尺寸
|
| | | * @param inviteCode -邀请码
|
| | | * @throws IOException
|
| | | */
|
| | | // 邀请好友图片
|
| | |
| | | return stateInt;
|
| | | }
|
| | |
|
| | | static int getTextLengthByWidth(Graphics2D g2d, Font font, String content, int maxWidth, int startPos) {
|
| | | public static int getTextLengthByWidth(Graphics2D g2d, Font font, String content, int maxWidth, int startPos) {
|
| | | FontMetrics fm = g2d.getFontMetrics(font);
|
| | | for (int i = startPos; i < content.length(); i++) {
|
| | | if (fm.stringWidth(content.substring(0, i)) >= maxWidth)
|
| | |
| | | return new int[] { width, height };
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 头像加白底图 邀请好友图片
|
| | | * |
| | | * @param urlInputStream
|
| | | * @param portraitInputStream
|
| | | * @param erCodeInputStream
|
| | |
| | | * @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);
|
| | | InputStream erCodeInputStream, String targetPath, String inviteCode) throws IOException {
|
| | | inviteFriendImgWhite(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230,
|
| | | inviteCode);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 头像加白底图 邀请好友图片 -自定义二维码位置
|
| | | * 头像加白底图 邀请好友图片 -自定义二维码位置
|
| | | * |
| | | * @param urlInputStream
|
| | | * @param portraitInputStream
|
| | | * @param erCodeInputStream
|
| | |
| | | * @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);
|
| | | 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 {
|
| | | |
| | | InputStream erCodeInputStream, String targetPath, Integer pX, Integer pY, Integer size, String inviteCode)
|
| | | throws IOException {
|
| | |
|
| | | if (pX == null) {
|
| | | pX = 260;
|
| | | }
|
| | | |
| | |
|
| | | if (pY == null) {
|
| | | pY = 908; |
| | | 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);
|
| | |
| | | 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.fillRoundRect(pPX - 4, pPY - 4, portraitSize + 8, portraitSize + 8, 5, 5);
|
| | | g2d.setRenderingHints(mapH);
|
| | | // 画 头像
|
| | | BufferedImage portraitImg = ImageIO.read(portraitInputStream);
|
| | |
| | | portraitImg = ImageUtil.roundImage(portraitImg, 10);
|
| | | g2d.drawImage(portraitImg, pPX, pPY, portraitSize, portraitSize, null);
|
| | |
|
| | | |
| | | // 画邀请码(邀请码的大小与字体固定)
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | |
| | | int ax = pX - (inviteCode.length() - 4)*13 ;
|
| | | int ay = pY + size + 118;
|
| | | |
| | |
|
| | | int ax = pX - (inviteCode.length() - 4) * 13;
|
| | | int ay = pY + size + 118;
|
| | |
|
| | | int width_diap = 235 + (int) (24.6 * (inviteCode.length() - 4));
|
| | | g2d.setColor(Color.white);
|
| | | // 画出一个矩形
|
| | | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.65f)); // 透明度 |
| | | g2d.fillRect(ax, ay - 38, width_diap, 50);
|
| | | // 前半圆
|
| | | g2d.fillArc(ax - 25, ay- 38, 50, 50, 90, 180);
|
| | | // 后半圆
|
| | | g2d.fillArc(ax + width_diap - 25, ay- 38, 50, 50, 270, 180);
|
| | | |
| | | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 1f)); |
| | | // 画出一个矩形
|
| | | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.65f)); // 透明度
|
| | | g2d.fillRect(ax, ay - 38, width_diap, 50);
|
| | | // 前半圆
|
| | | g2d.fillArc(ax - 25, ay - 38, 50, 50, 90, 180);
|
| | | // 后半圆
|
| | | g2d.fillArc(ax + width_diap - 25, ay - 38, 50, 50, 270, 180);
|
| | |
|
| | | g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 1f));
|
| | | String st = "邀请码:" + inviteCode;
|
| | | String os = System.getProperty("os.name");
|
| | | String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
|
| | |
| | | g2d.setFont(boldFont);
|
| | | g2d.getFontMetrics(boldFont);
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | | |
| | |
|
| | | g2d.setColor(new Color(0, 0, 0));
|
| | | g2d.drawString(st, ax, ay);
|
| | | }
|
| | |
| | | out.flush();
|
| | | out.close();
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 绘制邀请问候图
|
| | | * @param bgPigInStream 背景图
|
| | | * @param portraitInStream 用户头像
|
| | | * @param erCodeInStream 二维码
|
| | | * @param targetPath 路径
|
| | | * @param inviteCode 邀请码
|
| | | * @param content 文字内容
|
| | | * @param date 显示日历
|
| | | * |
| | | * @param bgPigInStream 背景图
|
| | | * @param portraitInStream 用户头像
|
| | | * @param erCodeInStream 二维码
|
| | | * @param targetPath 路径
|
| | | * @param inviteCode 邀请码
|
| | | * @param content 文字内容
|
| | | * @param date 显示日历
|
| | | * @throws IOException
|
| | | */
|
| | | public static void drawInviteToGreet(InputStream bgPigInStream, InputStream portraitInStream,
|
| | |
| | | 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);// 文字抗锯齿
|
| | |
| | | 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"));
|
| | |
| | | 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.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);
|
| | |
| | | if (os.toLowerCase().startsWith("win")) {
|
| | | fontBoldPath = "C:/yahei.ttf";
|
| | | }
|
| | | |
| | |
|
| | | Font boldFont = null;
|
| | | // 画邀请码(邀请码的大小与字体固定)
|
| | |
| | | out.flush();
|
| | | out.close();
|
| | | }
|
| | | |
| | |
|
| | | }
|