rt,jar jdk 里自带功能
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
// 先画一个底板图片
private static BufferedImage getWhitePic(int x,int y){
BufferedImage bufferImage=null;
bufferImage = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufferImage.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, x, y);
//填充整个屏幕
return bufferImage;
}
// 在底片左上角开始合成新图片
public static BufferedImage overlyingImage(BufferedImage buffImg, BufferedImage waterImg, int x, int y, float alpha) {
//覆盖
// create Graphics2D object
Graphics2D g2d = buffImg.createGraphics();
g2d.setBackground(Color.WHITE);
//set background color
int waterImgWidth = waterImg.getWidth();
int waterImgHeight = waterImg.getHeight();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
g2d.drawImage(waterImg, x, y, waterImgWidth, waterImgHeight, null);
g2d.dispose();
return buffImg;
}