So currently I'm using C++
code to dump screenshots to the disk. I read them in using Java
in order to crop them and then I write them back to the disk so C++
can load them back in and apply image algorithms (OpenCV
).
After writing the modified image back from Java
, I however get the following error in C++
:
libpng error: PNG unsigned integer out of range
My cropping code in Java
is as follows:
private void cropImage(Path imageFilePath) throws IOException
{
File imageFile = imageFilePath.toFile();
BufferedImage bufferedImage = ImageIO.read(imageFile);
BufferedImage subImage = bufferedImage.getSubimage(x, y, width, height);
BufferedImage copiedImage = new BufferedImage(subImage.getWidth(), subImage.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics graphics = copiedImage.createGraphics();
graphics.drawImage(subImage, 0, 0, null);
ImageIO.write(copiedImage, getExtension(imageFile.getName()), imageFile);
}
Surprisingly, if I view the cropped PNG
it looks fine in the Windows Photo
app but will not work in libpng
. Without the cropping step, there's no libpng
issue. Is there anything wrong with my PNG
cropping code?