as.array.bm_matrix: Cast bitmap/pixmap objects to an array

as.array.bm_bitmapR Documentation

Cast bitmap/pixmap objects to an array

Description

as.array.bm_bitmap() / as.array.bm_pixmap() casts bm_bitmap() / bm_pixmap() objects to an array of numeric values representing the RGBA channels. These arrays can be used in functions such as png::writePNG().

Usage

## S3 method for class 'bm_bitmap'
as.array(
  x,
  ...,
  first_row_is_top = TRUE,
  col = getOption("bittermelon.col", col_bitmap)
)

## S3 method for class 'bm_pixmap'
as.array(x, ..., first_row_is_top = TRUE)

Arguments

x

Either a bm_bitmap() or bm_pixmap() object.

...

Currently ignored.

first_row_is_top

If TRUE the first row of the matrix will represent the top of the bitmap (like grDevices::as.raster() objects). If FALSE the first row of the matrix will represent the bottom of the bitmap (like bm_bitmap() and bm_pixmap() objects).

col

Character vector of R color specifications. First color is used for values equal to 0, second color for values equal to 1, etc.

Examples

corn <- farming_crops_16x16()$corn$portrait
a <- as.array(corn)
f <- tempfile(fileext = ".png")
png::writePNG(a, f)

bittermelon documentation built on June 25, 2024, 5:09 p.m.