native-encoding {farver} | R Documentation |
Convert to and from the R native colour representation
Description
Colours in R are internally encoded as integers when they are passed around
to graphics devices. The encoding splits the 32 bit in the integer between
red, green, blue, and alpha, so that each get 8 bit, equivalent to 256
values. It is very seldom that an R user is subjected to this representation,
but it is present in the nativeRaster
format which can be obtained from
e.g. capturing the content of a graphic device (using dev.capture()
) or reading
in PNG files using png::readPNG(native = TRUE)
. It is very rare that you
might need to convert back and forth between this format, but it is provided
here for completeness.
Usage
encode_native(colour, ...)
decode_native(colour)
Arguments
colour |
For |
... |
Arguments passed on to |
Value
encode_native()
returns an integer vector and decode_native()
returns a character vector, both matching the length of the input.
Examples
# Get native representation of navyblue and #228B22
native_col <- encode_native(c('navyblue', '#228B22'))
native_col
# Convert back
decode_native(native_col)