title: How to convert webp to png or jpg using java in windows?
body: <p>I got <strong><a href="https://bitbucket.org/luciad/webp-imageio" rel="nofollow noreferrer">bitbucket.org/luciad/webp-imageio</a></strong> to work in Ubuntu, but I can't get it to work in Windows.</p>
  
  <p>Here is what I do in Ubuntu:</p>
  
  <ol>
  <li><p>Download webp-imageio and <a href="http://downloads.webmproject.org/releases/webp/libwebp-0.4.2.tar.gz" rel="nofollow noreferrer"><strong>libwebp</strong></a> source code (other versions can be found in the <a href="http://downloads.webmproject.org/releases/webp/index.html" rel="nofollow noreferrer"><strong>google webp downloads repository</strong></a>).</p></li>
  <li><p>Using cmake to compile libwebp and webp-imageio, there is a <code>CMakefile.txt</code> file in webp-imageio. Maybe you need to modify it? Then you will get <code>webp-imageio.jar</code> and <code>libwebp-imageio.so</code> (it will be <code>.dll</code> in windows)</p></li>
  <li><p>Put <code>libwebp-imageio.so</code> in the java project Native library location and <code>webp-imageio.jar</code> in the java build path.</p></li>
  <li><p>Then, run the following code:</p></li>
  </ol>
  
  
  
  <pre><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();  
  }  
  </code></pre>
  
  <ol start="5">
  <li>Then, I use cmake and mingw-w64, compile it in windows (<code>webp-imageio.jar</code> and <code>libwebp-imageio.dll</code>). That doesn't work, however, as <code>ImageIO.read(file1);</code> returns null. WHY?</li>
  </ol>
  
  <p>Here is my code for Windows:</p>
  
  
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>Here is the exception stack:</p>
  
  <pre><code>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)
  </code></pre>