繁体   English   中英

从位图android获取像素颜色

[英]get pixel color from bitmap android

我想检查位图部分中像素的颜色。 我需要确定黑色像素从什么位置开始。 这是我的实现。

Bitmap bmp = SavePixels(0, 0, screenWidth, screenHeight, gl);
for(int i = 0; i < 100; i++){
    for(int x = 0; x < 50; x++){
        //Log.i(EJ.TAG, i+","+x);
        int pixel = bmp.getPixel(i,x);
        if(pixel == Color.BLACK){
            cordinate = i;
            Log.i(EJ.TAG, i+","+x);
            break;
        }
    }
}

不幸的是,getPixel方法总是返回0

这应该找到包含黑色像素的第一列(从左开始):

    Bitmap bmp = SavePixels(0, 0, screenWidth, screenHeight, gl);
    boolean found = false;
    for(int x = 0; x < 50 && !found; x++){
        for(int y = 0; y < 100 && !found; y++){
            int pixel = bmp.getPixel(x, y);
            if(pixel == Color.BLACK){
                cordinate = x;
                found=true;
            }
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM