Covert中从String Base64到Bitmap的问题

时间:2015-06-26 05:15:11

标签: android bitmap base64

Bitmap转换为String Base64 的代码内容

Bitmap thumbnail = extras.getParcelable("data");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, baos);
thumbnail.recycle();
byte[] b = baos.toByteArray();
String attachment = Base64.encodeToString(b, Base64.DEFAULT);

String Base64转换为Bitmap 的代码内容

byte[] encodeByte = Base64.decode(strBase64, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
imageView.setImageBitmap(bitmap);

但我得到bitmap = null;

我也提到Base64 to Bitmap to display in ImageView

提前致谢。

2 个答案:

答案 0 :(得分:1)

tasksController = function() {
    var taskPage;
    var initialized = false;

    return {
        init: function(page) {
            if (!initialized) {
                ....some manipulation with jQuery...
                initialized = true;
            }
        }
    };
}();

答案 1 :(得分:0)

您在加载位图后调用thumbnail.recycle();,要么删除它,要么在加载位图之前调用