1.初始化
public void init(){
private String backgroundImgPath="背景图片位置";
private String contentImgPath=“内容图片位置”;
}
2.背景图上添加图片
public void step1() {
try {
BufferedImage img = new BufferedImage(750, 1333, BufferedImage.TYPE_INT_RGB);
BufferedImage bg = ImageIO.read(new File(backgroundImgPath));
BufferedImage content = ImageIO.read(new File(contentImgPath));
// 中间内容框画到背景图上
Graphics g = img.getGraphics();
g.drawImage(bg.getScaledInstance(750, 1333, Image.SCALE_DEFAULT), 0, 0, null);
g.drawImage(content.getScaledInstance(750, 1333, Image.SCALE_DEFAULT), 0, 0, null);
g.dispose();
ImageIO.write(img, "png", new File("文件输出路径"));
System.out.println("生成成功!");
} catch (IOException e) {
e.printStackTrace();
}
}