public static void mergeImage(String bigPath,String smallPath,String x,String y) throws IOException {
try {
BufferedImage small ;
BufferedImage big = ImageIO.read(new File(bigPath));
if(smallPath.contains("http")){
URL url = new URL(smallPath);
small = ImageIO.read(url);
}else{
small = ImageIO.read(new File(smallPath));
}
Graphics2D g = big.createGraphics();
float fx = Float.parseFloat(x);
float fy = Float.parseFloat(y);
int x_i = (int)fx;
int y_i = (int)fy;
g.drawImage(small, x_i, y_i,small.getWidth(),small.getHeight(), null);
g.dispose();
ImageIO.write(big, "png", new File(bigPath));
} catch (Exception e) {
e.printStackTrace();
}
}
java 图片插入另一张图片
最新推荐文章于 2022-01-22 18:53:45 发布