Convert WebP to PNG using java_android

Source: Internet
Author: User
Tags webp

WEBP is Google's image format, Java class Library ImageIO is not supported in this format. Currently, in addition to online conversions and tools, the third-party class library conversion WEBP format is broadly:

1.linux:google LIBWEBP is both a class library and can be invoked at the command line

2.python:python Image Library (PIL) and its branch Https://pypi.python.org/pypi/PIL don't know much about

3.java:luciad/webp-imageio HTTPS://BITBUCKET.ORG/LUCIAD/WEBP-IMAGEIO/SRC proven available (under Linux environment)

This article describes the third method:

In the Linux environment, put Google libwebp-0.4.0 into the luciad-webp-imageio-2962dd563583 root directory, install CMake, and execute cmake in the root directory above. Command, CMake executes the make command under the root directory after completion. Make completion generates the. jar and. So files in the Java directory and the C directory, respectively. Import the. jar into your own Java project path and put the. so file in the system Java path. You can then read and write WEBP format files using ImageIO in your Java project.

Description

Operating Environment: Ubuntu

Language: Java

Example: WEBP turn png

Steps:

One: Download the following three packages

1.CMake installation package: Cmake-3.1.0-rc2-linux-i386.tar

2.Google WEBP Dependent Library: libwebp-0.4.0.tar.gz Original address: Https://developers.google.com/speed/webp/download?hl=zh-cN

3.luciad/webp-imageio Project: Luciad-webp-imageio-2962dd563583.zip Original address: HTTPS://BITBUCKET.ORG/LUCIAD/WEBP-IMAGEIO/SRC

Considering the above resources need to flip the wall to download, relatively slow. I have sent three files to the csdn,0 download.

Address: http://download.csdn.net/detail/geeklei/8161731

Two: Compiled to get Webp-imageio.jar and libwebp-imageio.so

1. Extract Luciad-webp-imageio-2962dd563583.zip.

2. Extract the libwebp-0.4.0.tar.gz to the luciad-webp-imageio-2962dd563583 root directory.

3. Will Cmake-3.1.0-rc2-linux-i386.tar decompression. CMake decompression is used, of course, you can also use the command to download the installation from the mirror source.

4. Execute the CMake under the luciad-webp-imageio-2962dd563583 root directory while ensuring CMake is available. Command. Pay attention to CMake and. There is a space between

5.cmake end, see Makefile file, execute make command under luciad-webp-imageio-2962dd563583 root directory.

The 6.make ends with a. jar and. So in the Java and C folders in the luciad-webp-imageio-2962dd563583 root directory.

Three:

1. Import Webp-imageio.jar into your own Java project in Eclipse.

2. Place the libwebp-imageio.so in the system Java path. You can use SYSTEM.OUT.PRINTLN (System.getproperty ("Java.library.path") in the project), and the statement prints out the Java path to avoid omission. There are multiple, partially duplicated, Java paths that are printed.

3. Use ImageIO in your project to read and write WEBP format files.

Code:

File file1= New file ("/home/geeklei/desktop/640_tp.webp"); 
File file2= New file ("/home/geeklei/desktop/640a.png"); 
   
System.out.println (System.getproperty ("Java.library.path")); 
   
try { 
   
 BufferedImage im = Imageio.read (file1); 
 Imageio.write (IM, "png", file2); 
    
    
} catch (IOException e) { 
 e.printstacktrace (); 
} 

Thanks to the Luciad/webp-imageio project author Luciad's efforts, as well as the selfless help to my questions.

This morning I found someone had uploaded the compiled package to the project. I did not test, but also share the bag out. Original address: Https://bitbucket.org/luciad/webp-imageio/downloads

CSDN Address: http://download.csdn.net/detail/geeklei/8163329

There's. jar. So. dll

Covers Linux 32/64 windows 32/64 versions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.