/// <summary> /// Get color by parsing given RGBA value color string (RGBA(255,180,90,180)) /// </summary> /// <returns>true - valid color, false - otherwise</returns> private static bool GetColorByRgba(string str, int idx, int length, out CssColor color) { int r = -1; int g = -1; int b = -1; int a = -1; if (length > 13) { int s = idx + 5; r = ParseIntAtIndex(str, ref s); if (s < idx + length) { g = ParseIntAtIndex(str, ref s); } if (s < idx + length) { b = ParseIntAtIndex(str, ref s); } if (s < idx + length) { a = ParseIntAtIndex(str, ref s); } } if (r > -1 && g > -1 && b > -1 && a > -1) { color = CssColor.FromArgb(a, r, g, b); return(true); } color = CssColor.Empty; return(false); }
/// <summary> /// Get color by parsing given hex value color string (#A28B34). /// </summary> /// <returns>true - valid color, false - otherwise</returns> private static bool GetColorByHex(string str, int idx, int length, out CssColor color) { int r = -1; int g = -1; int b = -1; if (length == 7) { r = ParseHexInt(str, idx + 1, 2); g = ParseHexInt(str, idx + 3, 2); b = ParseHexInt(str, idx + 5, 2); } else if (length == 4) { r = ParseHexInt(str, idx + 1, 1); r = r * 16 + r; g = ParseHexInt(str, idx + 2, 1); g = g * 16 + g; b = ParseHexInt(str, idx + 3, 1); b = b * 16 + b; } if (r > -1 && g > -1 && b > -1) { color = CssColor.FromArgb(r, g, b); return(true); } color = CssColor.Empty; return(false); }