Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/graphics/BitmapFactory#nestedclasses) \| [Ctors](https://developer.android.com/reference/android/graphics/BitmapFactory#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/BitmapFactory#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/BitmapFactory#inhmethods)

# BitmapFactory

*** ** * ** ***

` public class BitmapFactory `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

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

<br />

*** ** * ** ***

Creates Bitmap objects from various sources, including files, streams, and byte-arrays.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/graphics/BitmapFactory.Options` |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/BitmapFactory#BitmapFactory()() ` |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeByteArray(byte[],%20int,%20int,%20android.graphics.BitmapFactory.Options)(byte[] data, int offset, int length, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` Decode an immutable bitmap from the specified byte array. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeByteArray(byte[],%20int,%20int)(byte[] data, int offset, int length) ` Decode an immutable bitmap from the specified byte array. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeFile(java.lang.String,%20android.graphics.BitmapFactory.Options)(https://developer.android.com/reference/java/lang/String pathName, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` Decode a file path into a bitmap. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeFile(java.lang.String)(https://developer.android.com/reference/java/lang/String pathName) ` Decode a file path into a bitmap. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeFileDescriptor(java.io.FileDescriptor)(https://developer.android.com/reference/java/io/FileDescriptor fd) ` Decode a bitmap from the file descriptor. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeFileDescriptor(java.io.FileDescriptor,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options)(https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/android/graphics/Rect outPadding, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` Decode a bitmap from the file descriptor. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20int)(https://developer.android.com/reference/android/content/res/Resources res, int id) ` Synonym for `https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20int,%20android.graphics.BitmapFactory.Options)` with null Options. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20int,%20android.graphics.BitmapFactory.Options)(https://developer.android.com/reference/android/content/res/Resources res, int id, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` Synonym for opening the given resource and calling `https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options)`. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options)(https://developer.android.com/reference/android/content/res/Resources res, https://developer.android.com/reference/android/util/TypedValue value, https://developer.android.com/reference/java/io/InputStream is, https://developer.android.com/reference/android/graphics/Rect pad, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` Decode a new Bitmap from an InputStream. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeStream(java.io.InputStream)(https://developer.android.com/reference/java/io/InputStream is) ` Decode an input stream into a bitmap. |
| ` static https://developer.android.com/reference/android/graphics/Bitmap` | ` https://developer.android.com/reference/android/graphics/BitmapFactory#decodeStream(java.io.InputStream,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options)(https://developer.android.com/reference/java/io/InputStream is, https://developer.android.com/reference/android/graphics/Rect outPadding, https://developer.android.com/reference/android/graphics/BitmapFactory.Options opts) ` Decode an input stream into a bitmap. |

### 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*.

## Public constructors

### BitmapFactory

```
public BitmapFactory ()
```

<br />

<br />

## Public methods

### decodeByteArray

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

```
public static Bitmap decodeByteArray (byte[] data, 
                int offset, 
                int length, 
                BitmapFactory.Options opts)
```

Decode an immutable bitmap from the specified byte array.

<br />

| Parameters ||
|---|---|
| `data` | `byte`: byte array of compressed image data <br /> |
| `offset` | `int`: offset into imageData for where the decoder should begin parsing. <br /> |
| `length` | `int`: the number of bytes, beginning at offset, to parse <br /> |
| `opts` | `BitmapFactory.Options`: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inPreferredConfig` is `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` and `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inMutable` is set, if the specified color space is not `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB`, or if the specified color space's transfer function is not an `https://developer.android.com/reference/android/graphics/ColorSpace.Rgb.TransferParameters` |

### decodeByteArray

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

```
public static Bitmap decodeByteArray (byte[] data, 
                int offset, 
                int length)
```

Decode an immutable bitmap from the specified byte array.

<br />

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

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image could not be decoded. <br /> |

### decodeFile

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

```
public static Bitmap decodeFile (String pathName, 
                BitmapFactory.Options opts)
```

Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.

<br />

| Parameters ||
|---|---|
| `pathName` | `String`: complete path name for the file to be decoded. <br /> |
| `opts` | `BitmapFactory.Options`: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inPreferredConfig` is `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` and `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inMutable` is set, if the specified color space is not `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB`, or if the specified color space's transfer function is not an `https://developer.android.com/reference/android/graphics/ColorSpace.Rgb.TransferParameters` |

### decodeFile

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

```
public static Bitmap decodeFile (String pathName)
```

Decode a file path into a bitmap. If the specified file name is null, or cannot be decoded into a bitmap, the function returns null.

<br />

| Parameters ||
|---|---|
| `pathName` | `String`: complete path name for the file to be decoded. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | the resulting decoded bitmap, or null if it could not be decoded. <br /> |

### decodeFileDescriptor

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

```
public static Bitmap decodeFileDescriptor (FileDescriptor fd)
```

Decode a bitmap from the file descriptor. If the bitmap cannot be decoded return null. The position within the descriptor will not be changed when this returns, so the descriptor can be used again as is.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: The file descriptor containing the bitmap data to decode <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | the decoded bitmap, or null <br /> |

### decodeFileDescriptor

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

```
public static Bitmap decodeFileDescriptor (FileDescriptor fd, 
                Rect outPadding, 
                BitmapFactory.Options opts)
```

Decode a bitmap from the file descriptor. If the bitmap cannot be decoded return null. The position within the descriptor will not be changed when this returns, so the descriptor can be used again as-is.

<br />

| Parameters ||
|---|---|
| `fd` | `FileDescriptor`: The file descriptor containing the bitmap data to decode <br /> |
| `outPadding` | `Rect`: If not null, return the padding rect for the bitmap if it exists, otherwise set padding to \[-1,-1,-1,-1\]. If no bitmap is returned (null) then padding is unchanged. <br /> |
| `opts` | `BitmapFactory.Options`: null-ok; Options that control downsampling and whether the image should be completely decoded, or just its size returned. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | the decoded bitmap, or null <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inPreferredConfig` is `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` and `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inMutable` is set, if the specified color space is not `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB`, or if the specified color space's transfer function is not an `https://developer.android.com/reference/android/graphics/ColorSpace.Rgb.TransferParameters` |

### decodeResource

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

```
public static Bitmap decodeResource (Resources res, 
                int id)
```

Synonym for `https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResource(android.content.res.Resources,%20int,%20android.graphics.BitmapFactory.Options)` with null Options.

<br />

| Parameters ||
|---|---|
| `res` | `Resources`: The resources object containing the image data <br /> |
| `id` | `int`: The resource id of the image data <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image could not be decoded. <br /> |

### decodeResource

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

```
public static Bitmap decodeResource (Resources res, 
                int id, 
                BitmapFactory.Options opts)
```

Synonym for opening the given resource and calling `https://developer.android.com/reference/android/graphics/BitmapFactory#decodeResourceStream(android.content.res.Resources,%20android.util.TypedValue,%20java.io.InputStream,%20android.graphics.Rect,%20android.graphics.BitmapFactory.Options)`.

<br />

| Parameters ||
|---|---|
| `res` | `Resources`: The resources object containing the image data <br /> |
| `id` | `int`: The resource id of the image data <br /> |
| `opts` | `BitmapFactory.Options`: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inPreferredConfig` is `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` and `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inMutable` is set, if the specified color space is not `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB`, or if the specified color space's transfer function is not an `https://developer.android.com/reference/android/graphics/ColorSpace.Rgb.TransferParameters` |

### decodeResourceStream

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

```
public static Bitmap decodeResourceStream (Resources res, 
                TypedValue value, 
                InputStream is, 
                Rect pad, 
                BitmapFactory.Options opts)
```

Decode a new Bitmap from an InputStream. This InputStream was obtained from resources, which we pass to be able to scale the bitmap accordingly.

<br />

| Parameters ||
|---|---|
| `res` | `Resources`: This value may be `null`. <br /> |
| `value` | `TypedValue`: This value may be `null`. <br /> |
| `is` | `InputStream`: This value may be `null`. <br /> |
| `pad` | `Rect`: This value may be `null`. <br /> |
| `opts` | `BitmapFactory.Options`: This value may be `null`. <br /> |

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

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inPreferredConfig` is `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` and `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inMutable` is set, if the specified color space is not `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB`, or if the specified color space's transfer function is not an `https://developer.android.com/reference/android/graphics/ColorSpace.Rgb.TransferParameters` |

### decodeStream

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

```
public static Bitmap decodeStream (InputStream is)
```

Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.

<br />

| Parameters ||
|---|---|
| `is` | `InputStream`: The input stream that holds the raw data to be decoded into a bitmap. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image data could not be decoded. <br /> |

### decodeStream

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

```
public static Bitmap decodeStream (InputStream is, 
                Rect outPadding, 
                BitmapFactory.Options opts)
```

Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.

<br />

| Parameters ||
|---|---|
| `is` | `InputStream`: The input stream that holds the raw data to be decoded into a bitmap. This value may be `null`. <br /> |
| `outPadding` | `Rect`: If not null, return the padding rect for the bitmap if it exists, otherwise set padding to \[-1,-1,-1,-1\]. If no bitmap is returned (null) then padding is unchanged. <br /> |
| `opts` | `BitmapFactory.Options`: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap` | The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight) <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inPreferredConfig` is `https://developer.android.com/reference/android/graphics/Bitmap.Config#HARDWARE` and `https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inMutable` is set, if the specified color space is not `https://developer.android.com/reference/android/graphics/ColorSpace.Model#RGB`, or if the specified color space's transfer function is not an `https://developer.android.com/reference/android/graphics/ColorSpace.Rgb.TransferParameters` Prior to `https://developer.android.com/reference/android/os/Build.VERSION_CODES#KITKAT`, if `https://developer.android.com/reference/java/io/InputStream#markSupported()` returns true, `is.mark(1024)` would be called. As of `https://developer.android.com/reference/android/os/Build.VERSION_CODES#KITKAT`, this is no longer the case. |