本文整理汇总了C#中ColorCollection.GetName方法的典型用法代码示例。如果您正苦于以下问题:C# ColorCollection.GetName方法的具体用法?C# ColorCollection.GetName怎么用?C# ColorCollection.GetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ColorCollection
的用法示例。
在下文中一共展示了ColorCollection.GetName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WritePalette
protected virtual void WritePalette(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatchFileVersion version, AdobePhotoshopColorSwatchColorSpace colorSpace)
{
int swatchIndex;
this.WriteInt16(stream, (short)version);
this.WriteInt16(stream, (short)palette.Count);
swatchIndex = 0;
foreach (Color color in palette)
{
short value1;
short value2;
short value3;
short value4;
swatchIndex++;
switch (colorSpace)
{
case AdobePhotoshopColorSwatchColorSpace.Rgb:
value1 = (short)(color.R * 256);
value2 = (short)(color.G * 256);
value3 = (short)(color.B * 256);
value4 = 0;
break;
case AdobePhotoshopColorSwatchColorSpace.Hsb:
value1 = (short)(color.GetHue() * 182.04);
value2 = (short)(color.GetSaturation() * 655.35);
value3 = (short)(color.GetBrightness() * 655.35);
value4 = 0;
break;
case AdobePhotoshopColorSwatchColorSpace.Grayscale:
if (color.R == color.G && color.R == color.B)
{
// already grayscale
value1 = (short)(color.R * 39.0625);
}
else
{
// color is not grayscale, convert
value1 = (short)(((color.R + color.G + color.B) / 3.0) * 39.0625);
}
value2 = 0;
value3 = 0;
value4 = 0;
break;
default:
throw new InvalidOperationException("Color space not supported.");
}
this.WriteInt16(stream, (short)colorSpace);
this.WriteInt16(stream, value1);
this.WriteInt16(stream, value2);
this.WriteInt16(stream, value3);
this.WriteInt16(stream, value4);
if (version == AdobePhotoshopColorSwatchFileVersion.Version2)
{
string name;
#if USENAMEHACK
name = palette.GetName(swatchIndex - 1);
if (string.IsNullOrEmpty(name))
{
name = string.Format("Swatch {0}", swatchIndex);
}
#else
name = color.IsNamedColor ? color.Name : string.Format("Swatch {0}", swatchIndex);
#endif
this.WriteInt32(stream, name.Length);
this.WriteString(stream, name);
}
}
}
开发者ID:FrankGITDeveloper,项目名称:Landsknecht_GreenScreen,代码行数:76,代码来源:AdobePhotoShopColorSwatchSerializer.cs
示例2: Serialize
/// <summary>
/// Serializes the specified <see cref="ColorCollection" /> and writes the palette to a file using the specified <see cref="Stream" />.
/// </summary>
/// <param name="stream">The <see cref="Stream" /> used to write the palette.</param>
/// <param name="palette">The <see cref="ColorCollection" /> to serialize.</param>
public override void Serialize(Stream stream, ColorCollection palette)
{
int swatchIndex;
if (stream == null)
{
throw new ArgumentNullException("stream");
}
if (palette == null)
{
throw new ArgumentNullException("palette");
}
swatchIndex = 0;
// TODO: Allow name and columns attributes to be specified
using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII))
{
writer.WriteLine("GIMP Palette");
writer.WriteLine("Name: ");
writer.WriteLine("Columns: 8");
writer.WriteLine("#");
foreach (Color color in palette)
{
writer.Write("{0,-3} ", color.R);
writer.Write("{0,-3} ", color.G);
writer.Write("{0,-3} ", color.B);
#if USENAMEHACK
writer.Write(palette.GetName(swatchIndex));
#else
if (color.IsNamedColor)
{
writer.Write(color.Name);
}
else
{
writer.Write("#{0:X2}{1:X2}{2:X2} Swatch {3}", color.R, color.G, color.B, swatchIndex);
}
#endif
writer.WriteLine();
swatchIndex++;
}
}
}