I have tried working with a bit of code to decode a file from SD and then edit it. Because of this editing that needs to be done, keeping a higher scaled image is important. Some phones run into memory issues, whereas others have enough room in their heap to continue the decode without a set option.
//the following is ending a process in which a photo is taken and saved
//under "/sdcard/folder/photo.png"
FileOutputStream fos= new FileOutputStream(photo.getPath());
fos.write(jpeg[0]);
fos.close();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap originalFile = BitmapFactory.decodeFile("/sdcard/folder/photo.png",options);
I am basically looking into whether there is a way to almost set an if statement to put the option into place (if needed) otherwise continue without it.
As a workaround, wrap decoding into a try-catch and if “out of memory” exception happen, just catch it and try decode with properly set inSampleSize.
However, this looks more like a hack than a solution.
Basically, you need to know how much memory your decoded bitmap will take and how much memory is available for your application’s heap to grow in the system right now.
First is easy to find out: width*height*4 bytes (by default decoding is in ARGB8888).
But I have no idea how to get the heap’s memory size.