user2632275
user2632275

Reputation: 3

Android outofmemory while loading image from Assest

I am facing outofmemory while trying to load bitmap image from Assest, Below is my code:

AssetManager assetManager = context.getAssets();

InputStream istr = assetManager.open(FILE_NAME);
bitmap = BitmapFactory.decodeStream(istr);

I am getting below exception most of time I am loading the image:

ERROR/AndroidRuntime(731): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

I have gone throw few articles on managing image size in ImageView. But my code not reaching to that point even.

Please Help

Upvotes: 0

Views: 79

Answers (2)

Sanket Shah
Sanket Shah

Reputation: 4382

Just add following code to your manifest

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:theme="@style/AppTheme" />

Upvotes: 0

Changwei Yao
Changwei Yao

Reputation: 13101

I guess the resolution is very big.

You should read the size first, and scale it before load it to the memory.

the best practice for this

Loading Large Bitmaps Efficiently

Upvotes: 2

Related Questions