Skip to main content

HEX to RGB

This method converts the specified hexadecimal color representation to RGB color values.

Syntax

hexToRgb(hexColor)

Parameters

  • hexColor : string
    The String representing the color to be converted, it can be either in the normal format #ff00ff or in the short format #f0f.

Return

  • object
    An object containing the RGB representation:
{
r: number,
g: number,
b: number
}

Throws

  • Error
    Thrown if the input hexadecimal color representation is invalid.

Examples

const editpix = new EditPix()

const blackHex = "#000000";
console.log(editpix.hexToRgb(blackHex))

const whiteHex = "#fff";
console.log(editpix.hexToRgb(whiteHex))

const hexColorsArray = ["#000", "#ffffff", "#ff0000"]
hexColorsArray.forEach(color => {
console.log(editpix.hexToRgb(color))
});