我正在尝试将Base64字符串图像解码为Bitmap
,但是它总是返回null
。
这是我的代码:
public static Bitmap getBitmap(String encode) {
Bitmap bm = null;
try {
byte[] decodedString = Base64.decode(encode, Base64.DEFAULT);
bm = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
} catch (Exception e) {
Log.e(TAG,e.getMessage());
return bm;
}
return bm;
}
答案 0 :(得分:0)
对我来说,这段代码有效:
Bitmap bmp = BitmapFactory.decodeByteArray(Base64.decode(B64.BASEFILE, Base64.DEFAULT), 0, Base64.decode(B64.BASEFILE, Base64.DEFAULT).length);
ImageView iw = findViewById(R.id.imageView);
iw.setImageBitmap(bmp);
我正在API 22上进行编译。