Bitmap

Constructors

Link copied to clipboard
constructor()

Creates an empty Bitmap without pixels, with ColorType.UNKNOWN, ColorAlphaType.UNKNOWN, and with a width and height of zero. PixelRef origin is set to (0, 0). Bitmap is not volatile.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Returns IRect { 0, 0, width(), height() }.

Link copied to clipboard
open val bytesPerPixel: Int

Returns number of bytes per pixel required by ColorType. Returns zero if colorType is ColorType.UNKNOWN.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Returns a unique value corresponding to the pixels in PixelRef. Returns a different value after notifyPixelsChanged() has been called. Returns zero if PixelRef is null.

Link copied to clipboard
open val height: Int

Returns pixel row count.

Link copied to clipboard
open override val imageInfo: ImageInfo
Link copied to clipboard
expect open val isClosed: Boolean

Check if underlying resource is closed.

Link copied to clipboard
open val isEmpty: Boolean

Returns true if either getWidth() or getHeight() are zero.

Link copied to clipboard

Returns true if pixels can not change.

Link copied to clipboard

Returns true if PixelRef is null.

Link copied to clipboard
open val isOpaque: Boolean

Returns true if ColorAlphaType is set to hint that all pixels are opaque; their alpha value is implicitly or explicitly 1.0. If true, and all pixels are not opaque, Skia may draw incorrectly.

Link copied to clipboard

Returns true if Bitmap can be drawn.

Link copied to clipboard

Returns PixelRef, which contains: pixel base address; its dimensions; and rowBytes(), the interval from one row to the next. PixelRef may be shared by multiple bitmaps. If PixelRef has not been set, returns null.

Link copied to clipboard

Returns origin of pixels within PixelRef. Bitmap bounds is always contained by PixelRef bounds, which may be the same size or larger. Multiple Bitmap can share the same PixelRef, where each Bitmap has different bounds.

Link copied to clipboard

Returns row bytes, the interval from one pixel row to the next. Row bytes is at least as large as: getWidth() * getBytesPerPixel().

Link copied to clipboard

Returns number of pixels that fit on row. Should be greater than or equal to getWidth().

Link copied to clipboard
open val shiftPerPixel: Int

Returns bit shift converting row bytes to row pixels. Returns zero for ColorType.UNKNOWN.

Link copied to clipboard

Returns the bounds of this bitmap, offset by its PixelRef origin.

Link copied to clipboard
open val width: Int

Returns pixel count in each row. Should be equal or less than getRowBytes() / getImageInfo().getBytesPerPixel().

Functions

Link copied to clipboard
fun allocN32Pixels(width: Int, height: Int, opaque: Boolean = false): Boolean

Sets ImageInfo to width, height, and native color type; and allocates pixel memory. Sets ImageInfo to ColorAlphaType.PREMUL.

Link copied to clipboard

Allocates pixel memory with HeapAllocator, and replaces existing PixelRef. The allocation size is determined by ImageInfo width, height, and ColorType.

fun allocPixels(imageInfo: ImageInfo): Boolean

Sets ImageInfo to info following the rules in .setImageInfo and allocates pixel memory.

fun allocPixels(info: ImageInfo, rowBytes: Int): Boolean

Sets ImageInfo to info following the rules in setImageInfo() and allocates pixel memory. rowBytes must equal or exceed info.width() times info.bytesPerPixel(), or equal zero.

Link copied to clipboard
fun allocPixelsFlags(imageInfo: ImageInfo, zeroPixels: Boolean): Boolean

Sets ImageInfo to info following the rules in setImageInfo() and allocates pixel memory. Memory is zeroed.

Link copied to clipboard
expect open fun close()

Free underlying native resource, peer is useless afterwards.

Link copied to clipboard

Returns minimum memory required for pixel storage. Does not include unused memory on last row when getRowBytesAsPixels() exceeds getWidth(). Returns zero if height() or width() is 0. Returns getHeight() times getRowBytes() if getColorType() is ColorType.UNKNOWN.

Link copied to clipboard

Returns true if all pixels are opaque. ColorType determines how pixels are encoded, and whether pixel describes alpha. Returns true for ColorType without alpha in each pixel; for other ColorType, returns true if all pixels have alpha values equivalent to 1.0 or greater.

Link copied to clipboard

Returns true if width or height are zero, or if PixelRef is null. If true, Bitmap has no effect when drawn or drawn into.

