Example #1
0
 public string ToWebColorString()
 {
     return(ColorRGB.ToWebColorString(this._r, this._g, this._b));
 }
Example #2
0
 public ColorRGB(uint rgb)
 {
     ColorRGB.GetRGBBytes(rgb, out this._r, out this._g, out this._b);
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <example>
        /// Sample usage:
        ///
        /// System.Drawing.Color c;
        /// bool result = TryParseRGBWebColorString("#ffffff", ref c);
        /// if (result)
        /// {
        ///    //it was correctly parsed
        /// }
        /// else
        /// {
        ///    //it was not correctly parsed
        /// }
        ///
        /// </example>
        /// <param name="webcolor"></param>
        ///<returns></returns>
        public static ColorRGB?TryParseWebColor(string webcolor)
        {
            // fail if string is null
            if (webcolor == null)
            {
                return(null);
            }

            // fail if string is empty
            if (webcolor.Length < 1)
            {
                return(null);
            }


            // clean any leading or trailing whitespace
            webcolor = webcolor.Trim();

            // fail if string is empty
            if (webcolor.Length < 1)
            {
                return(null);
            }

            // strip leading # if it is there
            while (webcolor.StartsWith("#"))
            {
                webcolor = webcolor.Substring(1);
            }

            // clean any leading or trailing whitespace
            webcolor = webcolor.Trim();

            // fail if string is empty
            if (webcolor.Length < 1)
            {
                return(null);
            }

            // fail if string doesn't have exactly 6 digits
            if (webcolor.Length != 6)
            {
                return(null);
            }

            int  current_color;
            bool result = int.TryParse(webcolor, NumberStyles.HexNumber, null, out current_color);

            if (!result)
            {
                // fail if parsing didn't work
                return(null);
            }

            // at this point parsing worked

            // the integer value is converted directly to an rgb value

            var the_color = new ColorRGB(current_color);

            return(the_color);
        }
Example #4
0
 private bool Equals(ColorRGB other)
 {
     return(this._r == other._r && this._g == other._g && this._b == other._b);
 }
Example #5
0
 private bool Equals(ColorRGB other)
 {
     return (this._r == other._r && this._g == other._g && this._b == other._b);
 }
Example #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <example>
        /// Sample usage:
        ///
        /// System.Drawing.Color c;
        /// bool result = TryParseRGBWebColorString("#ffffff", ref c);
        /// if (result)
        /// {
        ///    //it was correctly parsed
        /// }
        /// else
        /// {
        ///    //it was not correctly parsed
        /// }
        ///
        /// </example>
        /// <param name="webcolor"></param>
        ///<returns></returns>
        public static ColorRGB? TryParseWebColor(string webcolor)
        {
            // fail if string is null
            if (webcolor == null)
            {
                return null;
            }

            // fail if string is empty
            if (webcolor.Length < 1)
            {
                return null;
            }

            // clean any leading or trailing whitespace
            webcolor = webcolor.Trim();

            // fail if string is empty
            if (webcolor.Length < 1)
            {
                return null;
            }

            // strip leading # if it is there
            while (webcolor.StartsWith("#"))
            {
                webcolor = webcolor.Substring(1);
            }

            // clean any leading or trailing whitespace
            webcolor = webcolor.Trim();

            // fail if string is empty
            if (webcolor.Length < 1)
            {
                return null;
            }

            // fail if string doesn't have exactly 6 digits
            if (webcolor.Length != 6)
            {
                return null;
            }

            int current_color;
            bool result = int.TryParse(webcolor, NumberStyles.HexNumber, null, out current_color);

            if (!result)
            {
                // fail if parsing didn't work
                return null;
            }

            // at this point parsing worked

            // the integer value is converted directly to an rgb value

            var the_color = new ColorRGB(current_color);
            return the_color;
        }