1

I'm working on a tablet app. I tried to set high-resolution (2223x3553) images as background using Layout.setBackgroundResource(ResId). The app crashed while testing on Nexus 7, I won't paste the stack traces since there were like 8 or 9 exceptions with about 300 red lines in the LogCat and it took me a while to figure out the reason. I got it after I noticed the OutOfMemoryException, using 1280x800 images the app runs fine but some quality loss has occurred since those images are designed to be high-res.

The question: how to handle high-resolution images in Android to prevent crashes like that? All images are local and stored in the drawable folder

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
Droidman
  • 11,485
  • 17
  • 93
  • 141
  • FYI a bitmap of that height and width will require about 30 megabytes of java heap. – Blackbelt Feb 21 '13 at 09:35
  • @Maver1ck Have you tried the tutorial , You need to calculate the sample size and based on that you need load the image please check the tutorial... – Pragnani Feb 21 '13 at 09:42
  • Nexus-7 is only 1280×800. Your background image is over killed. – Calvin Feb 21 '13 at 09:44
  • You need to resize the image before load it to memory. This answer may be useful for you http://stackoverflow.com/questions/4837715/how-to-resize-a-bitmap-in-android – Ethan Feb 21 '13 at 09:32

2 Answers2

2

You have to use same library that I have used in such a Use Case ,

This project will help you in yours also. Because you need to compress the images while displaying them and also use the capability of lazy loading if you need eventually.

Prateek
  • 3,923
  • 6
  • 41
  • 79
2

Image sizes are limited in android development. You can not use images which are bigger than the prescribed ones. There is a guideline about how to choose images for your application. This is the link to the guidelines.

kittu88
  • 2,451
  • 5
  • 40
  • 80