As long as you remember the following principles, the OOM problem for processing images in Android is absolutely easy:
1. Large images must be compressed in proportion before they are displayed. to exit the current activity, they must be recycled.
Public static bitmap decodesampledbitmapfromresource (Resources res, int resid, int reqwidth, int reqheight) {// first decode with injustdecodebounds = true to check dimensions final bitmapfactory. options = new bitmapfactory. options (); options. injustdecodebounds = true; bitmapfactory. decoderesource (Res, resid, options); // calculate insamplesize options. insamplesize = calculateinsamplesize (options, reqwidth, reqheight); // decode bitmap with insamplesize set options. injustdecodebounds = false; return bitmapfactory. decoderesource (Res, resid, options );}
The insamplesize can be determined based on your actual situation.
If (Bitmap! = NULL &&! Bitmap. isrecycled () {bitmap. Recycle (); bitmap = NULL ;}
2. Large images (30 ~ 50 k) can be directly displayed, exit the current activity to immediately Recycle
If (Bitmap! = NULL &&! Bitmap. isrecycled () {bitmap. Recycle (); bitmap = NULL ;}
3. A large number of small images or images of different sizes are to be displayed. Please refer to my other LRU article.AlgorithmCached image: http://blog.csdn.net/androidzhaoxiaogang/article/details/8211649