1. /**
2. * bitmap转为base64
3. * @param bitmap
4. * @return
5. */
6. public static String bitmapToBase64(Bitmap bitmap) {
7.
8. null;
9. null;
10. try {
11. if (bitmap != null) {
12. new ByteArrayOutputStream();
13. 100, baos);
14.
15. baos.flush();
16. baos.close();
17.
18. byte[] bitmapBytes = baos.toByteArray();
19. result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
20. }
21. catch (IOException e) {
22. e.printStackTrace();
23. finally {
24. try {
25. if (baos != null) {
26. baos.flush();
27. baos.close();
28. }
29. catch (IOException e) {
30. e.printStackTrace();
31. }
32. }
33. return result;
34. }
35.
36. /**
37. * base64转为bitmap
38. * @param base64Data
39. * @return
40. */
41. public static Bitmap base64ToBitmap(String base64Data) {
42. byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT);
43. return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
44. }
android bitmap和base64之间的转换
原创
©著作权归作者所有:来自51CTO博客作者zchlww的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:空心三角形
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
JS选择图片获取base64编码预览图片
通过将图片转为data url的base64格式编码,实现直接预览图片
图片预览 base64 dataurl 图片转base64 -
base64和bitmap互相转换
[java] view plain copypublic class Base64 { /** * Default values for encoder/
Bitmap Base64 ide sed java -
Android Base64转BitMap
Android Base64转BitMap 使用场景:微信付款码 , 图片验证
Base64转BitMap Base64转图片 Base64转换成图片