toARGB32 method

int toARGB32()

Returns a 32-bit value representing this color.

The returned value is compatible with the default constructor (Color.new) but does not guarantee to result in the same color due to imprecisions in numeric conversions.

Unlike accessing the floating point equivalent channels individually (a, r, g, b), this method is intentionally lossy, and scales each channel using (channel * 255.0).round() & 0xff.

While useful for storing a 32-bit integer value, prefer accessing the individual channels (and storing the double equivalent) where higher precision is required.

The bits are assigned as follows:

  • Bits 24-31 represents the a channel as an 8-bit unsigned integer.
  • Bits 16-23 represents the r channel as an 8-bit unsigned integer.
  • Bits 8-15 represents the g channel as an 8-bit unsigned integer.
  • Bits 0-7 represents the b channel as an 8-bit unsigned integer.

Warning

The value returned by this getter implicitly converts floating-point component values (such as 0.5) into their 8-bit equivalent by using the toARGB32 method; the returned value is not guaranteed to be stable across different platforms or executions due to the complexity of floating-point math.

Implementation

int toARGB32() {
  return _floatToInt8(a) << 24 |
      _floatToInt8(r) << 16 |
      _floatToInt8(g) << 8 |
      _floatToInt8(b) << 0;
}