如何在Kotlin Android中将base64字符串转换为图像 [英] How to convert base64 string into image in kotlin android

查看:500
本文介绍了如何在Kotlin Android中将base64字符串转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Base64 String that represents a BitMap image.

我需要再次将该String转换为BitMap图像,以便在我的Android应用中的ImageView上使用它

I need to transform that String into a BitMap image again to use it on a ImageView in my Android app

该怎么做?

推荐答案

您可以使用以下代码进行解码:-

You can use this code to decode: -

val imageBytes = Base64.decode(base64String, Base64.DEFAULT)
val decodedImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length)
imageView.setImageBitmap(decodedImage)

这篇关于如何在Kotlin Android中将base64字符串转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