標籤:base ram ring exce new erb imageio 上下文 img
/** * 圖片覆蓋(覆蓋圖壓縮到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;}
java使用Graphics2D圖片疊加