I'm trying to do some image processing in Android. I need to get a chunk of pixel information of a bitmap. So I tried to use one of the Bitmap class method getPixels(). However, it seems like I'm not using it correctly or I misunderstood of the sole purpose of the method's behaviour.
For example, I'm doing the following in order to get pixel information of a 10 by 10 region of a bitmap from an arbitrary location(bitmap coordinate) x, y.
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
int[] pixels = new int[100];
bitmap.getPixels(pixels, 0, bitmap.getWidth(), x, y, 10, 10);
And I'm getting ArrayIndexOutOfBoundsException. I've been Googling around to see what I'm doing wrong, but I'm clueless. Most of the examples or questions regarding the use of getPixels() are usually for the case of extracting pixel information of the entire image. Hence the size of the int array is usually bitmap.getWidth()*bitmap.getHeight(), x and y values are 0, 0, and the width, height is bitmap's width and height.
Is Bitmap's getPixels() not designed for the purpose of my use(getting a chunk of pixel information of a sub-region of the bitmap)? Or am I using it incorrectly? Is there an alternative way to do this, perhaps using a different class?
I would appreciate it if anyone has something to say about this. Thanks.