package tech.yooo.ratel.member.controller.saas;
import lombok.extern.slf4j.Slf4j;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
@Slf4j
public class DemoPic {
public static void main(String[] args) throws IOException {
test();
}
public static void test() throws IOException {
String pngString = "D:\\down\\goods\\sku2\\78567856.jpg";
String goodsPath = "D:\\down\\goods\\sku1\\354634563.jpg";
String prefix = "D:\\down\\goods\\1577169685.png";
String savePath = "D:\\down";
String imageName = System.currentTimeMillis() + ".png";
BufferedImage bg = new BufferedImage(658, 1986, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bg.createGraphics();
g.setBackground(Color.WHITE);
g.setColor(Color.WHITE);
BufferedImage platImage = ImageIO.read(new File(pngString));
int y = 0;
g.drawImage(platImage.getScaledInstance(658, 986, Image.SCALE_SMOOTH), 0, y, 658, 986, null);
g.drawString("到手价" , 50, 50);
y+=986;
Rectangle rectangle = new Rectangle(0, 986, 658, 500);
BufferedImage goodsImg = ImageIO.read(new File(goodsPath));
g.drawImage(goodsImg.getScaledInstance(rectangle.width, rectangle.height, Image.SCALE_SMOOTH), rectangle.x, rectangle.y, null);
y+=500;
Double rebatePrice = 3.73;
String info = "下单返" + rebatePrice.toString();
g.setFont(new Font("Microsoft YaHei", Font.BOLD, 30));
g.setColor(new Color(255, 255, 255));
g.drawString(info , 110, y+25);
g.setFont(new Font("Microsoft YaHei", Font.PLAIN, 28));
g.setColor(new Color(255, 255, 255));
g.drawString("超值好物,买就返现" , 90, y+65);
BufferedImage qrCode = ImageIO.read(new File(prefix));
g.drawImage(qrCode, 510, y+5, 230, 230, null);
g.setFont(new Font("Microsoft YaHei", Font.PLAIN, 22));
g.setColor(Color.gray);
g.drawString("长按识别二维码" , 550, y+260);
y+=25;
g.drawRect(15, y +10,90,40);
g.setColor(new Color(255, 0, 61));
g.fillRect(15, y +50,90,40);
g.setFont(new Font("Microsoft YaHei", Font.BOLD, 25));
g.setColor(Color.white);
g.drawString("到手价" , 23, y+88);
g.setFont(new Font("Microsoft YaHei", Font.PLAIN, 36));
g.setColor(Color.red);
g.drawString("¥" , 125, y+95);
g.setFont(new Font("Microsoft YaHei", Font.BOLD, 60));
g.setColor(Color.red);
g.drawString(String.valueOf(561.27) , 145, y+45);
g.setFont(new Font("Microsoft YaHei", Font.PLAIN, 30));
g.setColor(new Color(89, 89, 89));
g.drawString("原价: " , 350, y+45);
g.setFont(new Font("Microsoft YaHei", Font.PLAIN, 30));
g.setColor(new Color(89, 89, 89));
g.drawString("¥" + 565 , 415, y+45);
y+=110;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.dispose();
ImageIO.write(bg, "jpg", new File(savePath + File.separator + imageName));
}
}