class

UIng::ImageBuffer

Inherits UIng::BlockConstructor < Reference < Object

A mutable, fixed-resolution RGBA image. All native operations must run on the UI thread between UIng.init and UIng.uninit. Call free explicitly or use open; native resources are not released by a GC finalizer. Requires ImageBuffer-capable libui-ng (dev da49cf29 or later), included in the release pinned in download.cr.

Constructors

new(*args, &)
Source
new(*args, **kwargs, &)
Source
new(width : Int32, height : Int32, *, format : Format = Format::RGBA8Straight)
Source
new(source : CrImage::Image, *, format : Format = CrImageAdapter.image_buffer_format(source))

Creates and fills a buffer. NRGBA/NRGBA64 use straight alpha; other image types use premultiplied alpha. An explicit format overrides that choice.

Source

Class methods

open(width : Int32, height : Int32, *, format : Format = Format::RGBA8Straight, &)

Always frees the buffer, including on exceptions; returns the block value. Keep the event loop inside the block when callbacks refer to this buffer.

Source
open(source : CrImage::Image, *, format : Format = CrImageAdapter.image_buffer_format(source), &)

Keeps the event loop inside the block and frees the buffer on every exit.

Source

Instance methods

format
Source
free

Idempotent. Already submitted draws remain valid after this call.

Source
height
Source
released?
Source
size

Pixel dimensions, independent of drawing coordinates or display DPI.

Source
to_unsafe
Source
update(source : CrImage::Image) : Nil

Copies a CrImage image with matching dimensions. Alpha representation and stride are adapted to this buffer's format. Does not request a redraw.

Source
update(pixels : Bytes, *, byte_stride : Int = @width.to_i64 * 4) : Nil

Copies the input before return. Final-row padding is optional. Straight RGBA is premultiplied natively; premultiplied input requires R, G, B <= A. Updates do not request a redraw; call Area#queue_redraw_all as needed.

Source
update_rect(x : Int32, y : Int32, width : Int32, height : Int32, pixels : Bytes, *, byte_stride : Int = width.to_i64 * 4) : Nil

pixels starts at the patch's top-left pixel. The rectangle must fit fully inside this buffer; pixels outside it are preserved, without compositing.

Source
update_rect(x : Int32, y : Int32, source : CrImage::Image) : Nil

Copies the entire patch at destination (x, y), using its visible bounds for the patch dimensions. Pixels outside the destination are preserved.

Source
width
Source

Nested types