I have bunch of photos sorted in a folder so that there is always one photo of type A
and one photo of type B
immediately after that.
Unfortunately, some of them needed to be rotated and I did so using standard Windows file explorer.
What I need is to combine each pair of photos A and B into new single photo so that the first source photo is displayed above the second. Both photos have same width.
Here is the code :
File first = ...;
File second = ...;
BufferedImage A = ImageIO.read(first);
BufferedImage B = ImageIO.read(second);
int resultHeight = A.getHeight() + B.getHeight();
int resultWidth = A.getWidth();
BufferedImage combined = new BufferedImage(resultWidth, resultHeight, BufferedImage.TYPE_INT_ARGB);
Graphics g = combined.getGraphics();
g.drawImage(A, 0, 0, null);
g.drawImage(B, 0, A.getHeight(), null);
g.dispose();
ImageIO.write(combined, "PNG", new File(destDirectory, destName));
Unfortunately, although all pictures seem to have same orientation when viewing with the Windows app
, they are rotated differently in the result photos. I know there is some kind of flag that seems to be ignored by the BufferedImage.
How can I detect that flag and eventually rotate the photo as needed before combining? Thanks!