Instead of using a two-dimensional array, consider using a little bit of for-loop logic and a one-dimensional array with
void getPixels (int[] pixels,
int offset,
int stride,
int x,
int y,
int width,
int height)
This approach should be much more performant than trying to split a one-dimensional array up into two-dimensional arrays, since you'd be converting the pixel data, which seems to be internally stored as int[]
, to an int[][]
, only to simplify your logic slightly.
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int row = 0; row < bitmap.getHeight(); row++)
for (int column = 0; column < bitmap.getWidth(); column++)
Color color = Color.valueOf(pixels[row * bitMap.getWidth() + column]);
Have a look at the Android Developers reference for Bitmap.getPixels(int[], int, int, int, int, int, int) and Color.valueOf(int) (to extract single color components, Color.alpha(int), Color.red(int), Color.green(int) and Color.blue(int) respectively).