The local data of a picture object occupies the largest amount of memory and is calculated separately from the memory in the Java portion of the program. So often Java heap is used enough. And the picture takes place outofmemoryerror situation. Calling this method when the picture is not in use can effectively reduce the peak value of local data in the image, thus reducing the probability of outofmemoryerror. Just a picture object called recycle () is in an "obsolete" state, which causes a program error when invoked. So there is no guarantee that the picture object will never be called again. It is not recommended to use this method.
There are four color modes for loading images into Android. Each is: alpha_8: Each pixel occupies 1byte of memory, argb_4444: Each pixel occupies 2byte memory, argb_8888: Each pixel occupies 4byte memory, rgb_565: Each pixel occupies 2byte memory. The default color mode for Android is argb_8888. This color mode is the most delicate color, showing the highest quality. But the same. Memory is also the largest.
The above code reads the picture resource in rgb_565 (or argb_4444) mode. Memory loss Although not as obvious as the first method, for most images, there is no difference between the argb_8888 pattern. A color bar may appear when you're reading a picture with a gradient effect.
In addition, it will affect the effect of the image processing.
4. How to change the color mode of a picture enlarged with the Matrix object:
Although you use the Matrix object to enlarge the picture. Will inevitably consume a lot of other memory. But sometimes it has to be done.
The enlarged image uses the argb_8888 color mode, even if the original picture is argb_4444 color mode. And there is no way to specify the color mode directly when zoomed in. You can change the image color mode using the following method.
Matrix matrix = new Matrix (); float newwidth = n; Picture enlarged width of float newheight =; Image enlarged Length Matrix.postscale (Newwidth/img.getwidth (), Newheight/img.getheight ()); Bitmap IMG1 = Bitmap.createbitmap (img, 0, 0, img.getwidth (), Img.getheight (), Matrix, True);//get enlarged picture Img2 = Img1.copy (bitm Ap. config.argb_4444, false); Get the picture of argb_4444 color mode img = NULL;IMG1 = null;
This creates an additional picture object IMG1 than the original image.
But the system will actively accept the takeover img1, so the actual memory is still cut.
It boils down to reading pictures in thumbnail mode and cutting down the memory used by every pixel in the image.
These two methods are effective, but also have their own shortcomings. The actual opening up or should be applied according to the scene as appropriate.
The most benevolent way, or to avoid the generation of garbage objects.
For example, in the application of the ListView, multiplexing Convertview and so on. If you apply asynctask to load a picture, set the referenced ImageView object to NULL in time. Because Asynctask is implemented with a thread pool, the objects referenced in this may have a very long life cycle, causing the GC to be unable to be acquitted. I still rely on Android's memory takeover mechanism. Recycle something is certainly effective in some degree. But it always feels inappropriate to accept the principle of Java memory takeover.