0
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。使用布尔数组数据在画布上的网格中绘制矩形。提前致谢。

4

2 回答 2

0

我想你注意到它在屏幕上?如果是这样,ImageView 的 xml 是什么?也许您无意中设置了错误的宽度或高度?

于 2012-03-31T18:35:35.330 回答
0

可能是一个迟到的答案,但我会尝试

opts.inScaled = false;
于 2015-01-15T19:19:51.890 回答