Options
1. inBitmap
重用这个bitmap
- If set, decode methods that take the Options object will attempt to reuse this bitmap when loading content.
- If the decode operation cannot use this bitmap, the decode method will return null and will throw an IllegalArgumentException.
- The current implementation necessitates that the reused bitmap be mutable, and the resulting reused bitmap will continue to remain mutable even when decoding a resource which would normally result in an immutable bitmap.
- You should still always use the returned Bitmap of the decode method and not assume that reusing the bitmap worked, due to the constraints outlined above and failure situations that can occur. Checking whether the return value matches the value of the inBitmap set in the Options structure will indicate if the bitmap was reused, but in all cases you should use the Bitmap returned by the decoding function to ensure that you are using the bitmap that was used as the decode destination.
配合 BitmapFactory 使用
Usage with BitmapFactory
- As of android.os.Build.VERSION_CODES.KITKAT, any mutable bitmap can be reused by BitmapFactory to decode any other bitmaps as long as the resulting byte count of the decoded bitmap is less than or equal to the allocated byte count of the reused bitmap. This can be because the intrinsic size is smaller, or its size post scaling (for density / sample size) is smaller.
- Prior to android.os.Build.VERSION_CODES.KITKAT additional constraints apply: The image being decoded (whether as a resource or as a stream) must be in jpeg or png format. Only equal sized bitmaps are supported, with inSampleSize set to 1. Additionally, the configuration of the reused bitmap will override the setting of inPreferredConfig, if set.
配合 BitmapRegionDecoder 使用
Usage with BitmapRegionDecoder
BitmapRegionDecoder will draw its requested content into the Bitmap provided, clipping if the output content size (post scaling) is larger than the provided Bitmap. The provided Bitmap's width, height, and Bitmap.Config will not be changed.
BitmapRegionDecoder support for inBitmap was introduced in android.os.Build.VERSION_CODES.JELLY_BEAN. All formats supported by BitmapRegionDecoder support Bitmap reuse via inBitmap.