writePixels

fun writePixels(bitmap: Bitmap, x: Int, y: Int): Boolean

Copies Rect from pixels to Canvas. Matrix and clip are ignored. Source Rect corners are (0, 0) and (bitmap.width(), bitmap.height()).

Destination Rect corners are (x, y) and (imageInfo().width(), imageInfo().height()).

Copies each readable pixel intersecting both rectangles, without scaling, converting to getImageInfo().getColorType() and getImageInfo().getAlphaType() if required.

Pixels are writable when BaseDevice is raster, or backed by a GPU. Pixels are not writable when Canvas is returned by Document::beginPage, returned by PictureRecorder::beginRecording, or Canvas is the base of a utility class like DebugCanvas.

Pixel values are converted only if ColorType and AlphaType do not match. Only pixels within both source and destination rectangles are copied. Canvas pixels outside Rect intersection are unchanged.

Pass negative values for x or y to offset pixels to the left or above Canvas pixels.

Does not copy, and returns false if:

  • Source and destination rectangles do not intersect.

  • bitmap does not have allocated pixels.

  • bitmap pixels could not be converted to Canvas getImageInfo().getColorType() or getImageInfo().getAlphaType().

  • Canvas pixels are not writable; for instance, Canvas is document based.

  • bitmap pixels are inaccessible; for instance, bitmap wraps a texture.

Return

true if pixels were written to Canvas

Parameters

bitmap

contains pixels copied to Canvas

x

offset into Canvas writable pixels on x-axis; may be negative

y

offset into Canvas writable pixels on y-axis; may be negative

See also