user4916582
user4916582

Reputation:

JPEG File seems to big: OutOfMemoryError

java.lang.OutOfMemoryError: Failed to allocate a 313194252 byte allocation with 11901284 free bytes and 174MB until OOM

I got this at this line:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.handskizze);

My Picture has a size of 2480*3508 at 300dpi. Is it maybe to big? How can I make it smaller?

Upvotes: 2

Views: 90

Answers (3)

W3hri
W3hri

Reputation: 1591

First of all, i would say your image is way too big for mobile devices. You should scale it down using Photoshop (or any other image editing software) to reduce its size. By doing so you minimize the size of your .apk and the processing time it takes to downscale the image.

Additionally, i would recomment you to use an image loader library. Im using the Universal Image Loader in most of my projects. It gets the measurement of the ImageView you want to load your image into, and downscales the image to reduce its size. You should give it a try ;)

Upvotes: 0

Santosh Kathait
Santosh Kathait

Reputation: 1444

In manifest use below attribute with application tag

android:largeHeap="true"

Also use

BitmapFactory.Options o=new BitmapFactory.Options();
o.inSampleSize = 2; //change value from 0 to 8 as per need and image resolution
myBitMap=BitmapFactory.decodeResource(getResources(),R.drawable.handskizze, o);

Upvotes: 0

Dhrumil Shah - dhuma1981
Dhrumil Shah - dhuma1981

Reputation: 15789

Whenever there is a requirement to load any image always try to use any ImageLoader library.

There are plenty of options available.

Here are some of the best libraries that developers uses. Try anyone of them which you fill easy to implement.

You can find some more libraries but I feel these 3 are used most.

Upvotes: 2

Related Questions