Skip to content

RGB.ToHex

Converts RGB color values to hexadecimal format

EvaluationContext.Colour.RGB.ToHex( red, green, blue, alpha )
Parameter Type Required Description
red INT64 The red value (0-255)
green INT64 The green value (0-255)
blue INT64 The blue value (0-255)
alpha DOUBLE The alpha value (0-1)

STRING Hex color string with optional alpha

EvaluationContext.Colour.RGB.ToHex(255, 0, 0) // Returns "#FF0000"
EvaluationContext.Colour.RGB.ToHex(255, 0, 0, 0.5) // Returns "#FF000080"
EvaluationContext.Colour.RGB.ToHex =
    (
        red: INT64,
        green: INT64,
        blue: INT64,
        alpha: DOUBLE
    ) =>

        "#" &
        EvaluationContext.Colour.Int.ToHex( red, 2 ) &
        EvaluationContext.Colour.Int.ToHex( green, 2 ) &
        EvaluationContext.Colour.Int.ToHex( blue, 2 ) &
        IF( NOT ISBLANK( alpha ), EvaluationContext.Colour.Int.ToHex( alpha * 255, 2 ) )