Create Color

IronDrawing enables users to create their own color using various ways including Hexadecimal, RGB values, and also from Enum where the customer can choose an already available color.

Color creation

To create a color using a Hexadecimal value, simply create a variable with the type Color and assign the hexadecimal value in terms of string to the variable using new Color("#191919") method. To create color using RGB values, key in the RGB values new Color(255, 255, 0) and store it inside a Color type variable.

// Creating a color using a Hexadecimal string
Color hexColor = new Color("#191919");

// Creating a color using RGB values
Color rgbColor = new Color(255, 255, 0);
// Creating a color using a Hexadecimal string
Color hexColor = new Color("#191919");

// Creating a color using RGB values
Color rgbColor = new Color(255, 255, 0);
' Creating a color using a Hexadecimal string
Dim hexColor As New Color("#191919")

' Creating a color using RGB values
Dim rgbColor As New Color(255, 255, 0)
$vbLabelText   $csharpLabel

Casting System.Drawing.Color to IronSoftware.Drawing.Color

Simply assign a System.Drawing.Color type variable with a color System.Drawing.Color.Red. Next, assign the variable to a new IronSoftware.Drawing.Color variable. ARGB values can be extracted and read from the color casted.

// Using System.Drawing.Color
System.Drawing.Color systemColor = System.Drawing.Color.Red;

// Casting System.Drawing.Color to IronSoftware.Drawing.Color
IronSoftware.Drawing.Color ironColor = new IronSoftware.Drawing.Color(systemColor);

// Extracting ARGB values
int alpha = ironColor.A;
int red = ironColor.R;
int green = ironColor.G;
int blue = ironColor.B;
// Using System.Drawing.Color
System.Drawing.Color systemColor = System.Drawing.Color.Red;

// Casting System.Drawing.Color to IronSoftware.Drawing.Color
IronSoftware.Drawing.Color ironColor = new IronSoftware.Drawing.Color(systemColor);

// Extracting ARGB values
int alpha = ironColor.A;
int red = ironColor.R;
int green = ironColor.G;
int blue = ironColor.B;
' Using System.Drawing.Color
Dim systemColor As System.Drawing.Color = System.Drawing.Color.Red

' Casting System.Drawing.Color to IronSoftware.Drawing.Color
Dim ironColor As New IronSoftware.Drawing.Color(systemColor)

' Extracting ARGB values
Dim alpha As Integer = ironColor.A
Dim red As Integer = ironColor.R
Dim green As Integer = ironColor.G
Dim blue As Integer = ironColor.B
$vbLabelText   $csharpLabel

Luminance

To get the luminance of the color casted, or any IronSoftware.Drawing.Color, use the .GetLuminance() method on the color. Luminance is a value from 0 (black) to 100 (white) where 50 is the perceptual "middle gray".

// Calculating the luminance of an IronSoftware.Drawing.Color
double luminance = ironColor.GetLuminance();
// Calculating the luminance of an IronSoftware.Drawing.Color
double luminance = ironColor.GetLuminance();
' Calculating the luminance of an IronSoftware.Drawing.Color
Dim luminance As Double = ironColor.GetLuminance()
$vbLabelText   $csharpLabel