I got bitbucket.org/luciad/webp-imageio to work in Ubuntu, but I can't get it to work in Windows.
Here is what I do in Ubuntu:
Download webp-imageio and libwebp source code (other versions can be found in the google webp downloads repository).
Using cmake to compile libwebp and webp-imageio, there is a
CMakefile.txt
file in webp-imageio. Maybe you need to modify it? Then you will getwebp-imageio.jar
andlibwebp-imageio.so
(it will be.dll
in windows)Put
libwebp-imageio.so
in the java project Native library location andwebp-imageio.jar
in the java build path.Then, run the following code:
File file1= new File("/home/rtm/Desktop/xixi.webp");
File file2= new File("/home/rtm/Desktop/haha.png");
System.loadLibrary("webp-imageio");
try {
BufferedImage im = ImageIO.read(file1);
ImageIO.write(im, "png", file2);
} catch (IOException e) {
e.printStackTrace();
}
- Then, I use cmake and mingw-w64, compile it in windows (
webp-imageio.jar
andlibwebp-imageio.dll
). That doesn't work, however, asImageIO.read(file1);
returns null. WHY?
Here is my code for Windows:
File file1 = new File("D://workspace//demo//Test//unnamed.webp");
File file2 = new File("D://workspace//demo//Test//xixi.png");
System.loadLibrary("webp-imageio");
try {
//FileUtils.copyFile(file1, file2);
BufferedImage im = ImageIO.read(file1);
ImageIO.write(im, "png", file2);
} catch (Exception e) {
e.printStackTrace();
}
Here is the exception stack:
java.lang.IllegalArgumentException: image == null!
at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(Unknown Source)
at javax.imageio.ImageIO.getWriter(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)