2010-01-11 62 views

回答

3

您可以使用此功能:

Bitmap[] splitImage(Bitmap bitmap, int rCnt, int cCnt) { 
    Bitmap[] result = new Bitmap[rCnt * cCnt]; 
    int w = bitmap.getWidth()/cCnt; 
    int h = bitmap.getHeight()/rCnt; 
    for (int i = 0; i < rCnt; i++) 
     for (int j = 0; j < cCnt; j++) { 
      Bitmap bitmapPart = new Bitmap(w, h); 
      Graphics g = new Graphics(bitmapPart); 
      g.drawBitmap(0, 0, w, h, bitmap, w * j, h * i); 
      result[i * cCnt + j] = bitmapPart; 
     } 
    return result; 
} 

看看的Puzzle game for BB on Google Code

+0

感謝您的回答最多完整的源代碼。這非常有幫助。 – 2010-01-12 13:46:26

+0

不客氣! – 2010-01-12 15:51:11