# BitmapFactory.Options

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Options

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/graphics/BitmapFactory.Options "View this page in Java")  

```
open class Options
```

|---|----------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                   ||
| ↳ | [android.graphics.BitmapFactory.Options](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#) |

## Summary

|                                                                                                              Public constructors                                                                                                              ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Options](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#Options())`()` Create a default Options object, which if left unchanged will give the same result from the decoder as if null were passed. |

|                                                                                                         Public methods                                                                                                          ||
|----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [requestCancelDecode](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#requestCancelDecode())`()` <br /> |

|                                                                                                                                                                                                                                                                                                                                                                                               Properties                                                                                                                                                                                                                                                                                                                                                                                               ||
|-------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Bitmap](https://developer.android.com/reference/kotlin/android/graphics/Bitmap)!               | [inBitmap](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inBitmap:android.graphics.Bitmap) If set, decode methods that take the Options object will attempt to reuse this bitmap when loading content.                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                      | [inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int) The pixel density to use for the bitmap.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inDither](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDither:kotlin.Boolean) <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inInputShareable](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inInputShareable:kotlin.Boolean) <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inJustDecodeBounds](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inJustDecodeBounds:kotlin.Boolean) If set to true, the decoder will return null (no bitmap), but the`out...`fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.                                                                                                                                                                                                                                                                                                                                                        |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inMutable](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inMutable:kotlin.Boolean) If set, decode methods will always return a mutable Bitmap instead of an immutable one.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inPreferQualityOverSpeed](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPreferQualityOverSpeed:kotlin.Boolean) <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [ColorSpace](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace)!       | [inPreferredColorSpace](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPreferredColorSpace:android.graphics.ColorSpace) If this is non-null, the decoder will try to decode into this color space.                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [Bitmap.Config](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)! | [inPreferredConfig](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPreferredConfig:android.graphics.Bitmap.Config) If this is non-null, the decoder will try to decode into this internal configuration.                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inPremultiplied](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPremultiplied:kotlin.Boolean) If true (which is the default), the resulting bitmap will have its color channels pre-multiplied by the alpha channel.                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inPurgeable](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPurgeable:kotlin.Boolean) <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                      | [inSampleSize](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inSampleSize:kotlin.Int) If set to a value \> 1, requests the decoder to subsample the original image, returning a smaller image to save memory.                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean) When this flag is set, if[inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int)and[inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)are not 0, the bitmap will be scaled to match[inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)when loaded, rather than relying on the graphics system scaling it each time it is drawn to a Canvas. |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                      | [inScreenDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScreenDensity:kotlin.Int) The pixel density of the actual screen that is being used.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                      | [inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int) The pixel density of the destination this bitmap will be drawn to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)!        | [inTempStorage](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTempStorage:kotlin.ByteArray) Temp storage to use for decoding.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)              | [mCancel](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#mCancel:kotlin.Boolean) <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [ColorSpace](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace)!       | [outColorSpace](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#outColorSpace:android.graphics.ColorSpace) If known, the color space the decoded bitmap will have.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Bitmap.Config](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)! | [outConfig](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#outConfig:android.graphics.Bitmap.Config) If known, the config the decoded bitmap will have.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                      | [outHeight](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#outHeight:kotlin.Int) The resulting height of the bitmap.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!               | [outMimeType](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#outMimeType:kotlin.String) If known, this string is set to the mimetype of the decoded image.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                      | [outWidth](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#outWidth:kotlin.Int) The resulting width of the bitmap.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

## Public constructors

### Options

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Options()
```

Create a default Options object, which if left unchanged will give the same result from the decoder as if null were passed.

## Public methods

### requestCancelDecode

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun requestCancelDecode(): Unit
```

**Deprecated:** *As of[android.os.Build.VERSION_CODES#N](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#N:kotlin.Int), this will not affect the decode, though it will still set mCancel. In[android.os.Build.VERSION_CODES#M](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#M:kotlin.Int)and below, if this can be called from another thread while this options object is inside a decode... call. Calling this will notify the decoder that it should cancel its operation. This is not guaranteed to cancel the decode, but if it does, the decoder... operation will return null, or if inJustDecodeBounds is true, will set outWidth/outHeight to -1*

## Properties

### inBitmap

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var 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 throw an[java.lang.IllegalArgumentException](https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html#). 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.

<br />

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.

### Usage with BitmapFactory

As of[android.os.Build.VERSION_CODES#KITKAT](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#KITKAT:kotlin.Int), any mutable bitmap can be reused by[BitmapFactory](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory)to decode any other bitmaps as long as the resulting[byte count](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#getByteCount())of the decoded bitmap is less than or equal to the[allocated byte count](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#getAllocationByteCount())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](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#KITKAT:kotlin.Int)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](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inSampleSize:kotlin.Int)set to 1. Additionally, the[configuration](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)of the reused bitmap will override the setting of[inPreferredConfig](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPreferredConfig:android.graphics.Bitmap.Config), if set.

### 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](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)will not be changed.

BitmapRegionDecoder support for[inBitmap](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inBitmap:android.graphics.Bitmap)was introduced in[android.os.Build.VERSION_CODES#JELLY_BEAN](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#JELLY_BEAN:kotlin.Int). All formats supported by BitmapRegionDecoder support Bitmap reuse via[inBitmap](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inBitmap:android.graphics.Bitmap).  
**See Also**

- [android.graphics.Bitmap#reconfigure(int,int, android.graphics.Bitmap.Config)](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#reconfigure(kotlin.Int,%20kotlin.Int,%20android.graphics.Bitmap.Config))  

### inDensity

Added in[API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inDensity: Int
```

The pixel density to use for the bitmap. This will always result in the returned bitmap having a density set for it (see[Bitmap.setDensity(int)](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#setDensity(kotlin.Int))). In addition, if[inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)is set (which it is by default} and this density does not match[inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int), then the bitmap will be scaled to the target density before being returned.

If this is 0,[BitmapFactory.decodeResource(Resources, int)](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20kotlin.Int)),[BitmapFactory.decodeResource(Resources, int, android.graphics.BitmapFactory.Options)](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20kotlin.Int,%20android.graphics.BitmapFactory.Options)), and[BitmapFactory.decodeResourceStream](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options))will fill in the density associated with the resource. The other functions will leave it as-is and no density will be applied.  
**See Also**

- [#inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)
- [#inScreenDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScreenDensity:kotlin.Int)
- [#inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)
- [android.graphics.Bitmap#setDensity(int)](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#setDensity(kotlin.Int))
- [android.util.DisplayMetrics#densityDpi](https://developer.android.com/reference/kotlin/android/util/DisplayMetrics.html#densityDpi:kotlin.Int)  

### inDither

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inDither: Boolean
```

**Deprecated:** *As of[android.os.Build.VERSION_CODES#N](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#N:kotlin.Int), this is ignored. In[android.os.Build.VERSION_CODES#M](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#M:kotlin.Int)and below, if dither is true, the decoder will attempt to dither the decoded image.*  

### inInputShareable

Added in[API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inInputShareable: Boolean
```

**Deprecated:** *As of[android.os.Build.VERSION_CODES#LOLLIPOP](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#LOLLIPOP:kotlin.Int), this is ignored. In[android.os.Build.VERSION_CODES#KITKAT](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#KITKAT:kotlin.Int)and below, this field works in conjunction with inPurgeable. If inPurgeable is false, then this field is ignored. If inPurgeable is true, then this field determines whether the bitmap can share a reference to the input data (inputstream, array, etc.) or if it must make a deep copy.*  

### inJustDecodeBounds

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inJustDecodeBounds: Boolean
```

If set to true, the decoder will return null (no bitmap), but the`out...`fields will still be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.  

### inMutable

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inMutable: Boolean
```

If set, decode methods will always return a mutable Bitmap instead of an immutable one. This can be used for instance to programmatically apply effects to a Bitmap loaded through BitmapFactory.

Can not be set simultaneously with inPreferredConfig =[android.graphics.Bitmap.Config#HARDWARE](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config), because hardware bitmaps are always immutable.  

### inPreferQualityOverSpeed

Added in[API level 10](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inPreferQualityOverSpeed: Boolean
```

**Deprecated:** *As of[android.os.Build.VERSION_CODES#N](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#N:kotlin.Int), this is ignored. The output will always be high quality. In[android.os.Build.VERSION_CODES#M](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#M:kotlin.Int)and below, if inPreferQualityOverSpeed is set to true, the decoder will try to decode the reconstructed image to a higher quality even at the expense of the decoding speed. Currently the field only affects JPEG decode, in the case of which a more accurate, but slightly slower, IDCT method will be used instead.*  

### inPreferredColorSpace

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inPreferredColorSpace: ColorSpace!
```

If this is non-null, the decoder will try to decode into this color space. If it is null, or the request cannot be met, the decoder will pick either the color space embedded in the image or the color space best suited for the requested image configuration (for instance[sRGB](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Named)for[Bitmap.Config.ARGB_8888](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)configuration and[EXTENDED_SRGB](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Named)for[Bitmap.Config.RGBA_F16](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)).

Only[ColorSpace.Model.RGB](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Model)color spaces are currently supported. An`IllegalArgumentException`will be thrown by the decode methods when setting a non-RGB color space such as[Lab](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Named).

Prior to[android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#UPSIDE_DOWN_CAKE:kotlin.Int), the specified color space's transfer function must be an[ICC parametric curve](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Rgb.TransferParameters). An`IllegalArgumentException`will be thrown by the decode methods if calling[ColorSpace.Rgb.getTransferParameters()](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Rgb#getTransferParameters())on the specified color space returns null. Starting from[android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#UPSIDE_DOWN_CAKE:kotlin.Int), non ICC parametric curve transfer function is allowed. E.g.,[BT2020_HLG](https://developer.android.com/reference/kotlin/android/graphics/ColorSpace.Named).

After decode, the bitmap's color space is stored in[outColorSpace](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#outColorSpace:android.graphics.ColorSpace).  

### inPreferredConfig

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inPreferredConfig: Bitmap.Config!
```

If this is non-null, the decoder will try to decode into this internal configuration. If it is null, or the request cannot be met, the decoder will try to pick the best matching config based on the system's screen depth, and characteristics of the original image such as if it has per-pixel alpha (requiring a config that also does). Image are loaded with the[Bitmap.Config.ARGB_8888](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)config by default.  

### inPremultiplied

Added in[API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inPremultiplied: Boolean
```

If true (which is the default), the resulting bitmap will have its color channels pre-multiplied by the alpha channel.

This should NOT be set to false for images to be directly drawn by the view system or through a[Canvas](https://developer.android.com/reference/kotlin/android/graphics/Canvas). The view system and[Canvas](https://developer.android.com/reference/kotlin/android/graphics/Canvas)assume all drawn images are pre-multiplied to simplify draw-time blending, and will throw a RuntimeException when un-premultiplied are drawn.

This is likely only useful if you want to manipulate raw encoded image data, e.g. with RenderScript or custom OpenGL.

This does not affect bitmaps without an alpha channel.

Setting this flag to false while setting[inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)to true may result in incorrect colors.  
**See Also**

- [android.graphics.Bitmap#hasAlpha()](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#hasAlpha())
- [android.graphics.Bitmap#isPremultiplied()](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#isPremultiplied())
- [#inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)  

### inPurgeable

Added in[API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inPurgeable: Boolean
```

**Deprecated:** *As of[android.os.Build.VERSION_CODES#LOLLIPOP](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#LOLLIPOP:kotlin.Int), this is ignored. In[android.os.Build.VERSION_CODES#KITKAT](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#KITKAT:kotlin.Int)and below, if this is set to true, then the resulting bitmap will allocate its pixels such that they can be purged if the system needs to reclaim memory. In that instance, when the pixels need to be accessed again (e.g. the bitmap is drawn, getPixels() is called), they will be automatically re-decoded.*

*For the re-decode to happen, the bitmap must have access to the encoded data, either by sharing a reference to the input or by making a copy of it. This distinction is controlled by inInputShareable. If this is true, then the bitmap may keep a shallow reference to the input. If this is false, then the bitmap will explicitly make a copy of the input data, and keep that. Even if sharing is allowed, the implementation may still decide to make a deep copy of the input data.*
*While inPurgeable can help avoid big Dalvik heap allocations (from API level 11 onward), it sacrifices performance predictability since any image that the view system tries to draw may incur a decode delay which can lead to dropped frames. Therefore, most apps should avoid using inPurgeable to allow for a fast and fluid UI. To minimize Dalvik heap allocations use the[inBitmap](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inBitmap:android.graphics.Bitmap)flag instead.
**Note:** This flag is ignored when used with[decodeResource(android.content.res.Resources,int,android.graphics.BitmapFactory.Options)](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20kotlin.Int,%20android.graphics.BitmapFactory.Options))or[decodeFile(java.lang.String,android.graphics.BitmapFactory.Options)](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeFile(kotlin.String,%20android.graphics.BitmapFactory.Options)).*

<br />

### inSampleSize

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inSampleSize: Int
```

If set to a value \> 1, requests the decoder to subsample the original image, returning a smaller image to save memory. The sample size is the number of pixels in either dimension that correspond to a single pixel in the decoded bitmap. For example, inSampleSize == 4 returns an image that is 1/4 the width/height of the original, and 1/16 the number of pixels. Any value \<= 1 is treated the same as 1. Note: the decoder uses a final value based on powers of 2, any other value will be rounded down to the nearest power of 2.  

### inScaled

Added in[API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inScaled: Boolean
```

When this flag is set, if[inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int)and[inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)are not 0, the bitmap will be scaled to match[inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)when loaded, rather than relying on the graphics system scaling it each time it is drawn to a Canvas.

BitmapRegionDecoder ignores this flag, and will not scale output based on density. (though[inSampleSize](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inSampleSize:kotlin.Int)is supported)

This flag is turned on by default and should be turned off if you need a non-scaled version of the bitmap. Nine-patch bitmaps ignore this flag and are always scaled.

If[inPremultiplied](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inPremultiplied:kotlin.Boolean)is set to false, and the image has alpha, setting this flag to true may result in incorrect colors.  

### inScreenDensity

Added in[API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inScreenDensity: Int
```

The pixel density of the actual screen that is being used. This is purely for applications running in density compatibility code, where[inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)is actually the density the application sees rather than the real screen density.

By setting this, you allow the loading code to avoid scaling a bitmap that is currently in the screen density up/down to the compatibility density. Instead, if[inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int)is the same as[inScreenDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScreenDensity:kotlin.Int), the bitmap will be left as-is. Anything using the resulting bitmap must also used[Bitmap.getScaledWidth](https://developer.android.com/reference/kotlin/android/graphics/Bitmap#getScaledWidth(kotlin.Int))and android.graphics.Bitmap#getScaledHeight to account for any different between the bitmap's density and the target's density.

This is never set automatically for the caller by[BitmapFactory](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory)itself. It must be explicitly set, since the caller must deal with the resulting bitmap in a density-aware way.  
**See Also**

- [#inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int)
- [#inTargetDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inTargetDensity:kotlin.Int)
- [#inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)
- [android.util.DisplayMetrics#densityDpi](https://developer.android.com/reference/kotlin/android/util/DisplayMetrics.html#densityDpi:kotlin.Int)  

### inTargetDensity

Added in[API level 4](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inTargetDensity: Int
```

The pixel density of the destination this bitmap will be drawn to. This is used in conjunction with[inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int)and[inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)to determine if and how to scale the bitmap before returning it.

If this is 0,[BitmapFactory.decodeResource(Resources, int)](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20kotlin.Int)),[BitmapFactory.decodeResource(Resources, int, android.graphics.BitmapFactory.Options)](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20kotlin.Int,%20android.graphics.BitmapFactory.Options)), and[BitmapFactory.decodeResourceStream](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory#decodeResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options))will fill in the density associated the Resources object's DisplayMetrics. The other functions will leave it as-is and no scaling for density will be performed.  
**See Also**

- [#inDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inDensity:kotlin.Int)
- [#inScreenDensity](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScreenDensity:kotlin.Int)
- [#inScaled](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inScaled:kotlin.Boolean)
- [android.util.DisplayMetrics#densityDpi](https://developer.android.com/reference/kotlin/android/util/DisplayMetrics.html#densityDpi:kotlin.Int)  

### inTempStorage

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var inTempStorage: ByteArray!
```

Temp storage to use for decoding. Suggest 16K or so.  

### mCancel

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var mCancel: Boolean
```

**Deprecated:** *As of[android.os.Build.VERSION_CODES#N](https://developer.android.com/reference/kotlin/android/os/Build.VERSION_CODES.html#N:kotlin.Int), see comments on[requestCancelDecode()](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#requestCancelDecode()). Flag to indicate that cancel has been called on this object. This is useful if there's an intermediary that wants to first decode the bounds and then decode the image. In that case the intermediary can check, inbetween the bounds decode and the image decode, to see if the operation is canceled.*  

### outColorSpace

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var outColorSpace: ColorSpace!
```

If known, the color space the decoded bitmap will have. Note that the output color space is not guaranteed to be the color space the bitmap is encoded with. If not known (when the config is[Bitmap.Config.ALPHA_8](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config)for instance), or there is an error, it is set to null.  

### outConfig

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var outConfig: Bitmap.Config!
```

If known, the config the decoded bitmap will have. If not known, or there is an error, it is set to null.  

### outHeight

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var outHeight: Int
```

The resulting height of the bitmap. If[inJustDecodeBounds](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inJustDecodeBounds:kotlin.Boolean)is set to false, this will be height of the output bitmap after any scaling is applied. If true, it will be the height of the input image without any accounting for scaling.

outHeight will be set to -1 if there is an error trying to decode.  

### outMimeType

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var outMimeType: String!
```

If known, this string is set to the mimetype of the decoded image. If not known, or there is an error, it is set to null.  

### outWidth

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
var outWidth: Int
```

The resulting width of the bitmap. If[inJustDecodeBounds](https://developer.android.com/reference/kotlin/android/graphics/BitmapFactory.Options#inJustDecodeBounds:kotlin.Boolean)is set to false, this will be width of the output bitmap after any scaling is applied. If true, it will be the width of the input image without any accounting for scaling.

outWidth will be set to -1 if there is an error trying to decode.