We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 9 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
将 libwebp 与 NDK 结合使用。
libwebp-0.1.3 已经附带 Android.mk 文件(已过时且有语法错误,但仍然如此)。它还在
/swig/
目录中生成了 JNI 绑定。我的工作方式如下:
PATH
中。your_project_dir/jni
中,Android.mk
替换为以下内容。jni/src/libwebp_java_wrap.c
。jni/Application.mk
,内容如下。/libs/
中生成.so
文件。您可以使用 nm -D libs/armeabi/libwebp.so 来检查它们。在列表中,您将看到本机库函数(例如WebPDecodeRGB
)及其 JNI 对应函数(例如Java_com_google_webp_libwebpJNI_WebPDecodeRGB
)/jni/swig/libwebp.jar
构建 Android 项目的路径这里是 Android.mk 的内容。对原始内容进行了更改:删除了编码器位,因为我不需要这些,添加了
libwebp_java_wrap.c
,将include $(BUILD_STATIC_LIBRARY)
更改为include $(BUILD_SHARED_LIBRARY)< /代码>。
libwebp_java_wrap.c 的内容位于此处,它与 libwebp tarball 中捆绑的内容基本相同,只是删除了编码器位。
Application.mk 的内容:
以下是如何在 Java 代码中使用。注意它如何将 byte[] 数组转换为 int[] 颜色数组——如果字节顺序改变,这将会中断,对吧?另请注意它如何使用数组而不是单个整数来表示宽度和高度,以便它们通过引用传递。
Use libwebp with NDK.
libwebp-0.1.3 already comes with Android.mk file (outdated and with syntax errors, but still). It also got generated JNI bindings in
/swig/
directory.Here's how I got it working:
PATH
.your_project_dir/jni
Android.mk
with the one below.jni/src/libwebp_java_wrap.c
with content from below.jni/Application.mk
, with content from below.ndk-build
from project directory. This generates.so
files in/libs/
. You can inspect them withnm -D libs/armeabi/libwebp.so
. In the list you'll see both the native library functions (likeWebPDecodeRGB
) and their JNI counterparts (likeJava_com_google_webp_libwebpJNI_WebPDecodeRGB
)/jni/swig/libwebp.jar
to build path of your Android projectHere's content for Android.mk. Changed from original: removed encoder bits as I don't need these, added
libwebp_java_wrap.c
, changedinclude $(BUILD_STATIC_LIBRARY)
toinclude $(BUILD_SHARED_LIBRARY)
.Content for libwebp_java_wrap.c is here, it's basically the same as bundled in libwebp tarball, except encoder bits removed.
Content for Application.mk:
Here's how to use in Java code. Notice how it converts byte[] array to int[] color array--this will break if endianness changes, right? Also notice how it uses arrays instead of single integers for width and height so they are passed by reference.
WebP 支持 Android 4.0+,即 API 级别 14。可以检查使用
android.os.Build.VERSION.SDK_INT >= 14
。WebP is supported for Android 4.0+, a.k.a. API level 14. You can check using
android.os.Build.VERSION.SDK_INT >= 14
.Google 声称从 Android 4.0+ 开始支持 WebP ( http://developer.android .com/guide/appendix/media-formats.html ),但是在我们自己的测试中,webp 图像在标准浏览器以及 Android 4.0 和 4.1 上的 Chrome 中都显示为蓝色问号。
在 Android 4.2 上,WebP 图像在 webview 和 google chrome 中似乎可以正常渲染。
Google claims that WebP is supported starting from Android 4.0+ ( http://developer.android.com/guide/appendix/media-formats.html ), however in our own tests webp images show as blue questionmarks both in the standard browser and Chrome on Android 4.0 and 4.1.
On Android 4.2 WebP images seem to be rendered ok in a webview and in google chrome.
我们为此编写了一个 Android 库。
https://github.com/EverythingMe/webp-android
webp-android是我们使用的一个库在 EverythingMe,因为我们喜欢 webp。我们用它来节省带宽并缩小 APK 大小。
webp-android 是 chromium 的 webp 解码器的改编版,并添加了 JNI 包装器,以便在 java 代码中轻松使用它。
将 webp 图像从 xml 加载到 ImageView(使用包含的
WebpImageView
)也很容易,如下所示:We've written an Android library just for that.
https://github.com/EverythingMe/webp-android
webp-android is a library we use at EverythingMe since we love webp. We use it to save bandwidth as well as shrinking our APK sizes.
webp-android is an adaptation of chromium's webp decoder, and an addition of a JNI wrapper to easily use it it in your java code.
It's also easy to load webp images from xml to an ImageView (with the included
WebpImageView
) like so:目前无法在 Android 设备上的任何本机应用程序(包括 Web 浏览器)上显示 webp 图像。您必须研究第三方应用程序才能显示这些图像。
根据 WebP 邮件列表,他们正在努力将 WebP 支持纳入 Android SDK 中。他们没有透露具体计划何时发布,但当他们发布时,你应该能够将位图保存为 WebP 格式以及 JPEG 和 PNG。
编辑:Android 4.0 又名 Ice Cream Sandwich 现在原生支持 WebP 格式。您可以在 Android 开发者网站查看支持的文件类型。
There is currently no way to display a webp image on any native app on an Android device, including the web browser. You will have to look into 3rd party apps to display these images.
According to the WebP mailing list, they are working on incorporating WebP support into the Android SDK. They did not say when exactly they plan to release this but when they do you should be able to save bitmaps as WebP format as well as JPEG and PNG.
EDIT: Android 4.0 aka Ice Cream Sandwich now comes with native support for the WebP format. You can see supported file types at the Android developer site.