Can I store image files in firebase using Java API

后端 未结 1 1195
长发绾君心
长发绾君心 2020-12-01 11:41

Is there any way to store image files in firebase using Java api?

相关标签:
1条回答
  • 2020-12-01 12:04

    Try using this snippet:

    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); 
    

    and for retrieving

    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;
       }
    }
    
    0 讨论(0)
提交回复
热议问题