private void ParseQ16HexColor(string color) { if (color.Length < 13) { ParseQ8HexColor(color); } else if (color.Length == 13 || color.Length == 17) { QuantumType red = (QuantumType)ParseHex(color, 1, 4); QuantumType green = (QuantumType)ParseHex(color, 5, 4); QuantumType blue = (QuantumType)ParseHex(color, 9, 4); QuantumType alpha = Quantum.Max; if (color.Length == 17) { alpha = (QuantumType)ParseHex(color, 13, 4); } _Instance = new Wrapper.MagickColor(red, green, blue, alpha); } else { throw new ArgumentException("Invalid hex value."); } }
internal static MagickColor Create(Wrapper.MagickColor value) { if (value == null) { return(null); } return(new MagickColor(value)); }
/// <summary> /// Updates the color value in an inherited class. /// </summary> protected override void UpdateValue() { Tuple <double, double, double> value = new Tuple <double, double, double>(Hue, Saturation, Luminosity); Wrapper.MagickColor color = Wrapper.MagickColor.ConvertHSLToRGB(value); Value.R = color.R; Value.G = color.G; Value.B = color.B; }
private void ParseQ8HexColor(string color) { byte red; byte green; byte blue; byte alpha = 255; if (color.Length == 4 || color.Length == 5) { red = (byte)ParseHex(color, 1, 1); red += (byte)(red * 16); green = (byte)ParseHex(color, 2, 1); green += (byte)(green * 16); blue = (byte)ParseHex(color, 3, 1); blue += (byte)(blue * 16); if (color.Length == 5) { alpha = (byte)ParseHex(color, 4, 1); alpha += (byte)(alpha * 16); } } else if (color.Length == 7 || color.Length == 9) { red = (byte)ParseHex(color, 1, 2); green = (byte)ParseHex(color, 3, 2); blue = (byte)ParseHex(color, 5, 2); if (color.Length == 9) { alpha = (byte)ParseHex(color, 7, 2); } } else { throw new ArgumentException("Invalid hex value."); } _Instance = new Wrapper.MagickColor(Quantum.Convert(red), Quantum.Convert(green), Quantum.Convert(blue), Quantum.Convert(alpha)); }
///========================================================================================== ///<summary> /// Initializes a new instance of the MagickColor class using the specified RGBA hex string or /// name of the color (http://www.imagemagick.org/script/color.php). /// For example: #F00, #F00C, #FF0000, #FF0000CC ///</summary> ///<param name="color">The RGBA/CMYK hex string or name of the color.</param> #elif Q16 || Q16HDRI ///<summary> /// Initializes a new instance of the MagickColor class using the specified RGBA hex string or /// name of the color (http://www.imagemagick.org/script/color.php). /// For example: #F00, #F00C, #FF0000, #FF0000CC, #FFFF00000000, #FFFF00000000CCCC ///</summary> ///<param name="color">The RGBA/CMYK hex string or name of the color.</param> #else #error Not implemented! #endif public MagickColor(string color) { Throw.IfNullOrEmpty("color", color); if (color.Equals("transparent", StringComparison.OrdinalIgnoreCase)) { _Instance = new Wrapper.MagickColor(Quantum.Max, Quantum.Max, Quantum.Max, 0); return; } if (color[0] == '#') { #if Q8 ParseQ8HexColor(color); #elif Q16 || Q16HDRI ParseQ16HexColor(color); #else #error Not implemented! #endif return; } _Instance = new Wrapper.MagickColor(color); }
private MagickColor(Wrapper.MagickColor instance) { _Instance = instance; }
public MagickColor(QuantumType cyan, QuantumType magenta, QuantumType yellow, QuantumType black, QuantumType alpha) { _Instance = new Wrapper.MagickColor(cyan, magenta, yellow, black, alpha); }
public MagickColor(QuantumType red, QuantumType green, QuantumType blue, QuantumType alpha) { _Instance = new Wrapper.MagickColor(red, green, blue, alpha); }
///<summary> /// Initializes a new instance of the MagickColor class using the specified color. ///</summary> ///<param name="color">The color to use.</param> public MagickColor(Color color) { _Instance = new Wrapper.MagickColor(color); }
///<summary> /// Initializes a new instance of the MagickColor class. ///</summary> public MagickColor() { _Instance = new Wrapper.MagickColor(); }
internal MagickColor(MagickColor color) { _Instance = new Wrapper.MagickColor(color._Instance); }