2
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?

asked Jun 18, 2015 at 9:31
1
  • Use universal image loader to load too large image Commented Jun 18, 2015 at 9:32

3 Answers 3

2

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.

answered Jun 18, 2015 at 9:39
Sign up to request clarification or add additional context in comments.

2 Comments

@dhuma1981 Can you explain why ImageLoader library is prefered over "direct" loading of an image?
So many reasons, easy to implement, no need to worry about asynchronization, automatic memory handling and caching.
0

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);
answered Jun 18, 2015 at 9:40

Comments

0

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 ;)

answered Jun 18, 2015 at 9:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.