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;
}
我在这里遇到问题,位图工厂似乎没有正确导入我的位图。这是原始的样子,这是 getPixel(和 getPixels)返回给我的。无论是否声明任何选项,都会发生这种情况。我想知道为什么它似乎是以 2x 分辨率导入图片的 2rds。我尝试过 1 位和 4 位位图以及声明 1 位和 4 位 Bitmap.Config。使用布尔数组数据在画布上的网格中绘制矩形。提前致谢。