public ColorRgb(ColorRgb32Bit color) { ColorRgb temp = FromColor(color); this._alpha = temp._alpha; this._r = temp._r; this._g = temp._g; this._b = temp._b; }
private static ColorRgb FromColor(ColorRgb32Bit color) { ColorRgb c = new ColorRgb(color.Alpha / 255.0, color.R / 255.0, color.G / 255.0, color.B / 255.0); return(c); }
/// <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 ColorRgb32Bit?TryParseWebColorString(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 (this means alpha was not provided) if (webcolor.Length != 6) { return(null); } int currentColor = 0; bool result = System.Int32.TryParse(webcolor, System.Globalization.NumberStyles.HexNumber, null, out currentColor); if (webcolor.Length == 6) { // only six digits were given so add alpha currentColor = (int)(((uint)currentColor) | ((uint)0xff000000)); } 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 ColorRgb32Bit theColor = new ColorRgb32Bit(currentColor); return(theColor); }
public ColorRgb32Bit(byte alpha, ColorRgb32Bit c) : this(alpha, c.R, c.G, c.B) { }
private bool Equals(ColorRgb32Bit other) { return(this._alpha == other._alpha && this._r == other._r && this._g == other._g && this._b == other._b); }