0

I have an image on which I want to process pixel number 159 and 160 specifically. I am running this code but it gives me ArrayIndexOutOfBoundsException. I think the way I have declared that array that is the problem.

int[] twoPositions = {159, 160};
bitmap.GetgetPixels(twoPositions, 0, width, 0, 0, width, height); //exception line (ArrayIndex....)

how to declare array in a way which will give me 0 row, 159th and 160th column pixel? thank you in advance...

Aalap Patel
  • 2,058
  • 2
  • 17
  • 31
  • Assuming that's supposed to be the `Bitmap#getPixels()` method, you're not using it correctly. Instead, use the `Bitmap#getPixel(int x, int y)` method. – Mike M. Mar 27 '16 at 06:45
  • getPixel is useful when I want one pixel here I want two pixels (0, 159) and (0, 160).. – Aalap Patel Mar 27 '16 at 07:04
  • Why don't you just call it twice, if you only need two pixels? If you really want to use `getPixels()`, you should refer to the docs to see how it's used: `bitmap.getPixels(twoPositions, 0, width, 159, 0, 2, 1);`. You don't need to initialize any values in the array. – Mike M. Mar 27 '16 at 07:42
  • yes that option i tried and working well just wanted to see if it works this way or not... thank you for the guidance... – Aalap Patel Mar 27 '16 at 15:35
  • Ah, gotcha. Can't blame ya for wanting to learn something new. Cheers! – Mike M. Mar 27 '16 at 15:38

0 Answers0