Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/graphics/ImageDecoder#nestedclasses) \| [Constants](https://developer.android.com/reference/android/graphics/ImageDecoder#constants) \| [Methods](https://developer.android.com/reference/android/graphics/ImageDecoder#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/graphics/ImageDecoder#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/ImageDecoder#inhmethods)

# ImageDecoder

*** ** * ** ***


`
public

final

class
ImageDecoder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


implements

https://developer.android.com/reference/java/lang/AutoCloseable


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.ImageDecoder |

<br />

*** ** * ** ***

<br />

A class for converting encoded images (like `PNG`, `JPEG`,
`WEBP`, `GIF`, or `HEIF`) into `https://developer.android.com/reference/android/graphics/drawable/Drawable` or
`https://developer.android.com/reference/android/graphics/Bitmap` objects.

To use it, first create a `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` using one of the
`createSource` overloads. For example, to decode from a `https://developer.android.com/reference/android/net/Uri`, call
`https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(android.content.ContentResolver,%20android.net.Uri)` and pass the result to
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`:

```
 File file = new File(...);
 ImageDecoder.Source source = ImageDecoder.createSource(file);
 Drawable drawable = ImageDecoder.decodeDrawable(source);
 
```

To change the default settings, pass the `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` and an
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` to
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)` or
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)`. For example, to
create a sampled image with half the width and height of the original image,
call `https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSampleSize(int)` inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`:

```
 OnHeaderDecodedListener listener = new OnHeaderDecodedListener() {
     public void onHeaderDecoded(ImageDecoder decoder, ImageInfo info, Source source) {
         decoder.setTargetSampleSize(2);
     }
 };
 Drawable drawable = ImageDecoder.decodeDrawable(source, listener);
 
```

The `https://developer.android.com/reference/android/graphics/ImageDecoder.ImageInfo` contains information about the encoded image, like
its width and height, and the `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` can be used to match to a particular
`https://developer.android.com/reference/android/graphics/ImageDecoder.Source` if a single `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`
is used with multiple `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` objects.

The `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` can also be implemented
as a lambda:

```
 Drawable drawable = ImageDecoder.decodeDrawable(source, (decoder, info, src) -> {
     decoder.setTargetSampleSize(2);
 });
 
```

If the encoded image is an animated `GIF` or `WEBP`,
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` will return an `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable`. To
start its animation, call `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable#start()`:

```
 Drawable drawable = ImageDecoder.decodeDrawable(source);
 if (drawable instanceof AnimatedImageDrawable) {
     ((AnimatedImageDrawable) drawable).start();
 }
 
```

By default, a `https://developer.android.com/reference/android/graphics/Bitmap` created by `https://developer.android.com/reference/android/graphics/ImageDecoder` (including
one that is inside a `https://developer.android.com/reference/android/graphics/drawable/Drawable`) will be immutable (i.e.
`https://developer.android.com/reference/android/graphics/Bitmap#isMutable()` returns `false`), and it
will typically have `Config` `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE`. Although
these properties can be changed with `https://developer.android.com/reference/android/graphics/ImageDecoder#setMutableRequired(boolean)`
(which is only compatible with `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)` and
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)`) and `https://developer.android.com/reference/android/graphics/ImageDecoder#setAllocator(int)`,
it is also possible to apply custom effects regardless of the mutability of
the final returned object by passing a `https://developer.android.com/reference/android/graphics/PostProcessor` to
`https://developer.android.com/reference/android/graphics/ImageDecoder#setPostProcessor(android.graphics.PostProcessor)`. A `https://developer.android.com/reference/android/graphics/PostProcessor` can also be a lambda:

```
 Drawable drawable = ImageDecoder.decodeDrawable(source, (decoder, info, src) -> {
     decoder.setPostProcessor((canvas) -> {
             // This will create rounded corners.
             Path path = new Path();
             path.setFillType(Path.FillType.INVERSE_EVEN_ODD);
             int width = canvas.getWidth();
             int height = canvas.getHeight();
             path.addRoundRect(0, 0, width, height, 20, 20, Path.Direction.CW);
             Paint paint = new Paint();
             paint.setAntiAlias(true);
             paint.setColor(Color.TRANSPARENT);
             paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
             canvas.drawPath(path, paint);
             return PixelFormat.TRANSLUCENT;
     });
 });
 
```

If the encoded image is incomplete or contains an error, or if an
`https://developer.android.com/reference/java/lang/Exception` occurs during decoding, a `https://developer.android.com/reference/android/graphics/ImageDecoder.DecodeException`
will be thrown. In some cases, the `https://developer.android.com/reference/android/graphics/ImageDecoder` may have decoded part of
the image. In order to display the partial image, an
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` must be passed to
`https://developer.android.com/reference/android/graphics/ImageDecoder#setOnPartialImageListener(android.graphics.ImageDecoder.OnPartialImageListener)`. For example:

