小编Vik*_*aka的帖子

Android BitmapFactory在Base64解码字节数组上返回null

我有一台服务器,里面有几张1.5 kb到9 Mb的照片.来自PC,平板电脑和手机的照片.服务器将它们编码为Base64字符串,然后将它们发送到Android客户端.在BitmapFactory.decodeByteArray中解码时,一个300 kb的照片返回null ...但是它是有效的图像并且在在线解码器中被很好地解码.

byte[] decodedString = Base64.decode(image64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, ecodedString.length);
Run Code Online (Sandbox Code Playgroud)

2天我找不到答案(

有任何想法吗?谢谢!

PS

 private boolean decodeImage64(String uid, String image64, String name) {
    Bitmap decodedByte;
    boolean result = false;
    if (image64 != null && !image64.isEmpty()) {

        try {
            Log.e(TAG, "decodeImage64: image64.getBytes().length = " + image64.getBytes().length);
            byte[] decodedString = Base64.decode(image64, Base64.DEFAULT);
            Log.e(TAG, "decodeImage64: decodedString = " + decodedString + "  , decodedString.length = " + decodedString.length);
            decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
            Log.e(TAG, "decodeImage64: decodedByte = " …
Run Code Online (Sandbox Code Playgroud)

base64 android bitmapfactory

6
推荐指数
1
解决办法
471
查看次数

标签 统计

android ×1

base64 ×1

bitmapfactory ×1