首页 > 技术文章 > Bitmap对图像进行Base64编解码

fruitbolgs 2015-08-14 17:21 原文

  1. public String bitmaptoString(Bitmap bitmap) {
  2. // 将Bitmap转换成字符串
  3. String string = null;
  4. ByteArrayOutputStream bStream = new ByteArrayOutputStream();
  5. bitmap.compress(CompressFormat.PNG, 100, bStream);
  6. byte[] bytes = bStream.toByteArray();
  7. string = Base64.encodeToString(bytes, Base64.DEFAULT);
  8. return string;
  9. }
  1. public Bitmap stringtoBitmap(String string) {
  2. // 将字符串转换成Bitmap类型
  3. Bitmap bitmap = null;
  4. try {
  5. byte[] bitmapArray;
  6. bitmapArray = Base64.decode(string, Base64.DEFAULT);
  7. bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0,
  8. bitmapArray.length);
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. }
  12. return bitmap;
  13. }



来自为知笔记(Wiz)


推荐阅读