```
 Drawable drawable = ImageDecoder.decodeDrawable(source, (decoder, info, src) -> {
     decoder.setOnPartialImageListener((DecodeException e) -> {
             // Returning true indicates to create a Drawable or Bitmap even
             // if the whole image could not be decoded. Any remaining lines
             // will be blank.
             return true;
     });
 });
 
```

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/graphics/ImageDecoder.DecodeException` Information about an interrupted decode. |
| ` class` | `https://developer.android.com/reference/android/graphics/ImageDecoder.ImageInfo` Information about an encoded image. |
| ` interface` | `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` Interface for changing the default settings of a decode. |
| ` interface` | `https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` Interface for inspecting a `https://developer.android.com/reference/android/graphics/ImageDecoder.DecodeException` and potentially preventing it from being thrown. |
| ` class` | `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` Source of encoded image data. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_DEFAULT` Use the default allocation for the pixel memory. |
| `int` | `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_HARDWARE` Require a `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` `https://developer.android.com/reference/android/graphics/Bitmap`. |
| `int` | `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_SHARED_MEMORY` Use shared memory for the pixel memory. |
| `int` | `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_SOFTWARE` Use a software allocation for the pixel memory. |
| `int` | `https://developer.android.com/reference/android/graphics/ImageDecoder#MEMORY_POLICY_DEFAULT` Use the most natural `https://developer.android.com/reference/android/graphics/Bitmap.Config` for the internal `https://developer.android.com/reference/android/graphics/Bitmap`. |
| `int` | `https://developer.android.com/reference/android/graphics/ImageDecoder#MEMORY_POLICY_LOW_RAM` Save memory if possible by using a denser `https://developer.android.com/reference/android/graphics/Bitmap.Config` at the cost of some image quality. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#close()() ` Closes this resource, relinquishing any underlying resources. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(byte[])(byte[] data) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a byte array. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(android.content.res.AssetManager,%20java.lang.String)(https://developer.android.com/reference/android/content/res/AssetManager assets, https://developer.android.com/reference/java/lang/String fileName) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a file in the "assets" directory. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(java.util.concurrent.Callable<android.content.res.AssetFileDescriptor>)(https://developer.android.com/reference/java/util/concurrent/Callable<https://developer.android.com/reference/android/content/res/AssetFileDescriptor> callable) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/java/util/concurrent/Callable` that returns a new `https://developer.android.com/reference/android/content/res/AssetFileDescriptor` for each request. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer buffer) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/java/nio/ByteBuffer`. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(java.io.File)(https://developer.android.com/reference/java/io/File file) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/java/io/File`. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(android.content.res.Resources,%20int)(https://developer.android.com/reference/android/content/res/Resources res, int resId) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a resource. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(android.content.ContentResolver,%20android.net.Uri)(https://developer.android.com/reference/android/content/ContentResolver cr, https://developer.android.com/reference/android/net/Uri uri) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/android/net/Uri`. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(byte[],%20int,%20int)(byte[] data, int offset, int length) ` Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a byte array. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)(https://developer.android.com/reference/android/graphics/ImageDecoder.Source src, https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener listener) ` Create a `https://developer.android.com/reference/android/graphics/Bitmap` from a `Source`. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)(https://developer.android.com/reference/android/graphics/ImageDecoder.Source src) ` Create a `https://developer.android.com/reference/android/graphics/Bitmap` from a `Source`. |
| ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)(https://developer.android.com/reference/android/graphics/ImageDecoder.Source src) ` Create a `https://developer.android.com/reference/android/graphics/drawable/Drawable` from a `Source`. |
| ` static https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)(https://developer.android.com/reference/android/graphics/ImageDecoder.Source src, https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener listener) ` Create a `https://developer.android.com/reference/android/graphics/drawable/Drawable` from a `Source`. |
| ` long` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getAllocationLimit()() ` Get the maximum memory limit in bytes for image decoding. |
| ` int` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getAllocator()() ` Return the allocator for the pixel memory. |
| ` https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getCrop()() ` Return the cropping rectangle, if set. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getDefaultProcessListener()() ` Return the process-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`. |
| ` static https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getDefaultThreadListener()() ` Return the thread-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`. |
| ` int` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getMemorySizePolicy()() ` Retrieve the memory policy for the decoded `https://developer.android.com/reference/android/graphics/Bitmap`. |
| ` https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getOnPartialImageListener()() ` Return the `https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` currently set. |
| ` https://developer.android.com/reference/android/graphics/PostProcessor` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#getPostProcessor()() ` Return the `https://developer.android.com/reference/android/graphics/PostProcessor` currently set. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#isDecodeAsAlphaMaskEnabled()() ` Return whether to treat single channel input as alpha. |
| ` static boolean` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#isMimeTypeSupported(java.lang.String)(https://developer.android.com/reference/java/lang/String mimeType) ` Return if the given MIME type is a supported file format that can be decoded by this class. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#isMutableRequired()() ` Return whether the decoded `https://developer.android.com/reference/android/graphics/Bitmap` will be mutable. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#isUnpremultipliedRequired()() ` Return whether the `https://developer.android.com/reference/android/graphics/Bitmap` will have unpremultiplied pixels. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setAllocationLimit(long)(long limit) ` Set a maximum memory limit (bytes) for an image decode. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setAllocator(int)(int allocator) ` Choose the backing for the pixel memory. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setCrop(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect subset) ` Crop the output to `subset` of the (possibly) scaled image. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setDecodeAsAlphaMaskEnabled(boolean)(boolean enabled) ` Specify whether to potentially treat the output as an alpha mask. |
| ` static void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setDefaultProcessListener(android.graphics.ImageDecoder.OnHeaderDecodedListener)(https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener listener) ` Set the process-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`. |
| ` static void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setDefaultThreadListener(android.graphics.ImageDecoder.OnHeaderDecodedListener)(https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener listener) ` Set the thread-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setMemorySizePolicy(int)(int policy) ` Specify the memory policy for the decoded `https://developer.android.com/reference/android/graphics/Bitmap`. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setMutableRequired(boolean)(boolean mutable) ` Specify whether the `https://developer.android.com/reference/android/graphics/Bitmap` should be mutable. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setOnPartialImageListener(android.graphics.ImageDecoder.OnPartialImageListener)(https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener listener) ` Set (replace) the `https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` on this object. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setPostProcessor(android.graphics.PostProcessor)(https://developer.android.com/reference/android/graphics/PostProcessor postProcessor) ` Modify the image after decoding and scaling. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetColorSpace(android.graphics.ColorSpace)(https://developer.android.com/reference/android/graphics/ColorSpace colorSpace) ` Specify the desired `https://developer.android.com/reference/android/graphics/ColorSpace` for the output. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSampleSize(int)(int sampleSize) ` Set the target size with a sampleSize. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSize(int,%20int)(int width, int height) ` Specify the size of the output `https://developer.android.com/reference/android/graphics/drawable/Drawable` or `https://developer.android.com/reference/android/graphics/Bitmap`. |
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#setUnpremultipliedRequired(boolean)(boolean unpremultipliedRequired) ` Specify whether the `https://developer.android.com/reference/android/graphics/Bitmap` should have unpremultiplied pixels. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/ImageDecoder#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


From interface `

https://developer.android.com/reference/java/lang/AutoCloseable

` `
abstract


void` `
https://developer.android.com/reference/java/lang/AutoCloseable#close()()
`

Closes this resource, relinquishing any underlying resources.


## Constants

### ALLOCATOR_DEFAULT

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

```
public static final int ALLOCATOR_DEFAULT
```

Use the default allocation for the pixel memory.

Will typically result in a `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE`
allocation, but may be software for small images. In addition, this will
switch to software when HARDWARE is incompatible, e.g.
`https://developer.android.com/reference/android/graphics/ImageDecoder#setMutableRequired(boolean)` or
`https://developer.android.com/reference/android/graphics/ImageDecoder#setDecodeAsAlphaMaskEnabled(boolean)`.

<br />

Constant Value:

0
(0x00000000)


### ALLOCATOR_HARDWARE

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

```
public static final int ALLOCATOR_HARDWARE
```

Require a `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` `https://developer.android.com/reference/android/graphics/Bitmap`.

When this is combined with incompatible options, like
`https://developer.android.com/reference/android/graphics/ImageDecoder#setMutableRequired(boolean)` or
`https://developer.android.com/reference/android/graphics/ImageDecoder#setDecodeAsAlphaMaskEnabled(boolean)`,
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`
will throw an `https://developer.android.com/reference/java/lang/IllegalStateException`.

<br />

Constant Value:

3
(0x00000003)


### ALLOCATOR_SHARED_MEMORY

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

```
public static final int ALLOCATOR_SHARED_MEMORY
```

Use shared memory for the pixel memory.

Useful for sharing across processes.

<br />

Constant Value:

2
(0x00000002)


### ALLOCATOR_SOFTWARE

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

```
public static final int ALLOCATOR_SOFTWARE
```

Use a software allocation for the pixel memory.

Useful for drawing to a software `https://developer.android.com/reference/android/graphics/Canvas` or for
accessing the pixels on the final output.

<br />

Constant Value:

1
(0x00000001)


### MEMORY_POLICY_DEFAULT

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

```
public static final int MEMORY_POLICY_DEFAULT
```

Use the most natural `https://developer.android.com/reference/android/graphics/Bitmap.Config` for the internal `https://developer.android.com/reference/android/graphics/Bitmap`.

This is the recommended default for most applications and usages. This
will use the closest `https://developer.android.com/reference/android/graphics/Bitmap.Config` for the encoded source. If the
encoded source does not exactly match any `https://developer.android.com/reference/android/graphics/Bitmap.Config`, the next
highest quality `https://developer.android.com/reference/android/graphics/Bitmap.Config` will be used avoiding any loss in
image quality.

<br />

Constant Value:

1
(0x00000001)


### MEMORY_POLICY_LOW_RAM

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

```
public static final int MEMORY_POLICY_LOW_RAM
```

Save memory if possible by using a denser `https://developer.android.com/reference/android/graphics/Bitmap.Config` at the
cost of some image quality.

For example an opaque 8-bit image may be compressed into an
`https://developer.android.com/reference/android/graphics/Bitmap.Config#RGB_565` configuration, sacrificing image
quality to save memory.

<br />

Constant Value:

0
(0x00000000)


## Public methods

### close

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

```
public void close ()
```

Closes this resource, relinquishing any underlying resources. This method
is invoked automatically on objects managed by the try-with-resources
statement.

This is an implementation detail of `https://developer.android.com/reference/android/graphics/ImageDecoder`, and should
never be called manually.

<br />

<br />

### createSource

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

```
public static ImageDecoder.Source createSource (byte[] data)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a byte array.

Note: If this `Source` is passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`,
and the encoded image is animated, the returned `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable`
will continue reading from `data`, so its contents must not
be modified, even after the `AnimatedImageDrawable` is returned.
`data`'s contents should never be modified during decode.
.   
This method is safe to call from any thread.

<br />

<br />

| Parameters ||
|---|---|
| `data` | `byte`: byte array of compressed image data. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if data is null. |

### createSource

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

```
public static ImageDecoder.Source createSource (AssetManager assets, 
                String fileName)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a file in the "assets" directory.


This method is safe to call from any thread.

<br />

| Parameters ||
|---|---|
| `assets` | `AssetManager`: This value cannot be `null`. <br /> |
| `fileName` | `String`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | This value cannot be `null`. <br /> |

### createSource

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

```
public static ImageDecoder.Source createSource (Callable<AssetFileDescriptor> callable)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/java/util/concurrent/Callable` that returns a
new `https://developer.android.com/reference/android/content/res/AssetFileDescriptor` for each request. This provides control
over how the `https://developer.android.com/reference/android/content/res/AssetFileDescriptor` is created, such as passing
options into `https://developer.android.com/reference/android/content/ContentResolver#openTypedAssetFileDescriptor(android.net.Uri,%20java.lang.String,%20android.os.Bundle)`, or
enabling use of a `https://developer.android.com/reference/android/os/CancellationSignal`.


It's important for the given `https://developer.android.com/reference/java/util/concurrent/Callable` to return a new, unique
`https://developer.android.com/reference/android/content/res/AssetFileDescriptor` for each invocation, to support reuse of the
returned `https://developer.android.com/reference/android/graphics/ImageDecoder.Source`.


This method is safe to call from any thread.

<br />

| Parameters ||
|---|---|
| `callable` | `Callable`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

### createSource

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

```
public static ImageDecoder.Source createSource (ByteBuffer buffer)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/java/nio/ByteBuffer`.

Decoding will start from `https://developer.android.com/reference/java/nio/Buffer#position()`.
The position of `buffer` will not be affected.

Note: If this `Source` is passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`,
and the encoded image is animated, the returned `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable`
will continue reading from the `buffer`, so its contents must not
be modified, even after the `AnimatedImageDrawable` is returned.
`buffer`'s contents should never be modified during decode.
.   
This method is safe to call from any thread.

<br />

<br />

| Parameters ||
|---|---|
| `buffer` | `ByteBuffer`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

### createSource

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

```
public static ImageDecoder.Source createSource (File file)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/java/io/File`.


This method should only be used for files that you have direct access to;
if you'd like to work with files hosted outside your app, use an API like
`https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(java.util.concurrent.Callable<android.content.res.AssetFileDescriptor>)` or
`https://developer.android.com/reference/android/graphics/ImageDecoder#createSource(android.content.ContentResolver,%20android.net.Uri)`.


This method is safe to call from any thread.

<br />

| Parameters ||
|---|---|
| `file` | `File`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

### createSource

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

```
public static ImageDecoder.Source createSource (Resources res, 
                int resId)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a resource.


This method is safe to call from any thread.

<br />

| Parameters ||
|---|---|
| `res` | `Resources`: the `https://developer.android.com/reference/android/content/res/Resources` object containing the image data. This value cannot be `null`. <br /> |
| `resId` | `int`: resource ID of the image data. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

### createSource

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

```
public static ImageDecoder.Source createSource (ContentResolver cr, 
                Uri uri)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a `https://developer.android.com/reference/android/net/Uri`.

##### Accepts the following URI schemes:

- content (`https://developer.android.com/reference/android/content/ContentResolver#SCHEME_CONTENT`)
- android.resource (`https://developer.android.com/reference/android/content/ContentResolver#SCHEME_ANDROID_RESOURCE`)
- file (`https://developer.android.com/reference/android/content/ContentResolver#SCHEME_FILE`)

.   
This method is safe to call from any thread.

<br />

<br />

| Parameters ||
|---|---|
| `cr` | `ContentResolver`: to retrieve from. This value cannot be `null`. <br /> |
| `uri` | `Uri`: of the image file. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

### createSource

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

```
public static ImageDecoder.Source createSource (byte[] data, 
                int offset, 
                int length)
```

Create a new `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` from a byte array.

Note: If this `Source` is passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`,
and the encoded image is animated, the returned `https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable`
will continue reading from `data`, so its contents must not
be modified, even after the `AnimatedImageDrawable` is returned.
`data`'s contents should never be modified during decode.
.   
This method is safe to call from any thread.

<br />

<br />

| Parameters ||
|---|---|
| `data` | `byte`: byte array of compressed image data. This value cannot be `null`. <br /> |
| `offset` | `int`: offset into data for where the decoder should begin parsing. <br /> |
| `length` | `int`: number of bytes, beginning at offset, to parse. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.Source` | a new Source object, which can be passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` or `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/ArrayIndexOutOfBoundsException` | if offset and length are not within data. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | if data is null. |

### decodeBitmap

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

```
public static Bitmap decodeBitmap (ImageDecoder.Source src, 
                ImageDecoder.OnHeaderDecodedListener listener)
```

Create a `https://developer.android.com/reference/android/graphics/Bitmap` from a `Source`.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `src` | `ImageDecoder.Source`: representing the encoded image. This value cannot be `null`. <br /> |
| `listener` | `ImageDecoder.OnHeaderDecodedListener`: for learning the `https://developer.android.com/reference/android/graphics/ImageDecoder.ImageInfo` and changing any default settings on the `ImageDecoder`. This will be called on the same thread as `decodeBitmap` before that method returns. This is required in order to change any of the default settings. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | Bitmap containing the image. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if `src` is not found, is an unsupported format, or cannot be decoded for any reason. |

### decodeBitmap

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

```
public static Bitmap decodeBitmap (ImageDecoder.Source src)
```

Create a `https://developer.android.com/reference/android/graphics/Bitmap` from a `Source`.

Since there is no `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`,
the default settings will be used. In order to change any settings, call
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)` instead.
.   
This method may take several seconds to complete, so it should only be called from a worker thread.

<br />

<br />

| Parameters ||
|---|---|
| `src` | `ImageDecoder.Source`: representing the encoded image. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | Bitmap containing the image. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if `src` is not found, is an unsupported format, or cannot be decoded for any reason. |

### decodeDrawable

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

```
public static Drawable decodeDrawable (ImageDecoder.Source src)
```

Create a `https://developer.android.com/reference/android/graphics/drawable/Drawable` from a `Source`.

