BitmapRegionDecoder reading OBB using APK Expansion ZIP Library

108 Views Asked by At

I'm trying to read a bitmap from an OBB file using BitmapRegionDecoder together with the APK expansion Zip Library as follows.

ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(cont,1, 1);
AssetFileDescriptor assetFileDescriptor = expansionFile.getAssetFileDescriptor(id);
FileDescriptor fileDescriptor = assetFileDescriptor.getFileDescriptor();
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(fileDescriptor, false);

To my surprise the BitmapRegionDecoder throws an IOException and I don't know why. When using an InputStream as follows the BitmapRegionDecoder has no problem reading the requested bitmap region.

InputStream fileStream = expansionFile.getInputStream(id);
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(fileStream, false);

I rather not use an InputStream since I have to tile a very large image and therefore would have to create a new stream for every tile (since I don't know how to "rewind"). This seems to invoke garbage collection very often. For now my best solution is to unzip the files and then read them from there. But that doubles the data size on the device.

Has anyone used BitmapRegionDecoder with OBB files successfully?

0

There are 0 best solutions below