class CrImage::Color
- CrImage::Color
- Reference
- Object
Overview
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
Defined in:
cr-image/color.crConstructors
- .default : Color
- .new(red : UInt8, green : UInt8, blue : UInt8, alpha : UInt8 = ChannelType::Alpha.default)
-
.of(color : String) : Color
Parse color from a hex string:
-
.random : Color
Generate a random color with full (255) opacity
Instance Method Summary
- #==(other : Color) : Bool
-
#[](channel_type : ChannelType) : UInt8
Receive the UInt8 portion of this color corresponding to
channel_type
- #alpha : UInt8
- #blue : UInt8
- #dist(other : Color, *, manhattan : Bool = false) : Float64
-
#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
- #green : UInt8
- #red : UInt8
Constructor Detail
def self.new(red : UInt8, green : UInt8, blue : UInt8, alpha : UInt8 = ChannelType::Alpha.default)
#
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)
Instance Method Detail
def [](channel_type : ChannelType) : UInt8
#
Receive the UInt8 portion of this color corresponding to channel_type
def 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