private QuantumType[] GetValueWithoutIndexChannel() { if (_Collection == null) { return(Value); } int index = _Collection.GetIndex(PixelChannel.Index); if (index == -1) { return(Value); } List <QuantumType> newValue = new List <QuantumType>(Value); newValue.RemoveAt(index); return(newValue.ToArray()); }
/// <summary> /// Converts the pixel to a color. Assumes the pixel is RGBA. /// </summary> /// <returns>A <see cref="MagickColor"/> instance.</returns> public MagickColor ToColor() { QuantumType[] value = GetValueWithoutIndexChannel(); if (value.Length == 0) { return(null); } if (value.Length == 1) { return(new MagickColor(value[0], value[0], value[0])); } if (value.Length == 2) { return(new MagickColor(value[0], value[0], value[0], value[1])); } bool hasBlackChannel = _collection != null && _collection.GetIndex(PixelChannel.Black) != -1; bool hasAlphaChannel = _collection != null && _collection.GetIndex(PixelChannel.Alpha) != -1; if (hasBlackChannel) { if (value.Length == 4 || !hasAlphaChannel) { return(new MagickColor(value[0], value[1], value[2], value[3], Quantum.Max)); } return(new MagickColor(value[0], value[1], value[2], value[3], value[4])); } if (value.Length == 3 || !hasAlphaChannel) { return(new MagickColor(value[0], value[1], value[2])); } return(new MagickColor(value[0], value[1], value[2], value[3])); }