Android base64转bitmap 报错 java.lang.IllegalArgumentException: bad base-64
publicstaticBitmapstringtoBitmap(Stringstring){//将字符串转换成Bitmap类型Bitmapbitmap=null;try...
public static Bitmap stringtoBitmap(String string) {
//将字符串转换成Bitmap类型
Bitmap bitmap = null;
try {
byte[] bitmapArray;
//就是这一句报错:java.lang.IllegalArgumentException: bad base-64
bitmapArray = Base64.decode(string, Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
LecoUtils.Log("转图片 e=" + e);
}
return bitmap;
}
这是我传入的从网上获取的base64生成的图片:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOsAAADrAQMAAACyxPOWAAAABlBMVEX///8AAABVwtN+AAACeklEQVRYhe1YwY2EMAw02gdPSkgn0BgSSDQGnaQEnnkgfDN24G51BRitNg9uyXCSFdsz44h814etRrHWblHpu1n0lFGKyITNPRzGs932MbWqs0gvkuwbA6LhSVtEnvmSZNhfGY8x6fYMeNNFy6BL5mYqzaNgLHvvZbRDfQaMfK/dQWTK7cpSRORv5RAFe9Aoxb+P9yYKgiuDzMl/9SzK/h/BxMCgFd308KAR75RL3x2p9A+AZz4OIfdlMN6LMFjQ8x0JWykqGpi0okU6zTxj7MXDYBQLFQ3yyrpSJ3C8Ug81GFZLNSKfsjPKgB7BazSMfKfi9Yh4jVuMCq8GDoWVZOf9kqti4NFu4XDjmj/SAkBiqf6oQmT+lHhY82VMoLNMv//LLRZhMA5VrVUQNDwJuYWRq9QVCYtxCyjYUn0y/ZS20uzRMDvCFKM9IRFuh0HQ6SrFQJiHaj+VJhjfzJSwEdoh4TBWoZh5qFT/Fg0CvgmH6ZmsdylcyVJNu65PgOkq0RvVn68eNF/3aNh0YmUVWvjQWfbupWixsAkXq5BB06QTHlN7lWIk7NziDWLWXHi816EGwhSL0pgT8SECjAzu09rAsfBRz5MU7K1Mib3tXCDMWcG5xcZoNA2NyR15JIxZy3rDDPnFyHYDEQ8f/DOpZdnGfDcrv/kOhEnGE4UfvWFJH+5riFC4Jh2bRjAbK5ME+Edio2C/GQTPCSVCaTcxNdiVTTjMAtxQj9zkrDULB5p027lI2O64DsylvE/1yN+dZjDMKmRRnuwX0vJ91RsMr2AUu0qtN6vdcg/YobBUMrZNm2r49Xs5xMDWJbyjMaduJl2dpaPh7/qo9QP/21H/QXMQTQAAAABJRU5ErkJggg==
然后老转换不过来,老报错,求大神指点 展开
//将字符串转换成Bitmap类型
Bitmap bitmap = null;
try {
byte[] bitmapArray;
//就是这一句报错:java.lang.IllegalArgumentException: bad base-64
bitmapArray = Base64.decode(string, Base64.DEFAULT);
bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
} catch (Exception e) {
e.printStackTrace();
LecoUtils.Log("转图片 e=" + e);
}
return bitmap;
}
这是我传入的从网上获取的base64生成的图片:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOsAAADrAQMAAACyxPOWAAAABlBMVEX///8AAABVwtN+AAACeklEQVRYhe1YwY2EMAw02gdPSkgn0BgSSDQGnaQEnnkgfDN24G51BRitNg9uyXCSFdsz44h814etRrHWblHpu1n0lFGKyITNPRzGs932MbWqs0gvkuwbA6LhSVtEnvmSZNhfGY8x6fYMeNNFy6BL5mYqzaNgLHvvZbRDfQaMfK/dQWTK7cpSRORv5RAFe9Aoxb+P9yYKgiuDzMl/9SzK/h/BxMCgFd308KAR75RL3x2p9A+AZz4OIfdlMN6LMFjQ8x0JWykqGpi0okU6zTxj7MXDYBQLFQ3yyrpSJ3C8Ug81GFZLNSKfsjPKgB7BazSMfKfi9Yh4jVuMCq8GDoWVZOf9kqti4NFu4XDjmj/SAkBiqf6oQmT+lHhY82VMoLNMv//LLRZhMA5VrVUQNDwJuYWRq9QVCYtxCyjYUn0y/ZS20uzRMDvCFKM9IRFuh0HQ6SrFQJiHaj+VJhjfzJSwEdoh4TBWoZh5qFT/Fg0CvgmH6ZmsdylcyVJNu65PgOkq0RvVn68eNF/3aNh0YmUVWvjQWfbupWixsAkXq5BB06QTHlN7lWIk7NziDWLWXHi816EGwhSL0pgT8SECjAzu09rAsfBRz5MU7K1Mib3tXCDMWcG5xcZoNA2NyR15JIxZy3rDDPnFyHYDEQ8f/DOpZdnGfDcrv/kOhEnGE4UfvWFJH+5riFC4Jh2bRjAbK5ME+Edio2C/GQTPCSVCaTcxNdiVTTjMAtxQj9zkrDULB5p027lI2O64DsylvE/1yN+dZjDMKmRRnuwX0vJ91RsMr2AUu0qtN6vdcg/YobBUMrZNm2r49Xs5xMDWJbyjMaduJl2dpaPh7/qo9QP/21H/QXMQTQAAAABJRU5ErkJggg==
然后老转换不过来,老报错,求大神指点 展开
1个回答
2017-08-11
展开全部
把头的那小段去掉,保留纯正的BASE64部分 data:image/png;base64, 不要。
~
~
~
~
~
~
更多追问追答
追问
我试过,不行啊,光传个 iVBORw0KGgoAA...............QAAAABJRU5ErkJggg=或者是传个base64, iVBORw0KGgoAA...............QAAAABJRU5ErkJggg=都不行,还是在那句报同样的错误,请问您觉得还可能是什么情况呢?
追答
bitmapArray = Base64.decode(string, Base64.DEFAULT);
这段,得到的就是一个二维码的图片,jpg的。
后面的生成bitmap不正确,是JPG,不是BMP的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |