王立平-Android中对图像进行Base64编码

  1. // ------------------base64-------------------//

    public String bitmaptoString(Bitmap bitmap) {





    // 将Bitmap转换成字符串





    String string = null;





    ByteArrayOutputStream bStream = new ByteArrayOutputStream();





    bitmap.compress(CompressFormat.PNG, 100, bStream);





    byte[] bytes = bStream.toByteArray();





    string = Base64.encodeToString(bytes, Base64.DEFAULT);





    return string;





    }





    // --------------base64-----------------//

    public Bitmap stringtoBitmap(String string) {





    // 将字符串转换成Bitmap类型





    Bitmap bitmap = null;





    try {





    byte[] bitmapArray;





    bitmapArray = Base64.decode(string, Base64.DEFAULT);





    bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,





    bitmapArray.length);





    } catch (Exception e) {





    e.printStackTrace();





    }





    return bitmap;





    }
上一篇:SharePoint 学习记事(二)


下一篇:HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)