| | |
| | | package com.yeshi.fanli.util;
|
| | |
|
| | | import java.awt.AlphaComposite;
|
| | | import java.awt.BasicStroke;
|
| | | import java.awt.Color;
|
| | | import java.awt.Font;
|
| | |
| | |
|
| | |
|
| | | try {
|
| | | boolean index = true;
|
| | | // 画第一张
|
| | | for (int i = 0; i < goodsList.size(); i++) {
|
| | | CommonGoods goods = goodsList.get(i);
|
| | | BigDecimal couplePrice = CommonGoodsUtil.getAfterUseCouplePrice(goods);
|
| | | // 第一张图需要有价格信息
|
| | | if (i == 0) {
|
| | | if (i == 0 || index) {
|
| | | int topX = 50;
|
| | | int topY = 50;
|
| | |
|
| | |
| | | int widht = 650;
|
| | | int height = 650;
|
| | | 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.drawString("¥ " + withNoZera + "", quanBGWidht + 70, quanBGHeight + 48);
|
| | | }
|
| | |
|
| | | 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);
|
| | |
| | |
|
| | | // 画邀请码(邀请码的大小与字体固定)
|
| | | if (!StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | |
| | | 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)); |
| | | String st = "邀请码:" + inviteCode;
|
| | | String os = System.getProperty("os.name");
|
| | | String fontBoldPath = "/usr/share/fonts/PingFang_Medium.ttf";
|
| | |
| | | } 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));
|