/**
* 圖片覆蓋(覆蓋圖壓縮到width*height大小,覆蓋到底圖上)
*
* @param baseFilePath 底圖
* @param coverFilePath 覆蓋圖
* @param x 起始x軸
* @param y 起始y軸
* @param width 覆蓋寬度
* @param height 覆蓋長度度
* @return
* @throws Exception
*/
public static BufferedImage coverImage(String baseFilePath, String coverFilePath, int x, int y, int width, int height) throws Exception{
File baseFile = new File(baseFilePath);//底圖
BufferedImage buffImg = ImageIO.read(baseFile);
File coverFile = new File(coverFilePath); //覆蓋層
BufferedImage coverImg = ImageIO.read(coverFile);
buffImg = coverImage(buffImg, coverImg, x, y, width, height);
return buffImg;
}
/**
* 圖片覆蓋(覆蓋圖壓縮到width*height大小,覆蓋到底圖上)
*
* @param baseBufferedImage 底圖
* @param coverBufferedImage 覆蓋圖
* @param x 起始x軸
* @param y 起始y軸
* @param width 覆蓋寬度
* @param height 覆蓋長度度
* @return
* @throws Exception
*/
public static BufferedImage coverImage(BufferedImage baseBufferedImage, BufferedImage coverBufferedImage, int x, int y, int width, int height) throws Exception{
// 創建Graphics2D對象,用在底圖對象上繪圖
Graphics2D g2d = baseBufferedImage.createGraphics();
// 繪制
g2d.drawImage(coverBufferedImage, x, y, 300, 300, null);
g2d.dispose();// 釋放圖形上下文使用的系統資源
return baseBufferedImage;
}