0
votes

I am getting an OOM error from loading a large bitmap using BitmapFactory.decodeResource. I have seen other suggestions about compressing the image but for my app, preserving quality is absolutely necessary. Eventually I need to get the image into a byte/pixel array. Is there any way to get all of the pixels into an array without having to reduce quality or 'tile' the bitmap?

Also, I don't need to keep the bitmap, only the byte array (or an array of pixels). The code I'm writing will search the array. It will all eventually be implemented into a more complex app (written by someone else, hence my inexperience with android).

1
How big an image are we talking about, and how much memory is the rest of your app using? - Gabe Sechan
Why not treat the bitmap file as a file and use more traditional methods of reading it with FileInputStream and the like? - Grambot
At the moment the app isn't using any. It is a 3.5mb jpeg (3200x2500). When saved as a bmp it comes out to nearly 25mb. Perhaps I should uncompress it in memory? - user3727843
@TheCapn would it work to create a FileInputStream and then read 3/4 bytes at a time for each pixel? I was unaware of FileInputStream. - user3727843
You will make a loop where you read a reasonable amount from the input stream, say 65534 bytes, and add to the byte array until done. Don't fiddle around with 4 bytes as it slows all down. - greenapps

1 Answers

0
votes

Take a look at android's documentation on handling large bitmaps http://developer.android.com/training/displaying-bitmaps/load-bitmap.html