private static void savePNG( final BufferedImage image, final String path ){
try {
RenderedImage rendImage = image;
ImageIO.write(rendImage, "PNG", new File(path));
} catch ( IOException e) {
e.printStackTrace();
}
}
Test this function. This one works for me.
The important change is that the second parameter to ImageIO.write
is changed from ".png"
to "PNG"
(lowercase "png"
would also work), refer to the output of ImageIO.getWriterFormatNames()
for valid names.