我有一个表示位图图像的 Base64 字符串。
我需要再次将该字符串转换为位图图像,以便在我的 Android 应用程序的 ImageView 上使用它
怎么做?
这是我用来将图像转换为 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);
原文由 NullPointerException 发布,翻译遵循 CC BY-SA 4.0 许可协议
您基本上可以使用其他一些内置方法来恢复您的代码。