1
我需要在運行時從較大的圖像創建一個新的更小的圖像。較小的圖像大小是固定的(正方形),代表較大圖像的特定區域(較小的圖像是較大圖像的子集)。圖像格式不重要。黑莓手機 - 如何從較大的圖像創建一個子圖像?
謝謝。
我需要在運行時從較大的圖像創建一個新的更小的圖像。較小的圖像大小是固定的(正方形),代表較大圖像的特定區域(較小的圖像是較大圖像的子集)。圖像格式不重要。黑莓手機 - 如何從較大的圖像創建一個子圖像?
謝謝。
您可以使用此功能:
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;
}
感謝您的回答最多完整的源代碼。這非常有幫助。 – 2010-01-12 13:46:26
不客氣! – 2010-01-12 15:51:11