Try not to use Setimagebitmap or Setimageresource or Bitmapfactory.decoderesource to set a large image, because these functions are completed decode, and ultimately through the Java layer of CreateBitmap to complete, you need to To consume more memory.
Therefore, instead of using the Bitmapfactory.decodestream method first to create a bitmap, and then set it to ImageView Source,decodestream the biggest secret is its direct call jni>> Nativedecodeasset () to complete the decode, eliminating the need to use the Java layer CreateBitmap, thus saving the Java layer of space.
If the config parameter is added to the read, it can be used to reduce the loaded memory effectively, thereby effectively blocking the throw out of
In addition, Decodestream directly take the picture to read the bytecode, not according to the machine's various resolutions to automatically adapt, after using the Decodestream, you need to configure the corresponding image resources in hdpi and mdpi,ldpi. Otherwise the same size (number of pixels) is the same on different resolution machines, and the displayed size is wrong.
In addition, the following ways can help:
- InputStream is = This.getresources (). Openrawresource (R.DRAWABLE.PIC1);
Bitmapfactory.options options=new bitmapfactory.options ();
Options.injustdecodebounds = false;
Options.insamplesize = 10; Width,hight is set to the original very
Bitmap BTP =bitmapfactory.decodestream (is,null,options);
- if (!bmp.isrecycle ()) {
Bmp.recycle ()//Recover the memory occupied by the picture
System.GC ()//Alarm system timely recovery
}
Solve memory overflow problems when Android loads pictures