Recently I wrote a method which takes a photo and does a horizontal mirror (also called horizontal flip) which was working fine with all the pictures I tried (until today). Today I tried the following photo and I get the following result. For some reason most of the image color has changed to red.
Original image
Image After processing
The original image is a png and the output is jpeg. I'm not sure if that has to do with it. Here is the code which is doing the flipping
public BufferedImage flipImageHorizentally(String imagePath) throws IOException {
BufferedImage bufferedImage = ImageIO.read(new File(imagePath));
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-bufferedImage.getWidth(null), 0);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
bufferedImage = op.filter(bufferedImage, null);
System.out.println("Flipped the image horizentally!");
return bufferedImage;
}
I then save the bufferedImage
which is returned using the code below
static void SaveImageToDisk(BufferedImage bufferedImage) {
String folderName = "ProcessedImages";
Common.CreateFolderIfNotExists(folderName);
try {
// retrieve image
File outputfile = new File(folderName + File.separator + UUID.randomUUID().toString() + ".jpg");
ImageIO.write(bufferedImage, "jpg", outputfile);
} catch (IOException e) {
e.printStackTrace();
}
}
What is causing the modified image to get red? How can I prevent this from happening?