zoukankan      html  css  js  c++  java
  • 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     }
  • 相关阅读:
    create-react-app 修改 webpack output.publicPath
    洛谷 P1282 多米诺骨牌 (01背包)
    UVa 1627
    UVa 1626
    UVa 11584
    UVa 11400
    UVa 116
    UVa 1347 Tour (dp)
    树形背包小结
    数据流图题目一
  • 原文地址:https://www.cnblogs.com/zl1991/p/8625424.html
Copyright © 2011-2022 走看看