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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# Book
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
w_w_w._ja__v__a__2__s___.___c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.