DrawableKt

Added in 1.1.0

public final class DrawableKt


Summary

Public methods

static final @NonNull Bitmap
toBitmap(
    @NonNull Drawable receiver,
    @Px int width,
    @Px int height,
    Bitmap.Config config
)

Return a Bitmap representation of this Drawable.

static final Bitmap
toBitmapOrNull(
    @NonNull Drawable receiver,
    @Px int width,
    @Px int height,
    Bitmap.Config config
)

Returns a Bitmap representation of this Drawable or null if the drawable cannot be represented as a bitmap.

static final void
updateBounds(
    @NonNull Drawable receiver,
    @Px int left,
    @Px int top,
    @Px int right,
    @Px int bottom
)

Updates this drawable's bounds.

Public methods

toBitmap

public static final @NonNull Bitmap toBitmap(
    @NonNull Drawable receiver,
    @Px int width,
    @Px int height,
    Bitmap.Config config
)

Return a Bitmap representation of this Drawable.

If this instance is a BitmapDrawable and the width, height, and config match, the underlying Bitmap instance will be returned directly. If any of those three properties differ then a new Bitmap is created. For all other Drawable types, a new Bitmap is created.

Parameters
@Px int width

Width of the desired bitmap. Defaults to Drawable.getIntrinsicWidth.

@Px int height

Height of the desired bitmap. Defaults to Drawable.getIntrinsicHeight.

Bitmap.Config config

Bitmap config of the desired bitmap. Null attempts to use the native config, if any. Defaults to Config.ARGB_8888 otherwise.

Throws
kotlin.IllegalArgumentException

if the underlying drawable is a BitmapDrawable where BitmapDrawable.getBitmap returns null or the drawable cannot otherwise be represented as a bitmap

See also
toBitmapOrNull

toBitmapOrNull

public static final Bitmap toBitmapOrNull(
    @NonNull Drawable receiver,
    @Px int width,
    @Px int height,
    Bitmap.Config config
)

Returns a Bitmap representation of this Drawable or null if the drawable cannot be represented as a bitmap.

If this instance is a BitmapDrawable and the width, height, and config match, the underlying Bitmap instance will be returned directly. If any of those three properties differ then a new Bitmap is created. For all other Drawable types, a new Bitmap is created.

If the result of BitmapDrawable.getBitmap is null or the drawable cannot otherwise be represented as a bitmap, returns null.

Parameters
@Px int width

Width of the desired bitmap. Defaults to Drawable.getIntrinsicWidth.

@Px int height

Height of the desired bitmap. Defaults to Drawable.getIntrinsicHeight.

Bitmap.Config config

Bitmap config of the desired bitmap. Null attempts to use the native config, if any. Defaults to Config.ARGB_8888 otherwise.

See also
toBitmap

updateBounds

public static final void updateBounds(
    @NonNull Drawable receiver,
    @Px int left,
    @Px int top,
    @Px int right,
    @Px int bottom
)

Updates this drawable's bounds. This version of the method allows using named parameters to just set one or more axes.

See also
setBounds