我可以使用Java API将图像文件存储在firebase中

Kab*_*bir 9 java android firebase

有没有办法使用Java API在firebase中存储图像文件?

sas*_*uri 12

尝试使用此代码段:

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 imageFile = Base64.encodeToString(byteArray, Base64.DEFAULT); 
Run Code Online (Sandbox Code Playgroud)

并用于检索

public Bitmap stringToBitMap(String encodedString){
   try {
      byte [] encodeByte=Base64.decode(encodedString,Base64.DEFAULT);
      Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
      return bitmap;
   } catch(Exception e) {
      e.getMessage();
      return null;
   }
}
Run Code Online (Sandbox Code Playgroud)

  • 如何从imageFile字符串显示图像? (3认同)
  • 以下内容可帮助您将编码的字符串显示为位图.byte [] decodingString = Base64.decode(imageFileString,Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodingString,0,encodedString.length); imageView.setImageBitmap(位图); (3认同)