Since there is no `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`,
the default settings will be used. In order to change any settings, call
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)` instead.
.   
This method may take several seconds to complete, so it should only be called from a worker thread.

<br />

<br />

| Parameters ||
|---|---|
| `src` | `ImageDecoder.Source`: representing the encoded image. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable` | Drawable for displaying the image. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if `src` is not found, is an unsupported format, or cannot be decoded for any reason. |

### decodeDrawable

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

```
public static Drawable decodeDrawable (ImageDecoder.Source src, 
                ImageDecoder.OnHeaderDecodedListener listener)
```

Create a `https://developer.android.com/reference/android/graphics/drawable/Drawable` from a `Source`.


This method may take several seconds to complete, so it should
only be called from a worker thread.

<br />

| Parameters ||
|---|---|
| `src` | `ImageDecoder.Source`: representing the encoded image. This value cannot be `null`. <br /> |
| `listener` | `ImageDecoder.OnHeaderDecodedListener`: for learning the `https://developer.android.com/reference/android/graphics/ImageDecoder.ImageInfo` and changing any default settings on the `ImageDecoder`. This will be called on the same thread as `decodeDrawable` before that method returns. This is required in order to change any of the default settings. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable` | Drawable for displaying the image. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | if `src` is not found, is an unsupported format, or cannot be decoded for any reason. |

### getAllocationLimit

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public long getAllocationLimit ()
```

