Color representation in r,g,b with values [0.0 – 1.0].

image_pdfimage_print

//GNU General Public License version 2 (GPLv2)
//http://dotwayutilities.codeplex.com/license

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using System.ComponentModel;

namespace Dotway.WPF.Controls.Utilities
{
///

/// Color representation in r,g,b with values [0.0 – 1.0].
///

public struct RGB
{
public RGB(Color color)
{
r = 0.0;
g = 0.0;
b = 0.0;

R = color.R / 255.0;
G = color.G / 255.0;
B = color.B / 255.0;
}

///

/// Each value must be in the span 0 – 255.
///

/// /// /// public RGB(byte red, byte green, byte blue)
{
r = 0.0;
g = 0.0;
b = 0.0;

R = red / 255.0;
G = green / 255.0;
B = blue / 255.0;
}

///

/// Each value must be in the span 0.0 – 1.0.
///

/// /// /// public RGB(double red, double green, double blue)
{
r = 0.0;
g = 0.0;
b = 0.0;

R = red;
G = green;
B = blue;
}

private double r;
public double R
{
get { return r; }
set
{
if (value >= 0.0 && value <= 1.0) { r = value; } else { throw new ArgumentOutOfRangeException("R is not in the span [0, 1]"); } } } private double g; public double G { get { return g; } set { if (value >= 0.0 && value <= 1.0) { g = value; } else { throw new ArgumentOutOfRangeException("G is not in the span [0, 1]"); } } } private double b; public double B { get { return b; } set { if (value >= 0.0 && value <= 1.0) { b = value; } else { throw new ArgumentOutOfRangeException("B is not in the span [0, 1]"); } } } } } [/csharp]

This entry was posted in 2D Graphics. Bookmark the permalink.