I'm still wrapping my head around how bitmaps work on Android. My current situation is - I'm trying to display a gridview of images but I get out of memory errors around 8 or so pictures.
The way I do it now is I'm using a custom camera (extending surfaceview and implementing surfaceholder.callback) to take a picture, decoding the byte array from the onPreviewFrame method using the YUV420SP conversion function into an int[] array and then creating a bitmap from that array. There are two reasons I'm doing this, 1. to save the stream into a blob within a sqlite db to transfer to a server at a later time, and 2. to avoid saving it as a jepg in the phone that can be altered with.
If there are better ways to do this I'm open to hearing about it, but for now I'm looking for an answer that'll help me shrink down the image size when I display it after calling it from the database, or before saving it to the database. I've looked at other threads on this topic but everything I've seen so far requires saving it as a jpeg and then using bitmapfactory.options to decode the file location into a bitmap. Does anyone know a way to use the options directly with the byte array parameter given or even after converting it using YUV420SP?
Let me know if any more clarification is needed.
So the problem is you did not scale down the image before displaying them into GridView, so while you create Bitmap from those int[], you should create a scale down version of the Bitmap before displaying them.
There will be something like this:
NOTE: I have NOT tested the code, but I am pretty confident it should work fine. For better performance, all these should be ran in the background thread.