【问题标题】:get pixel color from bitmap android从位图android获取像素颜色
【发布时间】:2015-01-20 22:37:05
【问题描述】:

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

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

【问题讨论】:

  • 您确定 SavePixels(0, 0, screenWidth, screenHeight, gl) 方法的结果吗?尝试将此位图保存在文件中并检查其中的内容
  • 您的Bitmap 正确吗?您是否尝试过使用 Color.RGBToHSV() 将 ARGB 颜色转换为 HSV 仅用于测试目的?
  • 是的,我将位图保存在设备上以确保我没有空白图像。位图正确
  • 你需要找到第一个黑色像素的行还是列?
  • 我要找栏目

标签: android android-bitmap


【解决方案1】:

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

    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;
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    • 2014-12-06
    • 1970-01-01
    相关资源
    最近更新 更多