Solution to the memory overflow problem of Android loading pictures
1. In the process of Android Software development, image processing is often encountered. When converting an image into a bitmap, due to the different size of the image, the memory will be exceeded when a large image is encountered. In order to solve this problem, the Android API provides the class bitmapfactory.options
2. Because Android has restrictions on the memory used by pictures, if you load a few megabytes of large pictures, the memory will overflow. Bitmap will load all pixels (i.e. length x width) of the picture into memory. If the picture resolution is too large, it will directly lead to memory oom. Only when bitmapfactory loads the picture, use bitmapfactory.options to configure relevant parameters to reduce the loaded pixels.
3. Detailed description of bitmapfactory.options related parameters:
(1) . options.inpredconfig value to reduce memory consumption. For example, the default value is ARGB_ Change 8888 to RGB_ 565, save half the memory. (2) . set options.insamplesize scaling to compress large pictures. (3) . set options.inpluggeable and inputshareable to enable the system to reclaim memory in time. A: Inpluggeable: when set to true, it indicates that the system memory can be recycled when it is insufficient. When set to false, it indicates that it cannot be recycled. B: Inputshareable: set whether to deep copy. It is used in combination with inpargeable. When inpargeable is false, this parameter has no meaning.
(4) . use decodestream instead of other methods.
Methods such as decoderesource, setimageresource, setimagebitmap, etc
4. Code part: