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