嗨我得到一个错误skia:--- decoder-> decodeRegion当我尝试使用BitmapRegionDeocde.decodeRegion解码第二个区域时返回false。我设法得到第一个区域位图,但是如果第二个区域得到null。
如何在不收到此错误的情况下设置获取所有区域的位图?
以下是我的代码示例:
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);
}
}
答案 0 :(得分:3)
我在解码的rect定义中有错误。 Rect无效。那是Rect rect = new Rect(i * DEFAULT_TILE_WIDTH, j * DEFAULT_TILE_HEIGHT, DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT);
但如果必须是Rect rect = new Rect(i * DEFAULT_TILE_WIDTH, j * DEFAULT_TILE_HEIGHT, DEFAULT_TILE_WIDTH * (i+1), DEFAULT_TILE_HEIGHT * (j+1));