我从数据库中获取一个表示图像的字符串。我想再次将其转换为图像,因此首先将其制作为字节数组,然后尝试对其进行解码。发生的事情是由于某种原因它返回null,但实际情况并非如此。我打印了数组的大小,以查看转换中是否有错误,但是那里没有任何问题。
private fun imageBit(image: String): Bitmap{
val b = image.toByteArray()
d("DEBUG2", "${b.size}") //prints 47109
val ins = ByteArrayInputStream(b)
d("DEBUG3", "${ByteArrayInputStream(b).readBytes().size}") //prints 47109
return BitmapFactory.decodeStream(ins)
}
试试看:
private fun imgBit(image: String): Bitmap{
val imgBytes = Base64.decode(image, 0)
return BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.size)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句