Get the maximum memory limit in bytes for image decoding.

<br />

| Returns ||
|---|---|
| `long` | <br /> |

### getAllocator

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

```
public int getAllocator ()
```

Return the allocator for the pixel memory.

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_DEFAULT` - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_SOFTWARE` - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_SHARED_MEMORY` - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_HARDWARE` |

### getCrop

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

```
public Rect getCrop ()
```

Return the cropping rectangle, if set.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Rect` | This value may be `null`. <br /> |

### getDefaultProcessListener

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

```
public static ImageDecoder.OnHeaderDecodedListener getDefaultProcessListener ()
```

Return the process-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` | This value may be `null`. <br /> |

### getDefaultThreadListener

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

```
public static ImageDecoder.OnHeaderDecodedListener getDefaultThreadListener ()
```

Return the thread-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` | This value may be `null`. <br /> |

### getMemorySizePolicy

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

```
public int getMemorySizePolicy ()
```

Retrieve the memory policy for the decoded `https://developer.android.com/reference/android/graphics/Bitmap`.

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/graphics/ImageDecoder#MEMORY_POLICY_DEFAULT` - `https://developer.android.com/reference/android/graphics/ImageDecoder#MEMORY_POLICY_LOW_RAM` |

### getOnPartialImageListener

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

```
public ImageDecoder.OnPartialImageListener getOnPartialImageListener ()
```

