2

I'm developing an Android Game application that requires loading a lot of images(png). I used BitmapFactory.decodeStream to load the images:

BitmapFactory.Options opt = new BitmapFactory.Options(); 
opt.inScaled = false; 
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;     
Bitmap bitmap = BitmapFactory.decodeStream(context.getResources().openRawResource(context.getRes‌​ources().getIdentifier(filenames.get(i),"drawable",context.getPackageName())),nul‌​l,opt);

It works fine on Samsung S1 i9000(Android 2.3.3). But when I test it on Samsung S2 i9100(Android 4.1.2) it crashes when I load the images.

I launched DDMS to check the heap and found out something weird. It seems S1 only allocated 5.494mb for my application, when S2 allocated over 43.280mb!

I would really appreciate if someone could tell me why there's such big difference between these two phones.

Screenshot image

Leigh
  • 28,765
  • 10
  • 55
  • 103
user2570810
  • 21
  • 1
  • 1
  • Screen densities are different. I assume you provide different images for different resolutions, aren't you? Are your PNGs optimised for all resolutions? – David Jashi Jul 11 '13 at 11:28
  • thank you David,But I didn't provide different images for different resolutions.I only provide one resolution images. – user2570810 Jul 11 '13 at 12:00
  • Do you use `dp` or `dip` to specify image sizes? If `dp`, try providing upscaled images to S2 – David Jashi Jul 11 '13 at 12:55
  • No. I just want to load image. But it's fine in S1 , crash in S2. I want to know what difference between these two phones. – user2570810 Jul 11 '13 at 14:58
  • They are too many to list: screen density, OS version, CPU. You should post the piece of code in question, maybe it;s not phones fault. – David Jashi Jul 11 '13 at 20:25
  • BitmapFactory.Options opt = new BitmapFactory.Options(); opt.inScaled = false; opt.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeStream(context.getResources().openRawResource(context.getResources().getIdentifier(filenames.get(i),"drawable",context.getPackageName())),null,opt); I am using surfaceview to show my animations. Before I start my animations, I will pre load animation images S1 can load all my images,but S2 will crash(heap overflow). Look my screenshot image, we can see when i load images,s1 and s2 heap usage is difference.(S1:5.494MB,S2:43.28MB – user2570810 Jul 12 '13 at 03:17

0 Answers0