欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

android 字符串转bitmap,android – 如何将Base64字符串转换为BitMap图像显示在ImageView?...

发布时间:2024/10/8 编程问答 32 豆豆
生活随笔 收集整理的这篇文章主要介绍了 android 字符串转bitmap,android – 如何将Base64字符串转换为BitMap图像显示在ImageView?... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我有一个Base64字符串,表示一个BitMap图像。

我需要将该字符串转换为BitMap图像,以使用它在ImageView在我的Android应用程序

怎么做?

这是我用来将图像转换为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);

总结

以上是生活随笔为你收集整理的android 字符串转bitmap,android – 如何将Base64字符串转换为BitMap图像显示在ImageView?...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。