Return the `https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` currently set.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` | This value may be `null`. <br /> |

### getPostProcessor

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

```
public PostProcessor getPostProcessor ()
```

Return the `https://developer.android.com/reference/android/graphics/PostProcessor` currently set.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/PostProcessor` | This value may be `null`. <br /> |

### isDecodeAsAlphaMaskEnabled

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

```
public boolean isDecodeAsAlphaMaskEnabled ()
```

Return whether to treat single channel input as alpha.

This returns whether `https://developer.android.com/reference/android/graphics/ImageDecoder#setDecodeAsAlphaMaskEnabled(boolean)` was set to
`true`. It may still return `true` even if the image has
more than one channel and therefore will not be treated as an alpha
mask.

<br />

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isMimeTypeSupported

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

```
public static boolean isMimeTypeSupported (String mimeType)
```

Return if the given MIME type is a supported file format that can be
decoded by this class. This can be useful to determine if a file can be
decoded directly, or if it needs to be converted into a more general
format using an API like `https://developer.android.com/reference/android/content/ContentResolver#openTypedAssetFile(android.net.Uri,%20java.lang.String,%20android.os.Bundle,%20android.os.CancellationSignal)`.

<br />

| Parameters ||
|---|---|
| `mimeType` | `String`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### isMutableRequired

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

