Added in API level 1

BitmapFactory


open class BitmapFactory
kotlin.Any
   ↳ android.graphics.BitmapFactory

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

Summary

Nested classes
open

Public constructors

Public methods
open static Bitmap!
decodeByteArray(data: ByteArray!, offset: Int, length: Int)

Decode an immutable bitmap from the specified byte array.

open static Bitmap!
decodeByteArray(data: ByteArray!, offset: Int, length: Int, opts: BitmapFactory.Options!)

Decode an immutable bitmap from the specified byte array.

open static Bitmap!
decodeFile(pathName: String!)

Decode a file path into a bitmap.

open static Bitmap!

Decode a file path into a bitmap.

open static Bitmap!

Decode a bitmap from the file descriptor.

open static Bitmap!

Decode a bitmap from the file descriptor.

open static Bitmap!

Synonym for decodeResource(android.content.res.Resources,int,android.graphics.BitmapFactory.Options) with null Options.

open static Bitmap!

Synonym for opening the given resource and calling decodeResourceStream.

open static Bitmap?

Decode a new Bitmap from an InputStream.

open static Bitmap!

Decode an input stream into a bitmap.

open static Bitmap?
decodeStream(is: InputStream?, outPadding: Rect?, opts: BitmapFactory.Options?)

Decode an input stream into a bitmap.

Public constructors

BitmapFactory

BitmapFactory()

Public methods

decodeByteArray

Added in API level 1
open static fun decodeByteArray(
    data: ByteArray!,
    offset: Int,
    length: Int
): Bitmap!

Decode an immutable bitmap from the specified byte array.

Parameters
data ByteArray!: byte array of compressed image data
offset Int: offset into imageData for where the decoder should begin parsing.
length Int: the number of bytes, beginning at offset, to parse
Return
Bitmap! The decoded bitmap, or null if the image could not be decoded.

decodeByteArray

Added in API level 1
open static fun decodeByteArray(
    data: ByteArray!,
    offset: Int,
    length: Int,
    opts: BitmapFactory.Options!
): Bitmap!

Decode an immutable bitmap from the specified byte array.

Parameters
data ByteArray!: byte array of compressed image data
offset Int: offset into imageData for where the decoder should begin parsing.
length Int: the number of bytes, beginning at offset, to parse
opts BitmapFactory.Options!: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned.
Return
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)
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options.inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options.inMutable is set, if the specified color space is not RGB, or if the specified color space's transfer function is not an ICC parametric curve

decodeFile

Added in API level 1
open static fun decodeFile(pathName: String!): Bitmap!

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.

Parameters
pathName String!: complete path name for the file to be decoded.
Return
Bitmap! the resulting decoded bitmap, or null if it could not be decoded.

decodeFile

Added in API level 1
open static fun decodeFile(
    pathName: String!,
    opts: BitmapFactory.Options!
): Bitmap!

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.

Parameters
pathName String!: complete path name for the file to be decoded.
opts BitmapFactory.Options!: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned.
Return
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)
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options.inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options.inMutable is set, if the specified color space is not RGB, or if the specified color space's transfer function is not an ICC parametric curve

decodeFileDescriptor

Added in API level 1
open static fun decodeFileDescriptor(fd: FileDescriptor!): Bitmap!

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.

Parameters
fd FileDescriptor!: The file descriptor containing the bitmap data to decode
Return
Bitmap! the decoded bitmap, or null

decodeFileDescriptor

Added in API level 1
open static fun decodeFileDescriptor(
    fd: FileDescriptor!,
    outPadding: Rect!,
    opts: BitmapFactory.Options!
): Bitmap!

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.

Parameters
fd FileDescriptor!: The file descriptor containing the bitmap data to decode
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.
opts BitmapFactory.Options!: null-ok; Options that control downsampling and whether the image should be completely decoded, or just its size returned.
Return
Bitmap! the decoded bitmap, or null
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options.inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options.inMutable is set, if the specified color space is not RGB, or if the specified color space's transfer function is not an ICC parametric curve

decodeResource

Added in API level 1
open static fun decodeResource(
    res: Resources!,
    id: Int
): Bitmap!

Synonym for decodeResource(android.content.res.Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Parameters
res Resources!: The resources object containing the image data
id Int: The resource id of the image data
Return
Bitmap! The decoded bitmap, or null if the image could not be decoded.

decodeResource

Added in API level 1
open static fun decodeResource(
    res: Resources!,
    id: Int,
    opts: BitmapFactory.Options!
): Bitmap!

Synonym for opening the given resource and calling decodeResourceStream.

Parameters
res Resources!: The resources object containing the image data
id Int: The resource id of the image data
opts BitmapFactory.Options!: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned.
Return
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)
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options.inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options.inMutable is set, if the specified color space is not RGB, or if the specified color space's transfer function is not an ICC parametric curve

decodeResourceStream

Added in API level 4
open static fun decodeResourceStream(
    res: Resources?,
    value: TypedValue?,
    is: InputStream?,
    pad: Rect?,
    opts: BitmapFactory.Options?
): Bitmap?

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

Parameters
res Resources?: This value may be null.
value TypedValue?: This value may be null.
is InputStream?: This value may be null.
pad Rect?: This value may be null.
opts BitmapFactory.Options?: This value may be null.
Return
Bitmap? This value may be null.
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options.inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options.inMutable is set, if the specified color space is not RGB, or if the specified color space's transfer function is not an ICC parametric curve

decodeStream

Added in API level 1
open static fun decodeStream(is: InputStream!): Bitmap!

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.

Parameters
is InputStream!: The input stream that holds the raw data to be decoded into a bitmap.
Return
Bitmap! The decoded bitmap, or null if the image data could not be decoded.

decodeStream

Added in API level 1
open static fun decodeStream(
    is: InputStream?,
    outPadding: Rect?,
    opts: BitmapFactory.Options?
): Bitmap?

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.

Parameters
is InputStream?: The input stream that holds the raw data to be decoded into a bitmap. This value may be null.
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.
opts BitmapFactory.Options?: null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned.
Return
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)
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options.inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options.inMutable is set, if the specified color space is not RGB, or if the specified color space's transfer function is not an ICC parametric curve

Prior to android.os.Build.VERSION_CODES#KITKAT, if is.markSupported() returns true, is.mark(1024) would be called. As of android.os.Build.VERSION_CODES#KITKAT, this is no longer the case.