获得Android的位图的像素颜色 [英] get pixel color from bitmap android

查看:231
本文介绍了获得Android的位图的像素颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to check the color of pixels in a section of a bitmap. I need to determine at what position the black pixels start. Here is my implementation.

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

Unfortunately the getPixel method always returns 0

推荐答案

这应该发现的第一列(左起)含有黑色像素:

This should find the first column (from left) containing a black pixel:

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

这篇关于获得Android的位图的像素颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