```
public boolean isMutableRequired ()
```

Return whether the decoded `https://developer.android.com/reference/android/graphics/Bitmap` will be mutable.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### isUnpremultipliedRequired

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

```
public boolean isUnpremultipliedRequired ()
```

Return whether the `https://developer.android.com/reference/android/graphics/Bitmap` will have unpremultiplied pixels.

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### setAllocationLimit

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void setAllocationLimit (long limit)
```

Set a maximum memory limit (bytes) for an image decode.

Memory usage is tracked during the decoding process, for instance when
calling `https://developer.android.com/` or `https://developer.android.com/`. If an allocation is expected to
raise the decode memory usage over the allocation limit, the decode is aborted and an
`https://developer.android.com/reference/java/io/IOException` is thrown by decode function.

The limit is applied per each image decode. The default limit is 0.5GiB. 0 indicates no
limit.

<br />

<br />

| Parameters ||
|---|---|
| `limit` | `long` <br /> |

### setAllocator

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

```
public void setAllocator (int allocator)
```

Choose the backing for the pixel memory.

This is ignored for animated drawables.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `allocator` | `int`: Type of allocator to use. Value is one of the following: - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_DEFAULT` - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_SOFTWARE` - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_SHARED_MEMORY` - `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_HARDWARE` |

### setCrop

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

```
public void setCrop (Rect subset)
```

Crop the output to `subset` of the (possibly) scaled image.

`subset` must be contained within the size set by
`https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSize(int,%20int)` or the bounds of the image if setTargetSize was
not called. Otherwise an `https://developer.android.com/reference/java/lang/IllegalStateException` will be thrown by
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`/`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`.

NOT intended as a replacement for
`https://developer.android.com/reference/android/graphics/BitmapRegionDecoder#decodeRegion(android.graphics.Rect,%20android.graphics.BitmapFactory.Options)`.
This supports all formats, but merely crops the output.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `subset` | `Rect`: This value may be `null`. <br /> |

### setDecodeAsAlphaMaskEnabled

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

```
public void setDecodeAsAlphaMaskEnabled (boolean enabled)
```

Specify whether to potentially treat the output as an alpha mask.

If this is set to `true` and the image is encoded in a format
with only one channel, treat that channel as alpha. Otherwise this call has
no effect.

