最近项目中有一个需求,获取服务端的图片Base64码转回图片后保存至相册,这么简单的事还用得着我动手吗,当然是使用ctrl c v大法了,下面看看代码:
public void savePicture(String courseStr){
SavePictureBean savePictureBean = new Gson().fromJson(courseStr, SavePictureBean.class);
String imgPath = savePictureBean.getImgSource();
Bitmap bitmap = ImageBase64Utils.base64ToBitmap(imgPath);
boolean b = SaveBitmapUtil.saveImageToGallery(mActivity, bitmap, null);
if (b) {
mActivity.toast("保存成功");
} else {
mActivity.toast("保存失败");
}
}
imgSource就是获取到的Base64串,这也太简单了,马上开始测试一下,
结果就崩了。。。。。。。。。。
崩的代码定位到这里:
/**
* base64转bitmap
*
* @param @param base64String
* @param @return 设定文件
* @return Bitmap 返回类型
* @throws
* @Title: base64ToBitmap
*/
public stati