提交 54843426 authored 作者: JarvanMo's avatar JarvanMo

support lower api because getAllocationByteCount() requires API 19.

上级 38e0d832
...@@ -3,6 +3,7 @@ package com.jarvan.fluwx.utils; ...@@ -3,6 +3,7 @@ package com.jarvan.fluwx.utils;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Build;
import com.jarvan.fluwx.constant.WeChatPluginImageSchema; import com.jarvan.fluwx.constant.WeChatPluginImageSchema;
import com.jarvan.fluwx.constant.WechatPluginKeys; import com.jarvan.fluwx.constant.WechatPluginKeys;
...@@ -44,7 +45,13 @@ public class ShareImageUtil { ...@@ -44,7 +45,13 @@ public class ShareImageUtil {
String pathWithoutUri = path.substring("file://".length()); String pathWithoutUri = path.substring("file://".length());
bmp = BitmapFactory.decodeFile(pathWithoutUri); bmp = BitmapFactory.decodeFile(pathWithoutUri);
if (bmp.getAllocationByteCount() >= WX_MAX_IMAGE_BYTE_SIZE) { int byteCount;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
byteCount = bmp.getAllocationByteCount();
}else {
byteCount = bmp.getByteCount();
}
if (byteCount >= WX_MAX_IMAGE_BYTE_SIZE) {
result = Util.bmpToCompressedByteArray(bmp, Bitmap.CompressFormat.JPEG, true); result = Util.bmpToCompressedByteArray(bmp, Bitmap.CompressFormat.JPEG, true);
} else { } else {
result = Util.bmpToByteArray(bmp, true); result = Util.bmpToByteArray(bmp, true);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论