This is incompatible with `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_HARDWARE`. Trying to
combine them will result in `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`/
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)` throwing an
`https://developer.android.com/reference/java/lang/IllegalStateException`.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `enabled` | `boolean` <br /> |

### setDefaultProcessListener

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

```
public static void setDefaultProcessListener (ImageDecoder.OnHeaderDecodedListener listener)
```

Set the process-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`. A subsequent call
will overwrite any previous calls.

If there is no thread-level default set on the current thread, this is the first
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` to run during image decoding. At the time of decoding, a
listener can also be provided to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)`
which is run after the process-level default.

Note: setting a thread-level default via
`https://developer.android.com/reference/android/graphics/ImageDecoder#setDefaultThreadListener(android.graphics.ImageDecoder.OnHeaderDecodedListener)` will cause the process-level
default to be skipped on that thread. The listener passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` will
always run.

<br />

| Parameters ||
|---|---|
| `listener` | `ImageDecoder.OnHeaderDecodedListener`: This value may be `null`. <br /> |

### setDefaultThreadListener

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

```
public static void setDefaultThreadListener (ImageDecoder.OnHeaderDecodedListener listener)
```

Set the thread-level default `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener`. A subsequent call
will overwrite any previous calls.

If set, this is the first `https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener` to run during image decoding.
At the time of decoding, a listener can also be provided to
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source,%20android.graphics.ImageDecoder.OnHeaderDecodedListener)` which is run after the
thread-level default.

Note: setting a thread-level default will cause the process-level default set by
`https://developer.android.com/reference/android/graphics/ImageDecoder#setDefaultProcessListener(android.graphics.ImageDecoder.OnHeaderDecodedListener)` to be skipped on that thread.
The listener passed to `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)` will always run.

<br />

| Parameters ||
|---|---|
| `listener` | `ImageDecoder.OnHeaderDecodedListener`: This value may be `null`. <br /> |

### setMemorySizePolicy

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

```
public void setMemorySizePolicy (int policy)
```

Specify the memory policy for the decoded `https://developer.android.com/reference/android/graphics/Bitmap`.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `policy` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/graphics/ImageDecoder#MEMORY_POLICY_DEFAULT` - `https://developer.android.com/reference/android/graphics/ImageDecoder#MEMORY_POLICY_LOW_RAM` |

### setMutableRequired

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

```
public void setMutableRequired (boolean mutable)
```

Specify whether the `https://developer.android.com/reference/android/graphics/Bitmap` should be mutable.

By default, a `https://developer.android.com/reference/android/graphics/Bitmap` created by `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)`
will be immutable i.e. `https://developer.android.com/reference/android/graphics/Bitmap#isMutable()` returns
`false`. This can be changed with `setMutableRequired(true)`.

Mutable Bitmaps are incompatible with `https://developer.android.com/reference/android/graphics/ImageDecoder#ALLOCATOR_HARDWARE`,
because `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` Bitmaps cannot be mutable.
Attempting to combine them will throw an
`https://developer.android.com/reference/java/lang/IllegalStateException`.

Mutable Bitmaps are also incompatible with `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`,
which would require retrieving the Bitmap from the returned Drawable in
order to modify. Attempting to decode a mutable `https://developer.android.com/reference/android/graphics/drawable/Drawable` will
throw an `https://developer.android.com/reference/java/lang/IllegalStateException`.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `mutable` | `boolean` <br /> |

### setOnPartialImageListener

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

```
public void setOnPartialImageListener (ImageDecoder.OnPartialImageListener listener)
```

Set (replace) the `https://developer.android.com/reference/android/graphics/ImageDecoder.OnPartialImageListener` on this object.

Will be called if there is an error in the input. Without one, an
error will result in an `Exception` being thrown.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `listener` | `ImageDecoder.OnPartialImageListener`: This value may be `null`. <br /> |

### setPostProcessor

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

```
public void setPostProcessor (PostProcessor postProcessor)
```

Modify the image after decoding and scaling.

This allows adding effects prior to returning a `https://developer.android.com/reference/android/graphics/drawable/Drawable` or
`https://developer.android.com/reference/android/graphics/Bitmap`. For a `Drawable` or an immutable `Bitmap`,
this is the only way to process the image after decoding.

If combined with `https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSize(int,%20int)` and/or `https://developer.android.com/reference/android/graphics/ImageDecoder#setCrop(android.graphics.Rect)`,
`https://developer.android.com/reference/android/graphics/PostProcessor#onPostProcess(android.graphics.Canvas)` occurs last.

If set on a nine-patch image, the nine-patch data is ignored.

For an animated image, the drawing commands drawn on the
`https://developer.android.com/reference/android/graphics/Canvas` will be recorded immediately and then applied to each
frame.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `postProcessor` | `PostProcessor`: This value may be `null`. <br /> |

