How to convert a Base64 string into a Bitmap image to show it in a ImageView?

問題:

I have a Base64 String that represents a BitMap image.我有一個代表位圖圖像的 Base64 字符串。

I need to transform that String into a BitMap image again to use it on a ImageView in my Android app我需要再次將該字符串轉換爲位圖圖像,以便在我的 Android 應用程序中的 ImageView 上使用它

How to do it?怎麼做?

This is the code that I use to transform the image into the base64 String:這是我用來將圖像轉換爲 base64 字符串的代碼:

//proceso de transformar la imagen BitMap en un String:
//android:src="c:\logo.png"
Resources r = this.getResources();
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.logo);
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
bm.compress(Bitmap.CompressFormat.PNG, 100, baos); //bm is the bitmap object   
byte[] b = baos.toByteArray();
//String encodedImage = Base64.encode(b, Base64.DEFAULT);
encodedImage = Base64.encodeBytes(b);

解決方案:

參考一: https://en.stackoom.com/question/KILu
參考二: https://stackoom.com/question/KILu
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章