我有两张合并的图像,分别是810KB和850KB大小(Jpegs)。当我使用以下方法时,生成的'合并' PNG 图片大小为16.4MB(在磁盘上)。为什么会出现这种情况,如何在合并图像为PNG文件的同时缩小尺寸?
public ImageOverlay mergeImage(BufferedImage baseImage, BufferedImage mergeImage, int padding) {
// create the new image, canvas size is the max. Of both image sizes
int w = baseImage.getWidth() + padding + mergeImage.getWidth();
int h = Math.max(baseImage.getHeight(), mergeImage.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
// paint both images, preserving the alpha channels
Graphics g = combined.getGraphics();
g.drawImage(baseImage, 0, 0, null);
g.drawImage(mergeImage, baseImage.getWidth() + padding, 0, null);
baseImage = combined;
ImageIO.write(baseImage, "png", new File(fileLocation));
}