webp最新版本是 0.4.2 ,下载地址:
https://chromium.googlesource.com/webm/libwebp/+/0.4.2
http://downloads.webmproject.org/releases/webp/libwebp-0.4.2.tar.gz
https://chromium.googlesource.com/webm/libwebp/+archive/0.4.2.tar.gz
/usr/local/lib
gcc -shared -fPIC -fno-strict-aliasing -O2 -I/usr/lib/jvm/java-openjdk/include -I/usr/lib/jvm/java-openjdk/include/linux libwebp_java_wrap.c -lwebp -o /usr/local/lib/libwebp_jni.so直接将so文件安装到/usr/local/lib
#include <jni.h> ^ compilation terminated.jni.h在目录:/usr/lib/jvm/java-openjdk/include
#include "jni_md.h" ^ compilation terminated.jni_md.h在目录:/usr/lib/jvm/java-openjdk/include/linux
import com.google.webp.libwebp; import java.lang.reflect.Method; public class libwebp_jni_example { static { System.out.println("###################"); System.out.println(System.getProperty("java.library.path")); System.loadLibrary("webp_jni"); } /** * usage: java -cp libwebp.jar:. libwebp_jni_example */ public static void main(String argv[]) { final int version = libwebp.WebPGetDecoderVersion(); System.out.println("libwebp version: " + Integer.toHexString(version)); System.out.println("libwebp methods:"); final Method[] libwebpMethods = libwebp.class.getDeclaredMethods(); for (int i = 0; i < libwebpMethods.length; i++) { System.out.println(libwebpMethods[i]); } } }
Exception in thread "main" java.lang.UnsatisfiedLinkError: no webp_jni in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at libwebp_jni_example.<clinit>(libwebp_jni_example.java:9)说明/usr/local/lib没有libwebp_jni.so,检查是否编译so文件,文件大小是否正确。
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/lib/libwebp_jni.so: libwebp.so.5: cannot open shared object file: No such file or directory at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1880) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1088) at libwebp_jni_example.<clinit>(libwebp_jni_example.java:9)说明目录LD_LIBRARY_PATH和java.library.path目录不一致。或者libwebp.so文件有问题,比如大小为0,则可能编译有问题,目前在centos6编译成功。
则设置环境变量:export LD_LIBRARY_PATH=/usr/local/lib
/usr/local/lib目录下面文件如下:
-rw-r--r--. 1 root root 4412068 Feb 3 16:40 libwebp.a -rwxr-xr-x. 1 root root 37138 Feb 3 16:44 libwebp_jni.so -rwxr-xr-x. 1 root root 952 Feb 3 16:40 libwebp.la lrwxrwxrwx. 1 root root 16 Feb 3 16:40 libwebp.so -> libwebp.so.5.0.2 lrwxrwxrwx. 1 root root 16 Feb 3 16:40 libwebp.so.5 -> libwebp.so.5.0.2 -rwxr-xr-x. 1 root root 2389782 Feb 3 16:40 libwebp.so.5.0.2 drwxr-xr-x. 2 root root 23 Feb 3 16:40 pkgconfig
################### /usr/local/lib libwebp version: 400 libwebp methods: public static int com.google.webp.libwebp.WebPGetDecoderVersion() public static byte[] com.google.webp.libwebp.WebPDecodeRGBA(byte[],long,int[],int[]) public static byte[] com.google.webp.libwebp.WebPDecodeARGB(byte[],long,int[],int[]) public static int com.google.webp.libwebp.WebPGetInfo(byte[],long,int[],int[]) public static byte[] com.google.webp.libwebp.WebPDecodeRGB(byte[],long,int[],int[]) public static byte[] com.google.webp.libwebp.WebPDecodeBGR(byte[],long,int[],int[]) public static byte[] com.google.webp.libwebp.WebPDecodeBGRA(byte[],long,int[],int[]) public static int com.google.webp.libwebp.WebPGetEncoderVersion() private static byte[] com.google.webp.libwebp.wrap_WebPEncodeRGB(byte[],int,int,int[],int,int,int,float) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeBGR(byte[],int,int,int[],int,int,int,float) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeRGBA(byte[],int,int,int[],int,int,int,float) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeBGRA(byte[],int,int,int[],int,int,int,float) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeLosslessRGB(byte[],int,int,int[],int,int,int) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeLosslessBGR(byte[],int,int,int[],int,int,int) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeLosslessRGBA(byte[],int,int,int[],int,int,int) private static byte[] com.google.webp.libwebp.wrap_WebPEncodeLosslessBGRA(byte[],int,int,int[],int,int,int) public static byte[] com.google.webp.libwebp.WebPEncodeRGB(byte[],int,int,int,float) public static byte[] com.google.webp.libwebp.WebPEncodeRGBA(byte[],int,int,int,float) public static byte[] com.google.webp.libwebp.WebPEncodeBGR(byte[],int,int,int,float) public static byte[] com.google.webp.libwebp.WebPEncodeBGRA(byte[],int,int,int,float) public static byte[] com.google.webp.libwebp.WebPEncodeLosslessRGB(byte[],int,int,int) public static byte[] com.google.webp.libwebp.WebPEncodeLosslessRGBA(byte[],int,int,int) public static byte[] com.google.webp.libwebp.WebPEncodeLosslessBGR(byte[],int,int,int) public static byte[] com.google.webp.libwebp.WebPEncodeLosslessBGRA(byte[],int,int,int)
Cenotso 6安装 webplib 0.4.2库,使用java调用成功
原文地址:http://blog.csdn.net/freewebsys/article/details/43451331