i want to convert a .webp image to .jpeg. I have used javax.imageio.ImageIO
.
but @ line no: 19 bImage = ImageIO.read(fis);
returns a null for webp images.
Code is working fine if I try to convert .png ,.gif file format..
can any one help?
public static void imageIoWrite() {
BufferedImage bImage = null;
try {
File initialImage = new File("resources/1.webp");
FileInputStream fis = new FileInputStream(initialImage);
bImage = ImageIO.read(fis); //why it returns null?
if (bImage != null) {
ImageIO.write(bImage, "jpg",
new File("resources/NewImage1.jpg"));
System.out.println("Image file written successfully");
} else {
System.out.println("imag is empty");
}
} catch (IOException e) {
System.out.println("Exception occured :" + e.getMessage());
}
}
It seems that ImageIO
is not able to read webp
images. As you can read in the docs, the method read
returns null
in this case. I think that you have to use an additional library to read and write webp
images.