package com;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class Test{
public static void main(String[] args){
try {
InputStream is1=new FileInputStream("D:/b.jpg");
InputStream is2=new FileInputStream("D:/a.jpg");
BufferedImage image1=ImageIO.read(is1);
BufferedImage image2=ImageIO.read(is2);
Graphics g=image1.getGraphics();
g.drawImage(image2,image1.getWidth()-50,image1.getHeight()-50,null);
OutputStream out=new FileOutputStream("D:/合并后的图片.jpg");
System.out.println("成功!");
JPEGImageEncoder enc=JPEGCodec.createJPEGEncoder(out);
enc.encode(image1);
is1.close();
is2.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
java融合图片
最新推荐文章于 2024-03-07 16:45:34 发布