How to use Android Bitmapfacty.options

Source: Internet
Author: User

Usually when we develop an Android application, we often need to deal with bitmap when loading images, generally using the relevant Decode method provided in Bitmapfactory;

If a large picture, we do not deal with direct decode words will often throw oom out of the memory of the exception. In order to avoid this situation, we will

Use an internal class option in Bitmapfactory to provide options for setting up.

injustdecodebounds If you set it to true, NULL will be returned at Decode, which allows you to query a bitmap property, such as the length and width of the bitmap, without taking up memory size.

inpreferredconfig by setting this value can be used to reduce memory consumption by default to argb_8888:4 bytes per pixel. Total 32 bits.
Alpha_8: Only save transparency, total 8 bits, 1 bytes.
argb_4444: Total 16 bits, 2 bytes.
rgb_565: Total 16 bits, 2 bytes.
If you do not need transparency, you can change the default value argb_8888 to rgb_565, saving half the memory.

insamplesize to the large picture compression, you can set the Options.injustdecodebounds, get bitmap peripheral data, wide and high. The compression ratio is then calculated and compressed.

inpurgeable and ininputshareable two are used side by side, if the inpurgeable = False is set, then the value of ininputshareable is ignored; the effect of these two options is to facilitate timely system

Reclaim memory occupied by bitmap; inpurgeable: Set to True, bitmap created with Bitmapfactory is used to store pixel memory space and can be reclaimed when the system is out of memory, when the app needs to be accessed again

When the bitmap is pixel, the system calls the Bitmapfactory decode method again to regenerate bitmap's pixel array. when set to False, indicates that it cannot be reclaimed.

ininputshareable: Set whether deep copy, used in conjunction with Inpurgeable, Inpurgeable is false, this parameter is meaningless

How to use Android Bitmapfacty.options

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.