2017-08-02 80 views
1

我解码数据从ByteBuffer来像:BitmapFactory.decodeByteArray(inputData.array(), 0, inputData.limit());BitmapFactory.decodeByteArray从ByteBuffer.array()进行解码的数据时,则返回null

相同的代码工作正常上较旧的Android(4.3例如),但在Android 7我收到错误"D/skia (14391): --- SkImageDecoder::Factory returned null",返回的图像为空。

图像数据从jpg文件正确加载。 ByteBuffer也有正确的位置和限制。

我读了大部分与BitmapFactory.decodeByteArray相关的类似问题,但似乎没有一个类似于我的场景。

回答

0

看来,如果我第一次从ByteBuffer读取数据到数组中,然后提供这些数据,BitmapFactory.decodeByteArray就能够正确解码图像。我错过了ByteBuffer数据实际启动的backing数组内的偏移量。

所以正确的代码是:

Bitmap im = BitmapFactory.decodeByteArray(inputData.array(), inputData.arrayOffset(), inputData.limit());