Color.fromRGB constructor

const Color.fromRGB(
  1. int r,
  2. int g,
  3. int b
)

Constructs a fully opaque color from the lower 8-bits of 3 integers.

  • r is red, from 0 to 255.
  • g is green, from 0 to 255.
  • b is blue, from 0 to 255.

Out of range values are brought into range using modulo (%) `255.

This constructor is semantically identical to Color.fromARGB where alpha is predefined as 255 (0xFF), suitable for fully opaque colors (i.e. where transparency is not intended or supported).

Implementation

const Color.fromRGB(
  int r,
  int g,
  int b,
) : value = ((0xFF << 24) |
              ((r & 0xFF) << 16) |
              ((g & 0xFF) << 8) |
              ((b & 0xFF) << 0)) &
          0xFFFFFFFF;