BitmapFactory.Options.InBitmap Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
If set, decode methods that take the Options object will attempt to reuse this bitmap when loading content.
[Android.Runtime.Register("inBitmap")]
public Android.Graphics.Bitmap InBitmap { get; set; }
[<Android.Runtime.Register("inBitmap")>]
member this.InBitmap : Android.Graphics.Bitmap with get, set
Property Value
- Attributes
Remarks
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 throw an java.lang.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.</p>
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.
<h3>Usage with BitmapFactory</h3>
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 Bitmap#getByteCount() byte count
of the decoded bitmap is less than or equal to the Bitmap#getAllocationByteCount() 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.
<p class="note">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 android.graphics.Bitmap.Config configuration
of the reused bitmap will override the setting of #inPreferredConfig
, if set.</p>
<h3>Usage with BitmapRegionDecoder</h3>
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.
<p class="note">BitmapRegionDecoder support for #inBitmap
was introduced in android.os.Build.VERSION_CODES#JELLY_BEAN
. All formats supported by BitmapRegionDecoder support Bitmap reuse via #inBitmap
.
Java documentation for android.graphics.BitmapFactory.Options.inBitmap
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.