java 两张图片叠加合并

try {
            /* 1 读取第一张图片*/
            File fileOne = new File("1.png");
            BufferedImage imageFirst = ImageIO.read(fileOne);
            /* 2读取第二张图片 */
            File fileTwo = new File("2.png");
            BufferedImage imageSecond = ImageIO.read(fileTwo);
			//创建一个最底层画布 高和宽为第一章图片的高和宽
            BufferedImage image = new BufferedImage(imageFirst.getWidth(),imageFirst.getHeight(),BufferedImage.TYPE_INT_ARGB);
            //通过底图创建画笔
            Graphics graphics = image.getGraphics();
            //在底图上画第一张图
            graphics.drawImage(imageFirst,0,0,null);
            //在底图上画第二张图
            graphics.drawImage(imageSecond,0,0,null);
            //在图片上写文字
            graphics.drawString("i am a str", 10, 30);
			//输出图片
            File outFile = new File("out.png");
            ImageIO.write(image, "png", outFile);
        } catch (Exception e) {
            e.printStackTrace();
        }

你可能感兴趣的:(java,java,开发语言)