ByteArray 可以使用 UIImage 在 swift 中显示为图像,但在 Kotlin 中使用 BitmapFactory.decodeByteArray 则不能显示为图像

ByteArray can be shown as image in swift using UIImage, but not in Kotlin using BitmapFactory.decodeByteArray

提问人:kenmaro 提问时间:10/31/2023 更新时间:10/31/2023 访问量:24

问:

我正在使用 Swift 和 Kotlin 从 NFC 适配器读取一些字节数组对象, 然后我遇到了一个问题。

按照协议,我得到了长度为 1983 的字节数组,它存储在 [UInt8] 中,只需传递

let uiImage = UIImage(data: data)

但是,在 Kotlin(Android 应用程序)中,我无法显示与

var bitmap = BitmapFactory.decodeByteArray(data, 0, data.size, BitmapFactory.Options())

现在这个位图是空的,只是显示

--- Failed to create image decoder with message 'unimplemented'
java.lang.NullPointerException: bitmap must not be null

我有点困惑是什么原因造成的..

如果有人有任何想法或建议,我将不胜感激,谢谢!

数组 swift kotlin jpeg

评论

0赞 Hezy Ziv 10/31/2023
在调用 BitmapFactory 之前是否检查数据对象是否为 null?分享你的 Kotlin 代码
0赞 kenmaro 10/31/2023
谢谢你的评论,我一直想知道出了什么问题,然后我就想通了。我正在处理JPEG2000编码的字节字符串,因此我需要使用此库 github.com/ThalesGroup/JP2ForAndroid/tree/master 进行解码。干杯

答: 暂无答案