3

I am new to Android and need to process a bitmap to extract the pixel information into a multi-dimensional array by collecting only the black pixels i.e. R = 0, G = 0, and B = 0. I noticed that there is a GetPixel(x, y) method which is apparently slow and I need something like this instead. But I'm lost on how to implement a better GetPixel(x, y) method using information from GetPixels(). I am trying something like this currently:

private static int[][] GetPixels(Bitmap bmp)
{
    int height = bmp.getHeight();
    int width = bmp.getWidth();
    int length = width * height;
    int[] pixels = new int[length];
    bmp.getPixels(pixels, 0, 0, 0, 0, width, height);
    int[][]result = new int[width][height];
    for(int pixel = 0, x = 0, y = 0; pixel < pixels.length; pixel += 4)
    {
        int argb = pixels[pixel];//how to access pixel information?
        result[x][y] = argb;//store only black pixels??
        x++;
        if(y == width)
        {
            x = 0;
            y++;
        }
    }
    return result;
}
Community
  • 1
  • 1
rtuner
  • 2,362
  • 3
  • 25
  • 37
  • You're getpixels is a bit wrong atm. It needs the width variable at the second argument. I use getpixels() from the Bitmap library and it's fine for speed. Best not to worry about optimizing until you need it. Maybe for speed you could use the raw YUV data instead of converting to RGB. I have used it to quickly get the grayscale. – James Burnstone Nov 05 '13 at 15:45
  • Hi @JamesBurnstone, you could post how to do it using raw YUV data. Can't really figure it out. Thanks. – rtuner Nov 22 '13 at 10:30
  • @JamesBurnstone: What do You mean by raw YUV data? What reading the pixels of a bitmap have to do with the picture from camera? How come You know the OP needs luminance? – Rekin Jan 06 '14 at 10:21
  • Sorry, I confused this with someone needing the camera input not just a bitmap image. Obviously then there is no yuv data, my mistake. – James Burnstone Jan 06 '14 at 13:56

0 Answers0