I have 2 images to be merged that are 810KB & 850KB in size (Jpegs). When I use the following method, the resulting 'merged' PNG images size is 16.4MB (on disk). Why is this the case and how can I reduce the size while having the merged image be a PNG file?
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));
}