Link copied to clipboard
fun erase(color: Int): Bitmap

Replaces pixel values with color, interpreted as being in the sRGB ColorSpace. All pixels contained by getBounds() are affected. If the getColorType() is ColorType.GRAY_8 or ColorType.RGB_565, then alpha is ignored; RGB is treated as opaque. If getColorType() is ColorType.ALPHA_8, then RGB is ignored.

fun erase(color: Int, area: IRect): Bitmap

Replaces pixel values inside area with color, interpreted as being in the sRGB ColorSpace. If area does not intersect getBounds(), call has no effect.

Link copied to clipboard
fun extractAlpha(dst: Bitmap, paint: Paint?): IPoint?

Sets dst to alpha described by pixels. Returns false if dst cannot be written to or dst pixels cannot be allocated.

Link copied to clipboard
fun extractSubset(dst: Bitmap, subset: IRect): Boolean

Shares PixelRef with dst. Pixels are not copied; this and dst point to the same pixels; dst.getBounds() are set to the intersection of subset and the original getBounds().

Link copied to clipboard
fun getAlphaf(x: Int, y: Int): Float

Look up the pixel at (x,y) and return its alpha component, normalized to 0..1. This is roughly equivalent to GetColorA(getColor()), but can be more efficent (and more precise if the pixels store more than 8 bits per component).

Link copied to clipboard
fun getColor(x: Int, y: Int): Int

Returns pixel at (x, y) as unpremultiplied color. Returns black with alpha if ColorType is ColorType.ALPHA_8.

Link copied to clipboard

fun installPixels(info: ImageInfo, pixels: ByteArray?, rowBytes: Int): Boolean

Sets ImageInfo to info following the rules in setImageInfo(), and creates PixelRef containing pixels and rowBytes.

Link copied to clipboard

Copies settings from src to returned Bitmap. Shares pixels if src has pixels allocated, so both bitmaps reference the same pixels.

Link copied to clipboard
fun makeShader(localMatrix: Matrix33?): Shader
fun makeShader(tmx: FilterTileMode, tmy: FilterTileMode, localMatrix: Matrix33?): Shader
fun makeShader(tmx: FilterTileMode = FilterTileMode.CLAMP, tmy: FilterTileMode = FilterTileMode.CLAMP, sampling: SamplingMode = SamplingMode.DEFAULT, localMatrix: Matrix33? = null): Shader
Link copied to clipboard

Marks that pixels in PixelRef have changed. Subsequent calls to getGenerationId() return a different value.

Link copied to clipboard

Create a pixmap and copy buffer contents into it

Link copied to clipboard
fun readPixels(dstInfo: ImageInfo = imageInfo, dstRowBytes: Int = rowBytes, srcX: Int = 0, srcY: Int = 0): ByteArray?

Copies a rect of pixels from Bitmap. Copy starts at (srcX, srcY), and does not exceed Bitmap (getWidth(), getHeight()).

Link copied to clipboard
fun reset(): Bitmap

Resets to its initial state; all fields are set to zero, as if Bitmap had been initialized by Bitmap().

Link copied to clipboard

Sets alpha type, if argument is compatible with current color type. Returns true unless argument is ColorAlphaType.UNKNOWN and current value is ColorAlphaType.UNKNOWN.

Link copied to clipboard
fun setImageInfo(imageInfo: ImageInfo): Boolean

Sets width, height, ColorAlphaType, ColorType, ColorSpace. Frees pixels, and returns true if successful.

fun setImageInfo(imageInfo: ImageInfo, rowBytes: Int): Boolean

Sets width, height, ColorAlphaType, ColorType, ColorSpace, and optional rowBytes. Frees pixels, and returns true if successful.

Link copied to clipboard

Sets internal flag to mark Bitmap as immutable. Once set, pixels can not change. Any other bitmap sharing the same PixelRef are also marked as immutable. Once PixelRef is marked immutable, the setting cannot be cleared.

Link copied to clipboard
fun setPixelRef(pixelRef: PixelRef?, dx: Int, dy: Int): Bitmap

Replaces pixelRef and origin in Bitmap. dx and dy specify the offset within the PixelRef pixels for the top-left corner of the bitmap.

Link copied to clipboard
fun swap(other: Bitmap)

Swaps the fields of the two bitmaps.

Link copied to clipboard
Link copied to clipboard
expect open override fun toString(): String