I am trying to read an image from the resource folder in my app and put it in a bitmap so i can do with it what i need. When reading images larger than ~ 1mb i get this:
E/Binder ( 3568): java.lang.OutOfMemoryError
E/Binder ( 3568): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/Binder ( 3568): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
E/Binder ( 3568): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
E/Binder ( 3568): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:445)
E/JavaBinder( 3568): Caused by: java.lang.OutOfMemoryError
E/JavaBinder( 3568): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
E/JavaBinder( 3568): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
E/JavaBinder( 3568): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
E/JavaBinder( 3568): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:445)
Is there a safer way to get these kind of images ? And i do not want to scale them down i just need to read the image as is.
Edit 1:
i am using this code :
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), id, options);
options.inSampleSize = 1;
options.inScaled = false;
options.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeResource(res, id, options);
i do not want to downsize the inSampleSize. i want to preserve the initial resolution but put the image into a bitmap. Can this be done with images above 2 mb in size and a width of 7000 px and height of 2400 px ?
Edit 2:
I've managed to bypass the error by using android:largeHeap="true", but surely there should be another solution to this ...