将图像转换为二维数组仅获取左上象限

Converting image to 2d array gets only top left quadrant

我正在 Android 中制作一个程序动画,它应该只拍摄一张 720x720 的图像,将其转换为二维颜色数组,然后单独绘制每个像素。我的代码的问题是它只需要左上象限并将其显示为整个图像,我无法弄清楚如何修复它。
代码、源图像和结果在这里:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new DrawPixels(this, 720, 720));

    }
} 


public class DrawPixels extends View {
    public int[][] image_array;
    Bitmap frame;
    Bitmap photo;
    Canvas frameDrawer;
    Rect bounds;
    Paint lp;
    int width , height;
    int x = 0;
    int y = 0;
    int radius = 3;

    public DrawPixels(Context context , int width, int height) {
        super(context);
        photo = BitmapFactory.decodeResource(context.getResources(), R.drawable.marilyn2);
        image_array = imageTo2dArray(photo);

        this.width = width;
        this.height = height;

        frame = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
        frameDrawer = new Canvas(frame);
        bounds = new Rect(0 , 0, width,height);

        lp = new Paint();
        lp.setStyle(Paint.Style.FILL);

    }

    @Override
    protected void onDraw(Canvas canvas){
        super.onDraw(canvas);

        if (x < 720 && y < 720) {
            lp.setColor(image_array[x][y]);
            frameDrawer.drawCircle(x, y, radius, lp);
        }

        canvas.drawBitmap(frame, null, bounds , null);

        //sampling every 5th pixel
        if (x < 720){
            if(y < 720){
                y += 5;
            }else{
                y = 0;
                x += 5;
            }
            invalidate();
        }
    }


    public int[][] imageTo2dArray(Bitmap bm){
        int[][] arr = new int[720][720];
        int p, a, r, g, b, avg;
        for(int i = 0; i < 720; i++) {
            for (int j = 0; j < 720; j++) {
                arr[i][j] = bm.getPixel(i, j);
            }
        }
        return  arr;
    }
}


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="d.androidnewcomer.drawing.MainActivity">

</android.support.constraint.ConstraintLayout>

marilyn2.png:

结果:

最可能的原因是 BitmapFactory.decodeResource 缩放位图,使其不再是 720x720 而是 1440x1440。

参见:BitmapFactory.decodeResource Bitmap not original size in pixels