0

I am using firebase as a backend for my android app and i want to save images on firebase and retrieve it back in my app.Somebody please tell me how to accomplish this.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

-1

You can store like this:

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

And then:

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

Good luck!

Federico Blumetto
  • 967
  • 1
  • 7
  • 12