HexToRgb {DescTools} | R Documentation |
HexToRgb()
converts a hexstring color the its red/green/blue representation.
HexToRgb(hex)
hex |
a color or a vector of colors specified as hexadecimal string of the form "#RRGGBB" or "#RRGGBBAA" |
A hex color is written as a hash character, "#", followed by 3 or 4 hexadecimal numbers, say 6, resp. 8, digits (0-9A-F). The first 3 pairs of digits specify the red, green and blue components. When there are 8 digits, then the last pair is interpreted as alpha channel defining transparency, where 00
represents a fully transparent color and FF
represent a fully opaque color.
The result will be returned as a matrix having 3 or 4 rows, depending on if the input contained a RRGGBBAA
definition or not. No distinction is made between upper and lower case. A missing leading # is tolerated.
a matrix with 3 or 4 rows.
Andri Signorell <andri@signorell.net>
HexToRgb(c("#ADD8E6", "#FA1572"))
# 4-digit representation returns a 4 row matrix
HexToRgb(hex=c("#A52A2ABB","#A52A3B","C52A3B"))