BitmapKt

public final class BitmapKt


Summary

Public methods

static final @NonNull Bitmap
BitmapKt.applyCanvas(
    @NonNull Bitmap receiver,
    @NonNull Function1<@NonNull CanvasUnit> block
)

Creates a new Canvas to draw on this bitmap and executes the specified block on the newly created canvas.

static final boolean

Returns true if the specified point is inside the bitmap.

static final boolean

Returns true if the specified point is inside the bitmap.

static final @NonNull Bitmap
createBitmap(int width, int height, @NonNull Bitmap.Config config)

Returns a mutable bitmap with the specified width and height.

static final @RequiresApi(value = "26") @NonNull Bitmap
createBitmap(
    int width,
    int height,
    @NonNull Bitmap.Config config,
    boolean hasAlpha,
    @NonNull ColorSpace colorSpace
)

Returns a mutable bitmap with the specified width and height.

static final int
BitmapKt.get(@NonNull Bitmap receiver, int x, int y)

Returns the value of the pixel at the specified location.

static final @NonNull Bitmap
BitmapKt.scale(
    @NonNull Bitmap receiver,
    int width,
    int height,
    boolean filter
)

Creates a new bitmap, scaled from this bitmap, when possible.

static final void
BitmapKt.set(@NonNull Bitmap receiver, int x, int y, @ColorInt int color)

Writes the specified color int into the bitmap (assuming it is mutable) at the specified (x, y) coordinate.

Public methods

BitmapKt.applyCanvas

@NonNull
public static final Bitmap BitmapKt.applyCanvas(
    @NonNull Bitmap receiver,
    @NonNull Function1<@NonNull CanvasUnit> block
)

Creates a new Canvas to draw on this bitmap and executes the specified block on the newly created canvas. Example:

return Bitmap.createBitmap(…).applyCanvas {
drawLine(…)
translate(…)
drawRect(…)
}

BitmapKt.contains

@NonNull
public static final boolean BitmapKt.contains(@NonNull Bitmap receiver, @NonNull Point p)

Returns true if the specified point is inside the bitmap. A point is contained if: 0 <= x < width and 0 <= y < height. An empty bitmap never contains any point.

BitmapKt.contains

@NonNull
public static final boolean BitmapKt.contains(@NonNull Bitmap receiver, @NonNull PointF p)

Returns true if the specified point is inside the bitmap. A point is contained if: 0 <= x < width and 0 <= y < height. An empty bitmap never contains any point.

createBitmap

@NonNull
public static final Bitmap createBitmap(int width, int height, @NonNull Bitmap.Config config)

Returns a mutable bitmap with the specified width and height. A config can be optionally specified. If not, the default config is Bitmap.Config.ARGB_8888.

Parameters
int width

The new bitmap's desired width

int height

The new bitmap's desired height

@NonNull Bitmap.Config config

The new bitmap's desired config

Returns
Bitmap

A new bitmap with the specified dimensions and config

createBitmap

@RequiresApi(value = "26")
@NonNull
public static final @RequiresApi(value = "26") Bitmap createBitmap(
    int width,
    int height,
    @NonNull Bitmap.Config config,
    boolean hasAlpha,
    @NonNull ColorSpace colorSpace
)

Returns a mutable bitmap with the specified width and height. The config, transparency and color space can optionally be specified. They respectively default to Bitmap.Config.ARGB_8888, true and sRGB.

Parameters
int width

The new bitmap's desired width

int height

The new bitmap's desired height

@NonNull Bitmap.Config config

The new bitmap's desired config

boolean hasAlpha

Whether the new bitmap is opaque or not

@NonNull ColorSpace colorSpace

The new bitmap's color space

Returns
@RequiresApi(value = "26") Bitmap

A new bitmap with the specified dimensions and config

BitmapKt.get

@NonNull
public static final int BitmapKt.get(@NonNull Bitmap receiver, int x, int y)

Returns the value of the pixel at the specified location. The returned value is a color int in the sRGB color space.

BitmapKt.scale

@NonNull
public static final Bitmap BitmapKt.scale(
    @NonNull Bitmap receiver,
    int width,
    int height,
    boolean filter
)

Creates a new bitmap, scaled from this bitmap, when possible. If the specified width and height are the same as the current width and height of this bitmap, this bitmap is returned and no new bitmap is created.

Parameters
int width

The new bitmap's desired width

int height

The new bitmap's desired height

boolean filter

true if the source should be filtered (true by default)

Returns
Bitmap

The new scaled bitmap or the source bitmap if no scaling is required.

BitmapKt.set

@NonNull
public static final void BitmapKt.set(@NonNull Bitmap receiver, int x, int y, @ColorInt int color)

Writes the specified color int into the bitmap (assuming it is mutable) at the specified (x, y) coordinate. The specified color is converted from sRGB to the bitmap's color space if needed.