手动进行垃圾回收 调用bitmap.recycle() 或者System.gc();
If you use them for fit-in screen display only, just scale them to the
screen-size. You don't need any bigger.
(inJustDecodeBounds = true)
2. When actually loading the pic, downsample (inSampleSize > 1) so
that the resulting image fits the screen as good as possible (for best
result, make the loaded image a bit bigger than the screen instead of
a bit smaller). Also, the values of inSampleSize work best across most
phones when its value is a power of 2 (2, 4, 8, etc)
3. Then scale the image (down) a bit further to exactly fit the
screen.
downsample the image (inSampleSize = 2) --> Loaded image is 1024x768.
Then scale the downsampled image by 52.08333% --> a bitmap of 533x400
pixels. Cache this image. Still, be careful not to cache too many
images.
- private Bitmap decodeFile(File f){
- Bitmap b = null;
- try {
- //Decode image size
- BitmapFactory.Options o = new BitmapFactory.Options();
- o.inJustDecodeBounds = true;
- BitmapFactory.decodeStream(new FileInputStream(f), null, o);
- int scale = 1;
- if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
- scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
- }
- //Decode with inSampleSize
- BitmapFactory.Options o2 = new BitmapFactory.Options();
- o2.inSampleSize = scale;
- b = BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
- } catch (FileNotFoundException e) {
- }
- return b;
- }
Reference :
1.Handling big Bitmaps http://groups.google.com/group/a ... 1a63ad2?lnk=gst&;q=samu
2. 'bitmap size exceeds VM budget' if Activity is restarted [includes test demo!]
http://code.google.com/p/android/issues/detail?id=8488
3. How to... if you want to create and destroy the Bitmaps too frequently...
http://mobi-solutions.blogspot.c ... -to-create-and.html 4.Handling large Bitmaps
http://stackoverflow.com/questions/2220949/handling-large-bitmaps