SOLVED. How to access pixels of a Bitmap image on Android?

You won't be able to access the pixel at (getWidth(),getHeight()) in any image because like everything else they are 0-indexed. The valid range of pixels is (0 to getWidth()-1, 0 to getHeight()-1), and thus the bottomrightmost pixel is obtained by b. GetPixel(b.getWidth()-1, b.getHeight()-1).

Up vote 1 down vote favorite 1 share g+ share fb share tw.

In short I am unable to access all the pixels of a bitmap image. I have used an intent to fire the native Camera app and returned a Bitmap image to my application activity. The data is definitely a bitmap object and I am able to display, get the height/width etc and access some pixels using getPixel().

However when I use the values of getHeight() and getWidth() I get an array out of bounds error. By trail and error I have found I can only access a reduced number of pixels of the image, for example with one image which returned a height and width value of 420,380, I could also access 200,100. I then do some image processing and used setPixel() on the original image.

When I display the image it shows the, say 200,100, processing pixels and the rest normal, therefore the pixels are obviously there and accessible by android but not by me. I have to spoken to other people who have also had this problem with images. Does anyone know anything more about this, reasons?

Or a work around? Many thanks in advance. It seems that there's no way around this, does anyone think it would be better/possible to access the image directly in memory maybe using the NDK?

Android image pixel link|improve this question edited Dec 19 '10 at 15:26 asked Nov 20 '10 at 15:04James Burnstone97110 100% accept rate.

Thanks for the reply, Yeah I'm aware of 0-indexed, the problem is I cant access well over half of the pixels. Basically I have some nested for loops (int y = 0;y – James Burnstone Nov 20 '10 at 16:06.

Got an answer from Albert Pucciani on the Android forums. I now create an int buffer and copy the pixels to it, then use get() and put() to extract the pixels. It's also much quicker to use get() and put() instead of the get/setPixel() from the Bitmap class.

Need to test now whether this does return all the pixels to the buffer for all images. After more testing I have discovered this is simply a memory issue as the amount allocated for each process includes all bitmaps.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions