有个需求要在一张图片上绘制图案,不好实现,就想到把图案的图片直接叠加到背景图片上,试了一下,居然成功了,话不多说,直接看代码:
public static void main(String[] args) {
try {
BufferedImage big = ImageIO.read(new File("E:\\js\\img\\trouble.png"));
BufferedImage small = ImageIO.read(new File("E:\\js\\img\\wrong.png"));
Graphics2D g = big.createGraphics();
int x = 250;
int y = 48 ;
g.drawImage(small, x, y, small.getWidth(), small.getHeight(), null);
g.dispose();
ImageIO.write(big, "png", new File("E:\\js\\img\\mr.png"));
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("-------------------成功-------------------");
}
看下效果:
大图就是后边的黑背景图,小图就是那个word的桌面截图