This is how you can use BitmapFactory.Options
:
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inSampleSize = 2;
options.inJustDecodeBounds = false;
options.inTempStorage = new byte[16 * 1024];
Bitmap bmp = BitmapFactory.decodeFile(picturePath,options);
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bmp, 960, 730, false);
Also you can calculate the inSampleSize
for your bitmap by writing a custom function.
Here's google documentation : http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
You Can increase the Memory allotted to your application by adding android:largeHeap="true"
in manifest.
Note : Increasing heap
for your application doesn't considered to be a ideal solution.
Here's the extract from google that explains it,
However, the ability to request a large heap is intended only for a
small set of apps that can justify the need to consume more RAM (such
as a large photo editing app). Never request a large heap simply
because you've run out of memory and you need a quick fix—you should
use it only when you know exactly where all your memory is being
allocated and why it must be retained. Yet, even when you're confident
your app can justify the large heap, you should avoid requesting it to
whatever extent possible. Using the extra memory will increasingly be
to the detriment of the overall user experience because garbage
collection will take longer and system performance may be slower when
task switching or performing other common operations.
here's the complete link of the documentation https://developer.android.com/training/articles/memory.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…