/**
*param qrcodePath : 最后图片保存路劲
*/
public static void overlapImage(String qrcodePath) {
try {
BufferedImage big = new BufferedImage(1080, 1920, BufferedImage.TYPE_INT_RGB);
Graphics2D gd = big.createGraphics();
//gd.setBackground(Color.white);
gd.setColor(Color.white);
gd.dispose();
//BufferedImage big = ImageIO.read(new File(screenPath));
//BufferedImage small = ImageIO.read(new File(qrcodePath));
BufferedImage small = new BufferedImage(540, 540,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = big.createGraphics();
int x = (big.getWidth() - small.getWidth()) / 2;
int y = 200 ;
g.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
g.dispose();
ImageIO.write(big, "jpg", new File(qrcodePath));
} catch (Exception e) {
e.printStackTrace();
}
}
java实现简单的俩张图片,一张贴在另一张上面的方法。
图片的拼接。