Android Bitmap与String互转(转)

复制代码
 1 /**
 2      * 图片转成string
 3      * 
 4      * @param bitmap
 5      * @return
 6      */
 7     public static String convertIconToString(Bitmap bitmap)
 8     {
 9         ByteArrayOutputStream baos = new ByteArrayOutputStream();// outputstream
10         bitmap.compress(CompressFormat.PNG, 100, baos);
11         byte[] appicon = baos.toByteArray();// 转为byte数组
12         return Base64.encodeToString(appicon, Base64.DEFAULT);
13 
14     }
15 
16     /**
17      * string转成bitmap
18      * 
19      * @param st
20      */
21     public static Bitmap convertStringToIcon(String st)
22     {
23         // OutputStream out;
24         Bitmap bitmap = null;
25         try
26         {
27             // out = new FileOutputStream("/sdcard/aa.jpg");
28             byte[] bitmapArray;
29             bitmapArray = Base64.decode(st, Base64.DEFAULT);
30             bitmap =
31                     BitmapFactory.decodeByteArray(bitmapArray, 0,
32                             bitmapArray.length);
33             // bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
34             return bitmap;
35         }
36         catch (Exception e)
37         {
38             return null;
39         }
40     }
复制代码

 

posted @   鸭子船长  阅读(822)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2017-03-22 android的armeabi和armeabi-v7a
2017-03-22 NDK编译STL
2017-03-22 LOCAL_CFLAGS参数说明
2017-03-22 Android.mk 文件语法详解
点击右上角即可分享
微信分享提示