Android BitMapRegionCode.decodeRegion,尝试从位图创建平铺时出错
您好,我收到一个错误skia:---decoder->decodeRegion在我尝试使用BitMapRegionDecodeRegion解码第二个区域时返回false。我设法得到第一个区域位图,但是如果得到第二个区域的null 如何在不出现此错误的情况下获取所有区域的位图 以下是我的代码示例:Android BitMapRegionCode.decodeRegion,尝试从位图创建平铺时出错,android,bitmap,skia,bitmapregiondecoder,Android,Bitmap,Skia,Bitmapregiondecoder,您好,我收到一个错误skia:---decoder->decodeRegion在我尝试使用BitMapRegionDecodeRegion解码第二个区域时返回false。我设法得到第一个区域位图,但是如果得到第二个区域的null 如何在不出现此错误的情况下获取所有区域的位图 以下是我的代码示例: public void createTiles(String fileAssetPath) { mfileAssetpath = fileAssetPath; try {
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);
}
}
public void createTiles(字符串fileAssetPath){
mfileAssetpath=文件AssetPath;
试一试{
BufferedInputStream is=新的BufferedInputStream(getContext().getAssets().open(mfileAssetpath));
BitMapRegionCoder解码器=BitMapRegionCoder.newInstance(is,true);
mbitmapheght=decoder.getHeight();
mBitmapWidth=decoder.getWidth();
// ************
瓷砖[]矩形;
int width=decoder.getWidth();
int height=decoder.getHeight();
int nbSameDimTile=0;
int nbEvenWidthTile=0;
int nbEvenHeightTile=0;
最终int nbPartWidth=宽度/默认瓷砖宽度;
最终int nbPartHeight=高度/默认瓷砖高度;
最终int moduloWidth=宽度%默认值\u瓷砖\u宽度;
最终整数模高=高度%DEFAULT\u TILE\u高度;
nbSameDimTile=nbPartWidth*nbPartHeight;
如果(模数高度>0)
nbEvenWidthTile=nbPartWidth;
如果(模块宽度>0)
nbevenheighttle=nbPartHeight;
//rects=新Rect[nbSameDimTile+nbEvenWidthTile+
//nbEvenHeightTile];
rects=新磁贴[nbSameDimTile];
int指数=0;
对于(int i=0;i
我在要解码的rect的定义中有一个错误。Rect无效。它是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度,默认瓷砖高度)代码>
但是如果必须是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度*(i+1),默认瓷砖高度*(j+1))代码>我在要解码的rect的定义中有一个错误。Rect无效。它是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度,默认瓷砖高度)代码>
但是如果必须是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度*(i+1),默认瓷砖高度*(j+1))代码>我在要解码的rect的定义中有一个错误。Rect无效。它是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度,默认瓷砖高度)代码>
但是如果必须是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度*(i+1),默认瓷砖高度*(j+1))代码>我在要解码的rect的定义中有一个错误。Rect无效。它是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度,默认瓷砖高度)代码>
但是如果必须是Rect Rect=new Rect(i*默认瓷砖宽度,j*默认瓷砖高度,默认瓷砖宽度*(i+1),默认瓷砖高度*(j+1))代码>