@UnstableApi
public final class BitmapUtil


Utility methods for Bitmap instances.

Summary

Public methods

static Bitmap
decode(
    byte[] data,
    int length,
    @Nullable BitmapFactory.Options options,
    int maximumOutputDimension
)

Decodes a Bitmap from a byte array using BitmapFactory and the ExifInterface.

static Bitmap

Returns an immutable, sharable version of Bitmap.

Public methods

decode

public static Bitmap decode(
    byte[] data,
    int length,
    @Nullable BitmapFactory.Options options,
    int maximumOutputDimension
)

Decodes a Bitmap from a byte array using BitmapFactory and the ExifInterface.

Parameters
byte[] data

Byte array of compressed image data.

int length

The number of bytes to parse.

@Nullable BitmapFactory.Options options

The BitmapFactory.Options to decode the data with.

int maximumOutputDimension

The largest output Bitmap dimension that can be returned by this method, or LENGTH_UNSET if no limits are enforced.

Throws
androidx.media3.common.ParserException

if the data could not be decoded.

java.io.IOException

makeShared

public static Bitmap makeShared(Bitmap bitmap)

Returns an immutable, sharable version of Bitmap. If the same instance of a shared bitmap is sent over binder calls, no additional copy is needed.

This method is a no-op if for API levels below 31 or if the Bitmap is already shared.

Parameters
Bitmap bitmap

A Bitmap.

Returns
Bitmap

A shared version of the Bitmap.