在android base64中获取空解码位图图像



我正在使用base64解码编码的图像字符串,但它总是返回null。

我已经使用以下代码对字符串进行了编码&将其存储在类文件-中

Bitmap icon = BitmapFactory.decodeResource(getActivity().getResources(),R.drawable.img);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.PNG, 100, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeToString(ba,Base64.DEFAULT);

ba1存储在java文件&在我的活动中访问它进行解码,如-

MyStrings mMyString=new MyStrings();
String imageString=mMyString.image1;
Bitmap bm=decodeBase64(imageString);

但我总是觉得bm为null。有什么解决方案可以获得图像位图吗?

使用这种方式

 Bitmap icon = BitmapFactory.decodeResource(getActivity().getResources(),R.drawable.img);
 ByteArrayOutputStream bao = new ByteArrayOutputStream();
 icon.compress(Bitmap.CompressFormat.PNG, 100, bao);
 byte[] byteArray = bao.toByteArray();
 String ba1= Base64.encodeToString(byteArray, Base64.NO_WRAP);

最新更新