复制一下代码
package cn.qtt.app.cy;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class MergeImg {
public static void main(String[] args) {
try {
String bigPath = "F:\\tomcat8\\webapps\\file_uploads/qrcode/2017/12/b.png";
String smallPath = "F:\\tomcat8\\webapps\\file_uploads/qrcode/2017/12/a.png";
String middlePath = "F:\\tomcat8\\webapps\\file_uploads/qrcode/2017/12/394804306601050112.png";
String outFile = "F:\\tomcat8\\webapps\\file_uploads/qrcode/2017/12/2.png";
BufferedImage big = ImageIO.read(new File(bigPath));
BufferedImage middle = ImageIO.read(new File(middlePath));
BufferedImage small = ImageIO.read(new File(smallPath));
Graphics2D g = middle.createGraphics();
int x = (middle.getWidth() - small.getWidth()) / 2;
int y = (middle.getHeight() - small.getHeight()) / 2;
g.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
Graphics2D gb = big.createGraphics();
int xb = (big.getWidth() - middle.getWidth()) / 2;
int yb = (big.getHeight() - middle.getHeight()) / 2;
gb.drawImage(middle, xb, yb, middle.getWidth(), middle.getHeight(),
null);
gb.dispose();
ImageIO.write(big, outFile.split("\\.")[1], new File(outFile));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}