當前位置: 首頁>>代碼示例>>C#>>正文


C# ColorCollection.GetName方法代碼示例

本文整理匯總了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++;
        }
      }
    }
開發者ID:leebivip,項目名稱:ColorHighlighter,代碼行數:53,代碼來源:GimpPaletteSerializer.cs


注:本文中的ColorCollection.GetName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。