有个需求要在一张图片上绘制图案,不好实现,就想到把图案的图片直接叠加到背景图片上,试了一下,居然成功了,话不多说,直接看代码:
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的桌面截图







![第7章第23节:双图排版:两张图片的错位叠加 [PowerPoint精美幻灯片实战教程]](https://img-blog.csdnimg.cn/img_convert/87e41e879ec3f3aa957c46db991a64d0.png)










