Displaying Bitmaps Efficiently (1)

Source: Internet
Author: User

Efficient image display-original Android official website translation

Translator: I am in an Android project team that I just created. OutOfMemory has been bothering me for a long time. I accidentally saw a suggestion in Stack Overflow and read this article. This article is not a high-end technology, and there are already some open-source components that can solve this problem. However, this article comprehensively describes how to deal with similar problems from the perspective of principles, which gives me a lot of inspiration. I am at a limited level. I have been searching for words during the translation process. Please forgive me if the translation is not in place.

 

Learning how to load images in Android not only helps you create a responsive UI, but also avoids exceeding the application's memory limit, thus avoiding OutOfMemory exceptions. If you are not careful enough, loading the Bitmap object will quickly consume the available memory of the application, causing the program to crash: java. lang. OutofMemoryError: bitmap size exceeds VM budget.

1. Exercise caution when loading images in Android due to the following reasons:

1. Mobile devices usually have limited system resources. Each app on the Android device can obtain at least 16 MB of available memory. Android Compatibility Document Android Compatibility Definition Document

2. Bitamp objects consume a lot of memory, especially for applications with rich images or photos. For example, a Galaxy Nexus camera (5 million pixels) can display a maximum

2. The following courses will show you how to quickly and securely load images in the Android environment.

Efficient image loading: describes how to ensure that a large image is loaded without exceeding the application memory limit.

Image processing outside the UI thread: Image operations (resetting the size, remote downloads, etc.) never occupy the UI thread. This section describes how to use AsyncTask in the background thread to process images and explain how to handle concurrency issues.

Cached images: This section describes how to use memory and external memory to cache images and improve UI response and mobility when loading images.

Image Memory Management: This section describes how to manage image memory to optimize the performance of applications.

Display images in the UI: This section combines the previous article to show you how to use background threads and image caches to load images into components such as ViewPager or GridView.

 

Click here to download the sample source code

Original article link

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.