Android Kotlin:以字节码显示图像

问题描述 投票:0回答:1

我正在使用Kotlin前端/ Python后端构建应用程序,并且我想显示字节码形式的图像。我的python脚本使用BytesIO()(https://docs.python.org/3/library/io.html#io.BytesIO)返回图像的字节码(例如<_io.bytesio object at>),我想使用kotlin显示其图像。

这甚至可能吗?如果是这样,如何将图像值分配给例如imageView id?样例代码将不胜感激。

谢谢。

android kotlin android-imageview
1个回答
0
投票

//可选代码

  val bmp = BitmapFactory.decodeResource(resources, R.drawable.person)
val stream = ByteArrayOutputStream()
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream)

//分配从Seerver到byteArray的字节

val byteArray: ByteArray = stream.toByteArray()
val bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
imageView.setImageBitmap(bitmap)
© www.soinside.com 2019 - 2024. All rights reserved.