static Boolean[][] squares = new Boolean[32][32];
static BitmapFactory.Options opts = new BitmapFactory.Options();
public static Boolean[][] getFrame(int id){
opts.inPreferredConfig = Bitmap.Config.ALPHA_8;
opts.outHeight = 32;
opts.outWidth = 32;
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.raw.f11, opts);
for (int y = 0; y < 32; y++) {
for (int x = 0; x < 32; x++) {
int pixel = bmp.getPixel(x, y);
if(pixel == -1)
squares[x][y] = false;
else
squares[x][y] = true;
}
}
return squares;
}
我在這裏有一個問題,位圖工廠似乎沒有正確導入我的位圖。以下是the original的外觀,what getPixel(和getPixels)返回給我。這發生在沒有任何選項的情況下。我想知道爲什麼它以2倍分辨率導入圖片的2rds。我已經嘗試了1位和4位位圖以及聲明1位和4位Bitmap.Config。使用布爾數組數據在畫布上的網格中繪製矩形。提前致謝。奇怪的位圖工廠行爲(安卓)
啊我應該提到這部分,做了某種自定義的虛擬屏幕,它顯示在畫布上的矩形的32×32格,使用它是數據的布爾數組,true是一個空方塊。這使得它與屏幕尺寸無關。和一個getPixel問題給我這些奇怪的價值。 – Dennis 2012-03-31 18:39:58