【问题标题】:How to save images on Firebase [duplicate]如何在 Firebase 上保存图像 [重复]
【发布时间】:2016-08-16 13:31:16
【问题描述】:

我正在使用 firebase 作为我的 android 应用程序的后端,我想将图像保存在 firebase 上并在我的应用程序中检索它。请告诉我如何完成此操作。

【问题讨论】:

标签: android firebase firebase-realtime-database


【解决方案1】:

你可以这样存储:

Bitmap bmp =  BitmapFactory.decodeResource(getResources(),R.drawable.chicken);//your image
ByteArrayOutputStream bYtE = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, bYtE);
bmp.recycle();
byte[] byteArray = bYtE.toByteArray();
String encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);  

然后:

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

祝你好运!

【讨论】:

  • 如何将手机图库中的图片保存到 firebase 以及我应该使用什么来代替 R.drawable.chicken 。
  • 糟糕的解决方案,当在 base64 上下载太多高质量的图像时,应用程序很容易崩溃。
猜你喜欢
  • 1970-01-01
  • 2017-08-10
  • 2021-02-26
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
相关资源
最近更新 更多