class

Image::RGBA8

Inherits Image::PixelBuffer < Reference < Object

RGBA8 is an in-memory image storing Color::RGBA8 pixels.

This is the most common image type for color images with transparency. Pixels are stored in a contiguous byte buffer (4 bytes per pixel: R, G, B, A).

Storage format: Raw bytes in R, G, B, A order Memory usage: width × height × 4 bytes

Features:

  • Direct byte buffer access via pix method
  • Sub-image support (shares underlying buffer)
  • Stride support for flexible memory layouts

Example:

img = Image::RGBA8.new(Image.rect(0, 0, 640, 480))
img[10, 20] = Image::Color::RGBA8.new(255, 0, 0, 255)
pixel = img[10, 20] # Returns Color::RGBA8

Constructors

new(pix : Bytes, stride : Int32, rect : Rectangle)
Source
new(rect : Rectangle)
Source

Instance methods

at(x : Int32, y : Int32) : Color::RGBA8

Returns the pixel at (x, y), or default value if out of bounds

Source
bounds

Returns the rectangular bounds where pixels are defined

Source
pix

Direct access to underlying byte buffer

Source
set(x : Int32, y : Int32, pixel : Color::RGBA8) : Nil

Sets the pixel at (x, y), no-op if out of bounds

Source
stride

Stride in bytes (bytes per row, may be larger than width * 4 for sub-images)

Source
sub_image(rect : Rectangle) : RGBA8

Returns a sub-image that shares the same byte buffer

Source
unsafe_at(x : Int32, y : Int32) : Color::RGBA8

Returns the pixel at (x, y) without bounds checking. undefined behavior if out of bounds.

Source