0

I compressed 2 2MB .jpg images to around 300kb each to match the working images i have with the same code. However every time i try and use the 2 compressed images in my app, as soon as i hit run on device (my phone) it just crashes and i get this in my error log:

FATAL EXCEPTION: main Process: apps.appname, PID: 17528

java.lang.OutOfMemoryError

I've narrowed it down to definitely being an error with just those 2 images that i compressed down from 2 MB to 300kb.

What can I do?

Community
  • 1
  • 1
  • The size of the images on disk is meaningless. What is the resolution of the images? – CommonsWare Jan 10 '16 at 00:45
  • I'm honestly unsure, where would i find the resolution for the files? Also glad to hear the size is meaningless.. that didnt seem right to me. Edit: Found it, rather large. 2432 x 4320 – Jonathan McCloskey Jan 10 '16 at 00:47
  • 1
    On Windows: Right Click on the File -> Properties -> Details. The actual size in memory is calculated like this: width * height * 4 Byte. Compressing them as jpegs won't have any use. – Tobias Baumeister Jan 10 '16 at 00:48
  • Got it to work! Thank you guys! Completely new to this so i didn't even consider the image resolution. Just resized the images in .Gimp and it worked perfectly. – Jonathan McCloskey Jan 10 '16 at 00:58
  • http://stackoverflow.com/a/30769592/3498931 if you don't want to do anything compressing and wanna load the images efficiently, i hope this answer would help or give you another way to get images. – Ajay P. Prajapati Jan 10 '16 at 04:05

1 Answers1

0

Found it, rather large. 2432 x 4320

"Rather large" is a bit of an understatement. Those, therefore, will each consume right around 40MB apiece if you try to load them in, in their entirety. You are unlikely to have heap space for that.

Moreover, you are unlikely to need images that large, as I am unaware of any Android device with that large of a screen resolution. The only scenario where you might want images of that resolution is if you are aiming for some sort of pinch-zoom UI for them, after having downloaded them as files, in which case this library can help.

Otherwise, resample the images to a lower resolution. If these are resources, be sure to put them in res/drawable-nodpi/, so that Android does not try to re-resample them to apply density conversions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • "Those, therefore, will each consume right around 40MB apiece if you try to load them in, in their entirety." That definitely explains the error. Ha. Again, thank you. Finally got everything working after a quick resizing. You guys are awesome here. – Jonathan McCloskey Jan 10 '16 at 01:00