Color representation in r,g,b with values [0.0 - 1.0]. : Color « 2D Graphics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » 2D Graphics » ColorScreenshots 
Color representation in r,g,b with values [0.0 - 1.0].
 
//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
{
    /// <summary>
    /// Color representation in r,g,b with values [0.0 - 1.0].
    /// </summary>
    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;
        }

        /// <summary>
        /// Each value must be in the span 0 - 255.
        /// </summary>
        /// <param name="red"></param>
        /// <param name="green"></param>
        /// <param name="blue"></param>
        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;
        }

        /// <summary>
        /// Each value must be in the span 0.0 - 1.0.
        /// </summary>
        /// <param name="red"></param>
        /// <param name="green"></param>
        /// <param name="blue"></param>
        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]");
                }
            }
        }
    }
}

   
  
Related examples in the same category
1.Transparent colorTransparent color
2.List all known color in a systemList all known color in a system
3.Draw each of 100 cells with randomly chosen colorsDraw each of 100 cells with randomly chosen colors
4.Filled with the semi transparent and transparent colorFilled with the semi transparent and transparent color
5.All the colors that are supported in C# according
6.Color ChangerColor Changer
7.Known ColorsKnown Colors
8.Five yellow squares with different alpha values(Transparensy)
9.Create two color instances with different alpha components
10.Color.Chocolate
11.Use Color.FromArgb to create Color
12.Get all known color
13.Color representation in h,s,v with h = [0 - 360], s,v = [0.0 - 1.0].
14.Return a randomly-generated color
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.