Android - java.lang.NoSuchFieldError: android.graphics.Bitmap$CompressFormat.WEBP

自作多情 提交于 2019-12-24 14:24:17

问题


I'm trying to use a very simple piece of code that has been supported since API 1.

if (bitmap != null) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.WEBP, IMAGE_QUALITY, byteArrayOutputStream);
    byte[] bytes = byteArrayOutputStream.toByteArray();
    result = Base64.encodeToString(bytes, Base64.DEFAULT);
}

somehow,

bitmap.compress(Bitmap.CompressFormat.WEBP, IMAGE_QUALITY, byteArrayOutputStream);

gives me that weird error: java.lang.NoSuchFieldError: android.graphics.Bitmap$CompressFormat.WEBP and this only happens on my moto razr 2.3

i can't find anything on the internet about this. what's going on? (i get that, clearly, motorola's stock android didn't think to include it, but how would i fix this?) any hints?

all i want to do is to compress take a snapshot of the screen (or view), and attach it IN A USER FRIENDLY WAY in String form (this same device also doesn't do file attachments correctly either) to the body of an email intent, and pass that off to whoever can send emails.

trying to compress to .jpeg, then converting it to base64 encoded string, and then attaching to email in the body takes forever, and is not very user-responsive. this can't happen.

any help?


回答1:


android.graphics.Bitmap$CompressFormat.WEBP only works for api level 14 or above.

Try some WebP libraries.
WebP library for java?



来源:https://stackoverflow.com/questions/19308831/android-java-lang-nosuchfielderror-android-graphics-bitmapcompressformat-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!