R: Convert a Hexstring Color to a Matrix With Three...

HexToRgb {DescTools} | R Documentation

## Convert a Hexstring Color to a Matrix With Three Red/Green/Blue Rows

### Description

`HexToRgb()` converts a hexstring color the its red/green/blue representation.

### Usage

    HexToRgb(hex)

### Arguments

`hex` | a color or a vector of colors specified as hexadecimal string of the form "#RRGGBB" or "#RRGGBBAA"

### Details

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.

### Value

a matrix with 3 or 4 rows.

### Author(s)

Andri Signorell <andri@signorell.net>

### See Also

`HexToCol`

### Examples

    HexToRgb(c("#ADD8E6", "#FA1572"))

    # 4-digit representation returns a 4 row matrix
    HexToRgb(hex=c("#A52A2ABB","#A52A3B","C52A3B"))

[Package DescTools version 0.99.34 Index]