### setTargetColorSpace

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

```
public void setTargetColorSpace (ColorSpace colorSpace)
```

Specify the desired `https://developer.android.com/reference/android/graphics/ColorSpace` for the output.

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

Only `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB` color spaces are
currently supported. An `IllegalArgumentException` will
be thrown by `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`/
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)` when setting a non-RGB color space
such as `https://developer.android.com/reference/android/graphics/ColorSpace.Named#CIE_LAB`.

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

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `colorSpace` | `ColorSpace` <br /> |

### setTargetSampleSize

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

```
public void setTargetSampleSize (int sampleSize)
```

Set the target size with a sampleSize.

By default, the output size will match the size of the encoded
image, which can be retrieved from the `https://developer.android.com/reference/android/graphics/ImageDecoder.ImageInfo` in
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

Requests the decoder to subsample the original image, returning a
smaller image to save memory. The `sampleSize` is the number of pixels
in either dimension that correspond to a single pixel in the output.
For example, `sampleSize == 4` returns an image that is 1/4 the
width/height of the original, and 1/16 the number of pixels.

Must be greater than or equal to 1.

This has the same effect as calling `https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSize(int,%20int)` with
dimensions based on the `sampleSize`. Unlike dividing the original
width and height by the `sampleSize` manually, calling this method
allows `ImageDecoder` to round in the direction that it can do most
efficiently.

Only the last call to this or `https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSize(int,%20int)` is respected.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `sampleSize` | `int`: sampling rate of the encoded image. Value is 1 or greater <br /> |

### setTargetSize

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

```
public void setTargetSize (int width, 
                int height)
```

Specify the size of the output `https://developer.android.com/reference/android/graphics/drawable/Drawable` or `https://developer.android.com/reference/android/graphics/Bitmap`.

By default, the output size will match the size of the encoded
image, which can be retrieved from the `https://developer.android.com/reference/android/graphics/ImageDecoder.ImageInfo` in
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

This will sample or scale the output to an arbitrary size that may
be smaller or larger than the encoded size.

Only the last call to this or `https://developer.android.com/reference/android/graphics/ImageDecoder#setTargetSampleSize(int)` is
respected.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `width` | `int`: width in pixels of the output, must be greater than 0. The units of this value are pixels. Value is 1 or greater <br /> |
| `height` | `int`: height in pixels of the output, must be greater than 0. The units of this value are pixels. Value is 1 or greater <br /> |

### setUnpremultipliedRequired

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

```
public void setUnpremultipliedRequired (boolean unpremultipliedRequired)
```

Specify whether the `https://developer.android.com/reference/android/graphics/Bitmap` should have unpremultiplied pixels.

By default, ImageDecoder will create a `https://developer.android.com/reference/android/graphics/Bitmap` with
premultiplied pixels, which is required for drawing with the
`https://developer.android.com/reference/android/view/View` system (i.e. to a `https://developer.android.com/reference/android/graphics/Canvas`). Calling
this method with a value of `true` will result in
`https://developer.android.com/reference/android/graphics/ImageDecoder#decodeBitmap(android.graphics.ImageDecoder.Source)` returning a `https://developer.android.com/reference/android/graphics/Bitmap` with unpremultiplied
pixels. See `https://developer.android.com/reference/android/graphics/Bitmap#isPremultiplied()`.
This is incompatible with `https://developer.android.com/reference/android/graphics/ImageDecoder#decodeDrawable(android.graphics.ImageDecoder.Source)`;
attempting to decode an unpremultiplied `https://developer.android.com/reference/android/graphics/drawable/Drawable` will throw an
`https://developer.android.com/reference/java/lang/IllegalStateException`.

Like all setters on ImageDecoder, this must be called inside
`https://developer.android.com/reference/android/graphics/ImageDecoder.OnHeaderDecodedListener#onHeaderDecoded(android.graphics.ImageDecoder,%20android.graphics.ImageDecoder.ImageInfo,%20android.graphics.ImageDecoder.Source)`.

<br />

<br />

| Parameters ||
|---|---|
| `unpremultipliedRequired` | `boolean` <br /> |

## Protected methods

### finalize

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

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the `finalize` method to dispose of
system resources or to perform other cleanup.


The general contract of `finalize` is that it is invoked
if and when the Java virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The `finalize` method may take any action, including
making this object available again to other threads; the usual purpose
of `finalize`, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.


The `finalize` method of class `Object` performs no
special action; it simply returns normally. Subclasses of
`Object` may override this definition.


The Java programming language does not guarantee which thread will
invoke the `finalize` method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.


After the `finalize` method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.


The `finalize` method is never invoked more than once by a Java
virtual machine for any given object.


Any exception thrown by the `finalize` method causes
the finalization of this object to be halted, but is otherwise
ignored.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |