class

CrImage::Color

Inherits Reference < Object

Utility class for parsing and representing colors that can be used for certain methods in CrImage.

See Operation::MaskApply#apply_color, Operation::Draw#draw_square, or Operation::Draw#draw_circle

Constructors

default
Source
new(red : UInt8, green : UInt8, blue : UInt8, alpha : UInt8 = ChannelType::Alpha.default)
Source
of(color : String) : Color

Parse color from a hex string:

Color.of("#1")        # same as "#11" => Color.new(17, 17, 17, 255)
Color.of("#01")       # => Color.new(1, 1, 1, 255)
Color.of("#123")      # same as "#112233" => Color.new(17, 34, 51, 255)
Color.of("#1234")     # same as "#11223344" => Color.new(34, 51, 68, 17)
Color.of("#010203")   # => Color.new(1, 2, 3, 255)
Color.of("#01020304") # => Color.new(2, 3, 4, 1)
Source
random

Generate a random color with full (255) opacity

Source

Instance methods

==(other : Color) : Bool
Source
[](channel_type : ChannelType) : UInt8

Receive the UInt8 portion of this color corresponding to channel_type

Source
alpha
Source
blue
Source
dist(other : Color, *, manhattan : Bool = false) : Float64
Source
gray(red_multiplier : Float = 0.299, green_multiplier : Float = 0.587, blue_multiplier : Float = 0.114) : UInt8

Convert this Color to a single UInt8 gray value

Source
green
Source