2013-10-07 40 views
0

您好,我收到一個錯誤skia:--- decoder-> decodeRegion返回false當我嘗試解碼與BitmapRegionDeocde.decodeRegion第二個區域。我設法得到第一個區域位圖,但如果第二個區域爲空。BitmapRegionDecode.decodeRegion,試圖從位圖創建平鋪時skia錯誤

如何獲得我所有區域的位圖而不會出現此錯誤?

這裏是我的代碼示例:

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




} 

回答

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