Android 画布绘制对象上的getPixels和setPixels

Android 画布绘制对象上的getPixels和setPixels,android,Android,我已经在自定义视图上创建了一条从屏幕的一个角到另一个角的对角线白线- canvas.drawLine(0, 0, MainActivity.width+10, MainActivity.height, paint); 我知道如何在位图上获取像素和设置像素,就像这样- public Bitmap generateAlphaMask(Bitmap bmpTop,Bitmap bmpBottom) { int width = bmpTop.getWidth(); int height

我已经在自定义视图上创建了一条从屏幕的一个角到另一个角的对角线白线-

canvas.drawLine(0, 0, MainActivity.width+10, MainActivity.height, paint);
我知道如何在位图上获取像素和设置像素,就像这样-

public Bitmap generateAlphaMask(Bitmap bmpTop,Bitmap bmpBottom) {
    int width = bmpTop.getWidth();
    int height = bmpTop.getHeight();

    boolean[][] res = new boolean[width][height];
    int[] colors = new int[width * height];
    bmpTop.getPixels(colors, 0, width, 0, 0, width, height);

    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            int cell = y * width + x;
            int redVal = Color.red(colors[cell]);
            int greenVal = Color.green(colors[cell]);
            int blueVal = Color.blue(colors[cell]);

            int alpha = Color.alpha(colors[cell]);

            res[x][y] = alpha == ALPHA_THRESHOLD;

            if (res[x][y]) {
                bmpBottom.setPixel(x, y, Color.TRANSPARENT);
            }
        }
    }

    return bmpBottom;
}
公共位图生成页面掩码(位图bmpTop、位图bmpbotom){
int width=bmpTop.getWidth();
int height=bmpTop.getHeight();
布尔[][]res=新的布尔值[宽度][高度];
int[]颜色=新int[宽度*高度];
获取像素(颜色,0,宽度,0,0,宽度,高度);
对于(int x=0;x
但我想存储画布上像素的位置,其中像素是“非白色的”。 帮我解决这个问题