IccNamedColorCollection Class
The colors of an ICC named color profile, in the order of the profile, and their lookup by name.
public sealed class IccNamedColorCollection : IEnumerable<IccNamedColor>, IReadOnlyCollection<IccNamedColor>, IReadOnlyList<IccNamedColor>, IEnumerableRemarks
Version 2 and 4 profiles store their colors in a namedColor2Tag (ICC.1:2022 section 10.17): a 7-bit ASCII name made of a prefix, a root name and a suffix, the media-relative colorimetry in the connection space of the profile, and optionally the device values of its data color space. Version 5 (iccMAX) profiles store them in a namedColorTag (ICC.2:2023 section 9.2.104) with a UTF-8 name and values for several tints; the collection holds the color at full tint (1.0). The spectral data of an iccMAX color are not read.
Instances are immutable and thread-safe. A name that appears several times refers to its first color.
Example
public static (byte[] Rgb, IReadOnlyList<double> Inks) SpotColor(string swatchBookPath, string name)
{
var swatchBook = new IccProfile(new MetadataBlob(File.ReadAllBytes(swatchBookPath)));
var colors = IccNamedColorCollection.Create(swatchBook);
if (!colors.TryGetValue(name, out var color))
throw new ArgumentException($"The swatch book has no color named '{name}'.", nameof(name));
// The colorimetry of the color, converted to the device values of the display (relative colorimetric intent)
var transform = IccNamedColorTransform.Create(swatchBook, IccProfile.Srgb);
var rgb = new byte[transform.DestinationChannelCount];
transform.Convert(color, rgb);
// On the press the profile was made for, its device values (here CMYK inks) reproduce the color exactly
return (rgb, color.DeviceValues);
}- Implements
Properties
| Name | Description |
|---|---|
| Count | Gets the number of colors. |
| DeviceChannelCount | Gets the number of device values of each color (IccNamedColor.DeviceValues); 0 when the profile gives none. |
| Profile | Gets the named color profile the colors were read from. |
DeviceChannelCount
IccNamedColorCollection.csGets the number of device values of each color (IccNamedColor.DeviceValues); 0 when the profile gives none.
public int DeviceChannelCount { get; }Property value
Profile
IccNamedColorCollection.csGets the named color profile the colors were read from.
public IccProfile Profile { get; }Property value
Indexers
| Name | Description |
|---|---|
| this[int] | Gets the color at an index, in the order of the profile. |
| this[string] | Gets the color with a name (ordinal, case-sensitive comparison). |
Item overloads
this[int]
IccNamedColorCollection.csGets the color at an index, in the order of the profile.
public IccNamedColor this[int index] { get; }Parameters
indexint- The index.
Property value
Exceptions
ArgumentOutOfRangeExceptionindexis negative or not less thanIccNamedColorCollection.Count.
this[string]
IccNamedColorCollection.csGets the color with a name (ordinal, case-sensitive comparison).
public IccNamedColor this[string name] { get; }Parameters
namestring- The full name of the color.
Property value
Exceptions
ArgumentNullExceptionnameisnull.KeyNotFoundException- No color has this name.
Methods
| Name | Description |
|---|---|
| Create(IccProfile) | Reads the colors of a named color profile. |
| GetEnumerator() | Returns an enumerator that iterates through the collection. |
| IndexOf(string) | Gets the index of the first color with a name (ordinal, case-sensitive comparison). |
| System.Collections.IEnumerable.GetEnumerator() | |
| TryGetValue(string, IccNamedColor?) | Gets the color with a name (ordinal, case-sensitive comparison). |
Create(IccProfile)
IccNamedColorCollection.csReads the colors of a named color profile.
public static IccNamedColorCollection Create(IccProfile profile)Parameters
profileIccProfile- A profile of the
IccProfileClass.NamedColorclass.
Returns
IccNamedColorCollection The colors.
Exceptions
ArgumentNullExceptionprofileisnull.ArgumentExceptionprofileis not a named color profile.InvalidImageContentException- The profile is malformed.
UnsupportedImageFeatureException- The profile is valid but its colors cannot be read: the connection space is neither CIEXYZ nor CIELAB (a spectral iccMAX profile), or an iccMAX color has no value at full tint or stores its colorimetry as integers.
GetEnumerator()
IccNamedColorCollection.csReturns an enumerator that iterates through the collection.
public IEnumerator<IccNamedColor> GetEnumerator()Returns
IEnumerator<IccNamedColor> An enumerator that can be used to iterate through the collection.
IndexOf(string)
IccNamedColorCollection.csGets the index of the first color with a name (ordinal, case-sensitive comparison).
Parameters
namestring- The full name of the color.
Returns
int The index, or -1 when no color has this name.
Exceptions
ArgumentNullExceptionnameisnull.
System.Collections.IEnumerable.GetEnumerator()
IccNamedColorCollection.csTryGetValue(string, IccNamedColor?)
IccNamedColorCollection.csGets the color with a name (ordinal, case-sensitive comparison).
public bool TryGetValue(string name, out IccNamedColor? color)Parameters
namestring- The full name of the color.
colorIccNamedColor?- The first color with this name, or
null.
Returns
bool true when a color has this name.
Exceptions
ArgumentNullExceptionnameisnull.