Hi i get a error skia: --- decoder->decodeRegion returned false when I try to decode a second region with BitmapRegionDeocde.decodeRegion. I manage to get the first region bitmap, but if get null for the second region.
How can I manage to get the bitmap of all my regions without getting this error ?
Here is a sample of my code :
public void createTiles(String fileAssetPath) {
mfileAssetpath = fileAssetPath;
try {
BufferedInputStream is = new BufferedInputStream(getContext().getAssets().open(mfileAssetpath));
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, true);
mBitmapHeight = decoder.getHeight();
mBitmapWidth = decoder.getWidth();
// ************
Tile[] rects;
int width = decoder.getWidth();
int height = decoder.getHeight();
int nbSameDimTile = 0;
int nbEvenWidthTile = 0;
int nbEvenHeightTile = 0;
final int nbPartWidth = width / DEFAULT_TILE_WIDTH;
final int nbPartHeight = height / DEFAULT_TILE_HEIGHT;
final int moduloWidth = width % DEFAULT_TILE_WIDTH;
final int moduloHeight = height % DEFAULT_TILE_HEIGHT;
nbSameDimTile = nbPartWidth * nbPartHeight;
if (moduloHeight > 0)
nbEvenWidthTile = nbPartWidth;
if (moduloWidth > 0)
nbEvenHeightTile = nbPartHeight;
// rects = new Rect[nbSameDimTile + nbEvenWidthTile +
// nbEvenHeightTile];
rects = new Tile[nbSameDimTile];
int index = 0;
for (int i = 0; i < nbPartWidth; i++) {
for (int j = 0; j < nbPartHeight; j++) {
Tile t = new Tile();
Rect rect = new Rect(i * DEFAULT_TILE_WIDTH, j * DEFAULT_TILE_HEIGHT, DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT);
System.out.println("This rect : " + rect);
t.bitmap = decoder.decodeRegion(rect, null);
t.rect = rect;
rects[index] = t;
index++;
}
}
mRects = rects;
// ************
decoder.recycle();
mLoaded = true;
} catch (IOException e) {
mLoaded = false;
Log.e("System.out", "", e);
}
}
I had an error in the definition of the rect to decode. The Rect was invalid. It was
Rect rect = new Rect(i * DEFAULT_TILE_WIDTH, j * DEFAULT_TILE_HEIGHT, DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT);
But if must be
Rect rect = new Rect(i * DEFAULT_TILE_WIDTH, j * DEFAULT_TILE_HEIGHT, DEFAULT_TILE_WIDTH * (i+1), DEFAULT_TILE_HEIGHT * (j+1));