BitmapRegionDecode.decodeRegion,尝试从位图创建图块时出现skia错误
Posted
技术标签:
【中文标题】BitmapRegionDecode.decodeRegion,尝试从位图创建图块时出现skia错误【英文标题】:BitmapRegionDecode.decodeRegion, skia error when trying to create tile from bitmap 【发布时间】:2013-10-07 21:50:48 【问题描述】:您好,我收到一个错误skia:---decoder->decodeRegion 在我尝试使用 BitmapRegionDeocde.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);
【问题讨论】:
【参考方案1】:我在要解码的矩形的定义中有错误。矩形无效。是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));
【讨论】:
以上是关于BitmapRegionDecode.decodeRegion,尝试从位图创建图块时出现skia错误的主要内容,如果未能解决你的问题,请参考以下文章