0

嗨,我收到一个错误skia:--- 当我尝试使用 BitmapRegionDeocde.decodeRegion 解码第二个区域时,decoder->decodeRegion 返回 false。我设法获得第一个区域位图,但如果第二个区域为空。

如何在不出现此错误的情况下获取所有区域的位图?

这是我的代码示例:

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);
    }




}
4

1 回答 1

3

我在要解码的矩形的定义中有一个错误。矩形无效。它是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));

于 2013-10-08T08:10:51.507 回答