2016-04-22 77 views
0

我正在使用Firebase作爲我的Android應用程序的後端,並且我想將圖像保存到firebase中,並將其恢復到我的app中。有人請告訴我如何完成此操作。如何保存Firebase上的圖像

+0

看看這個類似的問題:http://stackoverflow.com/a/13957446/1478764 – chRyNaN

+0

是的。或者其中之一:https://www.google.com/search?q=site:stackoverflow.com+firebase+image+android –

回答

0

您可以存儲這樣的:

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

祝你好運!

+0

如何將圖片從手機圖庫保存到Firebase,以及我應該如何使用R代替.drawable.chicken。 –