class CrImage::Color

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.default : Color #

[View source]
def self.new(red : UInt8, green : UInt8, blue : UInt8, alpha : UInt8 = ChannelType::Alpha.default) #

[View source]
def self.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)

[View source]
def self.random : Color #

Generate a random color with full (255) opacity


[View source]

Instance Method Detail

def ==(other : Color) : Bool #

[View source]
def [](channel_type : ChannelType) : UInt8 #

Receive the UInt8 portion of this color corresponding to channel_type


[View source]
def alpha : UInt8 #

[View source]
def blue : UInt8 #

[View source]
def dist(other : Color, *, manhattan : Bool = false) : Float64 #

[View source]
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


[View source]
def green : UInt8 #

[View source]
def red : UInt8 #

[View source]