Android Image Memory Optimization

Source: Internet
Author: User

Operate the image itself. Try not to use setimagebitmap, setimageresource, bitmapfactory. decoderesource to set a large image, because these methods are completed through the createbitmap on the Java layer after the decode is completed, requiring more memory consumption. Therefore, use bitmapfactory first. the decodestream method creates a bitmap and sets it as the source of imageview. The biggest secret of decodestream is that it directly calls JNI> nativedecodeasset () to complete decode, you no longer need to use the createbitmap on the Java layer, thus saving the Java Layer Space. If the configuration parameter of the slice is added during reading, the loaded memory can be reduced more effectively to prevent memory exceptions from being thrown. In addition, decodestream directly reads bytecode from images and does not automatically adapt to various machine resolutions. After decodestream is used, it must be in hdpi and mdpi, configure the corresponding image resources in ldpi. Otherwise, the images are of the same size (number of pixels) on machines with different resolutions. The displayed size is incorrect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.