Reference: http://blog.csdn.net/huangbiao86/article/details/8072128
1. Read the images using Bitmapfactory.decodestream () and bitmapfactorty.decodefile () to avoid using Bitmapfactory.decoderesource, the first two function calls Jni> >nativedecodeasset () to complete the decode, eliminating the need to use the Java layer CreateBitmap, thus saving the Java layer of space.
Note: By looking at source code Discovery Bitmapfactory.decoderesource eventually also calls Nativedecodeasset ()
2. Optimize heap memory allocation for Dalvik virtual machines
Can be called when the program is OnCreate
Private final static floattarget_heap_utilization = 0.75f; Vmruntime.getruntime (). Settargetheaputilization (target_heap_utilization);
Private final static int cwj_heap_size = 6* 1024* 1024x768;
Vmruntime.getruntime (). Setminimumheapsize (Cwj_heap_size); //Set minimum heap memory to 6MB size. Of course, the memory crunch can also be handled by manually interfering with the GC.
3.options Set Picture size options.insamplesize
Private ImageView Preview; Private String filename= "/sdcard/dcim/camera/2010-05-14 16.01.44.jpg"new= 2; // The image width is the original One-second, that is, the picture is the original One-fourth Bitmap B = bitmapfactory.decodefile (filename, options);p Review.setimagebitmap (b); filepath.settext (filename);
Android Bitmap Prevent memory overflow