This question is similar to…
…but regards .jpg
and not .png
.
I join two images together using the following Java code, and an orange background is mysteriously added. How can I get rid of it?
Note that I am trying to cover my bases using both setColor
and setBackground
, and both clearRect
and fillRect
.
Note that the source of the two images is a PDF, extracted using PDFBox
public static BufferedImage joinBufferedImage(BufferedImage img1, BufferedImage img2) {
int offset = 0;
int width = Math.max(img1.getWidth() , img2.getWidth()) + offset;
int height = img1.getHeight() + img2.getHeight() + offset;
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = newImage.createGraphics();
g2.setColor(Color.WHITE);
g2.setBackground(Color.WHITE);
g2.clearRect(0, 0, width, height);
g2.fillRect(0, 0, width, height);
g2.drawImage(img1, null, 0, 0);
g2.drawImage(img2, null, 0, img1.getHeight() + offset);
g2.dispose();
return newImage;
}
BufferedImage joined = joinBufferedImage(bim, bim2);
ImageIO.write(joined, "jpg", imageFile);