• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ColorCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ColorCollection的典型用法代码示例。如果您正苦于以下问题:C# ColorCollection类的具体用法?C# ColorCollection怎么用?C# ColorCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ColorCollection类属于命名空间,在下文中一共展示了ColorCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Deserialize

        /// <summary>
        /// Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized.</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

              if (stream == null)
              {
            throw new ArgumentNullException("stream");
              }

              results = new ColorCollection();

              for (int i = 0; i < stream.Length / 3; i++)
              {
            int r;
            int g;
            int b;

            r = stream.ReadByte();
            g = stream.ReadByte();
            b = stream.ReadByte();

            results.Add(Color.FromArgb(r, g, b));
              }

              return results;
        }
开发者ID:MEXXIO,项目名称:Arduino-LED-Controller,代码行数:31,代码来源:RawPaletteSerializer.cs


示例2: Deserialize

        /// <summary>
        ///     Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized..</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

            if (stream == null)
                throw new ArgumentNullException("stream");

            results = new ColorCollection();

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    string line;

                    line = reader.ReadLine();
                    if (!string.IsNullOrEmpty(line) && !line.StartsWith(";") && line.Length == 8)
                    {
                        int a;
                        int r;
                        int g;
                        int b;

                        a = int.Parse(line.Substring(0, 2), NumberStyles.HexNumber);
                        r = int.Parse(line.Substring(2, 2), NumberStyles.HexNumber);
                        g = int.Parse(line.Substring(4, 2), NumberStyles.HexNumber);
                        b = int.Parse(line.Substring(6, 2), NumberStyles.HexNumber);

                        results.Add(Color.FromArgb(a, r, g, b));
                    }
                }
            }

            return results;
        }
开发者ID:samarjeet27,项目名称:ynotesamples,代码行数:40,代码来源:PaintNetPaletteSerializer.cs


示例3: CreateDawnBringer16Palette

    /// <summary>
    /// Creates the DB16 palette.
    /// </summary>
    /// <remarks>http://www.pixeljoint.com/forum/forum_posts.asp?TID=12795</remarks>
    /// <param name="pad">if set to <c>true</c> the palette is padded with black to fill 256 entries.</param>
    protected ColorCollection CreateDawnBringer16Palette(bool pad)
    {
      ColorCollection results;

      results = new ColorCollection();

      results.Add(Color.FromArgb(20, 12, 28));
      results.Add(Color.FromArgb(68, 36, 52));
      results.Add(Color.FromArgb(48, 52, 109));
      results.Add(Color.FromArgb(78, 74, 78));
      results.Add(Color.FromArgb(133, 76, 48));
      results.Add(Color.FromArgb(52, 101, 36));
      results.Add(Color.FromArgb(208, 70, 72));
      results.Add(Color.FromArgb(117, 113, 97));
      results.Add(Color.FromArgb(89, 125, 206));
      results.Add(Color.FromArgb(210, 125, 44));
      results.Add(Color.FromArgb(133, 149, 161));
      results.Add(Color.FromArgb(109, 170, 44));
      results.Add(Color.FromArgb(210, 170, 153));
      results.Add(Color.FromArgb(109, 194, 202));
      results.Add(Color.FromArgb(218, 212, 94));
      results.Add(Color.FromArgb(222, 238, 214));

      if (pad)
      {
        while (results.Count < 256)
        {
          results.Add(Color.FromArgb(0, 0, 0));
        }
      }

      return results;
    }
开发者ID:nabeshin,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:38,代码来源:TestBase.cs


示例4: HueColorSlider

 public HueColorSlider()
 {
     BarStyle = ColorBarStyle.Custom;
     Maximum = 359;
     CustomColors =
         new ColorCollection(Enumerable.Range(0, 359).Select(h => new HslColor(h, 1, 0.5).ToRgbColor()));
 }
开发者ID:samarjeet27,项目名称:ynotesamples,代码行数:7,代码来源:HueColorSlider.cs


示例5: ColorGrid

 protected ColorGrid(ColorCollection colors, ColorCollection customColors, ColorPalette palette)
 {
     _cellBackground = Resources.cellbackground;
     _cellBackgroundBrush = new TextureBrush(_cellBackground, WrapMode.Tile);
     SetStyle(
         ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer |
         ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick |
         ControlStyles.SupportsTransparentBackColor, true);
     HotIndex = InvalidIndex;
     ColorRegions = new Dictionary<int, Rectangle>();
     if (Palette != ColorPalette.None)
         Colors = colors;
     else
         Palette = palette;
     CustomColors = customColors;
     ShowCustomColors = true;
     CellSize = new Size(12, 12);
     Spacing = new Size(3, 3);
     Columns = 16;
     AutoSize = true;
     Padding = new Padding(5);
     AutoAddColors = true;
     CellBorderColor = SystemColors.ButtonShadow;
     ShowToolTips = true;
     SeparatorHeight = 8;
     EditMode = ColorEditingMode.CustomOnly;
     Color = Color.Black;
     CellBorderStyle = ColorCellBorderStyle.FixedSingle;
     SelectedCellStyle = ColorGridSelectedCellStyle.Zoomed;
 }
开发者ID:samarjeet27,项目名称:ynotesamples,代码行数:30,代码来源:ColorGrid.cs


示例6: 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)
    {
      if (stream == null)
        throw new ArgumentNullException("stream");

      if (palette == null)
        throw new ArgumentNullException("palette");

      // TODO: Allow name and columns attributes to be specified

      using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
      {
        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 (color.IsNamedColor)
            writer.Write(color.Name);
          else
            writer.Write("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
          writer.WriteLine();
        }
      }
    }
开发者ID:koponk,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:34,代码来源:GimpPaletteSerializer.cs


示例7: Deserialize

        /// <summary>
        ///     Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized..</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

            if (stream == null)
                throw new ArgumentNullException("stream");

            results = new ColorCollection();

            using (var reader = new StreamReader(stream))
            {
                string header;
                string startHeader;

                // check signature
                header = reader.ReadLine();
                startHeader = reader.ReadLine();

                if (header != "GIMP Palette")
                    throw new InvalidDataException("Invalid palette file");

                while (startHeader != "#")
                    startHeader = reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    int r;
                    int g;
                    int b;
                    string data;
                    string[] parts;

                    data = reader.ReadLine();
                    parts = !string.IsNullOrEmpty(data)
                        ? data.Split(new[]
                        {
                            ' ', '\t'
                        }, StringSplitOptions.RemoveEmptyEntries)
                        : new string[0];

                    if (!int.TryParse(parts[0], out r) || !int.TryParse(parts[1], out g) ||
                        !int.TryParse(parts[2], out b))
                        throw new InvalidDataException(string.Format("Invalid palette contents found with data '{0}'",
                            data));

                    results.Add(Color.FromArgb(r, g, b));
                }
            }

            return results;
        }
开发者ID:samarjeet27,项目名称:ynotesamples,代码行数:56,代码来源:GimpPaletteSerializer.cs


示例8: Deserialize

        /// <summary>
        ///     Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized..</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

            if (stream == null)
                throw new ArgumentNullException("stream");

            results = new ColorCollection();

            using (var reader = new StreamReader(stream))
            {
                string header;
                string version;
                int colorCount;

                // check signature
                header = reader.ReadLine();
                version = reader.ReadLine();

                if (header != "JASC-PAL" || version != "0100")
                    throw new InvalidDataException("Invalid palette file");

                colorCount = Convert.ToInt32(reader.ReadLine());
                for (int i = 0; i < colorCount; i++)
                {
                    int r;
                    int g;
                    int b;
                    string data;
                    string[] parts;

                    data = reader.ReadLine();
                    parts = !string.IsNullOrEmpty(data)
                        ? data.Split(new[]
                        {
                            ' ', '\t'
                        }, StringSplitOptions.RemoveEmptyEntries)
                        : new string[0];

                    if (!int.TryParse(parts[0], out r) || !int.TryParse(parts[1], out g) ||
                        !int.TryParse(parts[2], out b))
                        throw new InvalidDataException(string.Format("Invalid palette contents found with data '{0}'",
                            data));

                    results.Add(Color.FromArgb(r, g, b));
                }
            }

            return results;
        }
开发者ID:samarjeet27,项目名称:ynotesamples,代码行数:55,代码来源:JascPaletteSerializer.cs


示例9: EqualsNullTest

    public void EqualsNullTest()
    {
      // arrange
      ColorCollection target;
      bool actual;

      target = new ColorCollection();

      // act
      actual = target.Equals(null);

      // assert
      actual.Should().BeFalse();
    }
开发者ID:nabeshin,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:14,代码来源:ColorCollectionTests.cs


示例10: CreateDawnBringer32Palette

    /// <summary>
    /// Creates the DB32 palette.
    /// </summary>
    /// <remarks>http://www.pixeljoint.com/forum/forum_posts.asp?TID=16247</remarks>
    /// <param name="pad">if set to <c>true</c> the palette is padded with black to fill 256 entries.</param>
    protected ColorCollection CreateDawnBringer32Palette(bool pad)
    {
      ColorCollection results;

      results = new ColorCollection();

      results.Add(Color.FromArgb(0, 0, 0));
      results.Add(Color.FromArgb(34, 32, 52));
      results.Add(Color.FromArgb(69, 40, 60));
      results.Add(Color.FromArgb(102, 57, 49));
      results.Add(Color.FromArgb(143, 86, 59));
      results.Add(Color.FromArgb(223, 113, 38));
      results.Add(Color.FromArgb(217, 160, 102));
      results.Add(Color.FromArgb(238, 195, 154));
      results.Add(Color.FromArgb(251, 242, 54));
      results.Add(Color.FromArgb(153, 229, 80));
      results.Add(Color.FromArgb(106, 190, 48));
      results.Add(Color.FromArgb(55, 148, 110));
      results.Add(Color.FromArgb(75, 105, 47));
      results.Add(Color.FromArgb(82, 75, 36));
      results.Add(Color.FromArgb(50, 60, 57));
      results.Add(Color.FromArgb(63, 63, 116));
      results.Add(Color.FromArgb(48, 96, 130));
      results.Add(Color.FromArgb(91, 110, 225));
      results.Add(Color.FromArgb(99, 155, 255));
      results.Add(Color.FromArgb(95, 205, 228));
      results.Add(Color.FromArgb(203, 219, 252));
      results.Add(Color.FromArgb(255, 255, 255));
      results.Add(Color.FromArgb(155, 173, 183));
      results.Add(Color.FromArgb(132, 126, 135));
      results.Add(Color.FromArgb(105, 106, 106));
      results.Add(Color.FromArgb(89, 86, 82));
      results.Add(Color.FromArgb(118, 66, 138));
      results.Add(Color.FromArgb(172, 50, 50));
      results.Add(Color.FromArgb(217, 87, 99));
      results.Add(Color.FromArgb(215, 123, 186));
      results.Add(Color.FromArgb(143, 151, 74));
      results.Add(Color.FromArgb(138, 111, 48));

      if (pad)
      {
        while (results.Count < 256)
        {
          results.Add(Color.FromArgb(0, 0, 0));
        }
      }

      return results;
    }
开发者ID:nabeshin,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:54,代码来源:TestBase.cs


示例11: 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)
    {
      if (stream == null)
        throw new ArgumentNullException("stream");

      if (palette == null)
        throw new ArgumentNullException("palette");

      using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
      {
        writer.WriteLine("JASC-PAL");
        writer.WriteLine("0100");
        writer.WriteLine(palette.Count);
        foreach (Color color in palette)
        {
          writer.Write("{0} ", color.R);
          writer.Write("{0} ", color.G);
          writer.Write("{0} ", color.B);
          writer.WriteLine();
        }
      }
    }
开发者ID:koponk,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:27,代码来源:JascPaletteSerializer.cs


示例12: 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)
    {
      if (stream == null)
        throw new ArgumentNullException("stream");

      if (palette == null)
        throw new ArgumentNullException("palette");

      // TODO: Not writing 96 colors, but the entire contents of the palette, wether that's less than 96 or more

      using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
      {
        writer.WriteLine(@"; Paint.NET Palette File
; Lines that start with a semicolon are comments
; Colors are written as 8-digit hexadecimal numbers: aarrggbb
; For example, this would specify green: FF00FF00
; The alpha ('aa') value specifies how transparent a color is. FF is fully opaque, 00 is fully transparent.
; A palette must consist of ninety six (96) colors. If there are less than this, the remaining color
; slots will be set to white (FFFFFFFF). If there are more, then the remaining colors will be ignored.");
        foreach (Color color in palette)
          writer.WriteLine("{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B);
      }
    }
开发者ID:koponk,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:28,代码来源:PaintNetPaletteSerializer.cs


示例13: Serialize

    public void Serialize(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatchFileVersion version, AdobePhotoshopColorSwatchColorSpace colorSpace)
    {
      if (stream == null)
      {
        throw new ArgumentNullException(nameof(stream));
      }

      if (palette == null)
      {
        throw new ArgumentNullException(nameof(palette));
      }

      if (version == AdobePhotoshopColorSwatchFileVersion.Version2)
      {
        this.WritePalette(stream, palette, AdobePhotoshopColorSwatchFileVersion.Version1, colorSpace);
      }
      this.WritePalette(stream, palette, version, colorSpace);
    }
开发者ID:FrankGITDeveloper,项目名称:Landsknecht_GreenScreen,代码行数:18,代码来源:AdobePhotoShopColorSwatchSerializer.cs


示例14: ApplyColorCollection

        private void ApplyColorCollection(ColorCollection Collection, bool RandomOrder)
        {
            if (!Collection.Color.Any())
                return;

            bool strayElement = false;
            Color thisColor, thisColor2 = Color.White;
            int iPos = 0;

            foreach (Element elem in TimelineControl.SelectedElements)
            {
                string effectName = elem.EffectNode.Effect.EffectName;
                object[] parms = new object[elem.EffectNode.Effect.ParameterValues.Count()];
                List<Color> validColors = new List<Color>();

                Array.Copy(elem.EffectNode.Effect.ParameterValues, parms, parms.Count());
                validColors.AddRange(elem.EffectNode.Effect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

                if (RandomOrder)
                {
                    int r1 = rnd.Next(Collection.Color.Count());
                    int r2 = rnd.Next(Collection.Color.Count());

                    int n = 0;
                    while (r1 == r2 && n <= 5)
                    {
                        r2 = rnd.Next(Collection.Color.Count());
                        n++;
                    }

                    thisColor = Collection.Color[r1];
                    thisColor2 = Collection.Color[r2];
                }
                else
                {
                    if (iPos == Collection.Color.Count()) { iPos = 0; }
                    thisColor = Collection.Color[iPos];
                    iPos++;
                    if (effectName == "Alternating")
                    {
                        thisColor2 = Collection.Color[iPos];
                        iPos++;
                    }
                }

                if (validColors.Any() && !validColors.Contains(thisColor)) { thisColor = validColors[rnd.Next(validColors.Count())]; }

                if (effectName == "Alternate")
                {
                    if (validColors.Any() && !validColors.Contains(thisColor2)) { thisColor2 = validColors[rnd.Next(validColors.Count())]; }

                    int n2 = 0;
                    while (thisColor2 == thisColor && n2 <= 5)
                    {
                        thisColor2 = validColors[rnd.Next(validColors.Count())];
                        n2++;
                    }
                }

                switch (effectName)
                {
                    case "Candle Flicker":
                    case "LipSync":
                    case "Nutcracker":
                    case "Launcher":
                    case "RDS":
                        strayElement = true;
                        break;
                    case "Custom Value":
                        //Disabled until we fix the custom value null reference errors - not related to this.
                        //parms[0] = 4; //Set it to a type of color value
                        //parms[5] = thisColor;
                        strayElement = true;
                        break;
                    case "Alternating":
                        parms[1] = thisColor;
                        parms[3] = thisColor2;
                        parms[8] = parms[9] = true;
                        break;
                    case "Set Level":
                        parms[1] = thisColor;
                        break;
                    case "Pulse":
                        parms[1] = new ColorGradient(thisColor);
                        break;
                    case "Chase":
                        parms[0] = 0; // StaticColor
                        parms[3] = thisColor;
                        break;
                    case "Spin":
                        parms[2] = 0; // StaticColor
                        parms[9] = thisColor;
                        break;
                    case "Twinkle":
                        parms[7] = 0; // StaticColor
                        parms[8] = thisColor;
                        break;
                    case "Wipe":
                        parms[0] = new ColorGradient(thisColor);
                        break;
//.........这里部分代码省略.........
开发者ID:komby,项目名称:vixen,代码行数:101,代码来源:TimedSequenceEditorForm.cs


示例15: PopulateCollectionColors

        private void PopulateCollectionColors(ColorCollection collection)
        {
            listViewColors.BeginUpdate();
            listViewColors.Items.Clear();

            listViewColors.LargeImageList = new ImageList();
            listViewColors.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            listViewColors.LargeImageList.ImageSize = new Size(48, 48);

            foreach (Color colorItem in collection.Color)
            {
                Bitmap result = new Bitmap(48,48);
                Graphics gfx = Graphics.FromImage(result);
                using (SolidBrush brush = new SolidBrush(colorItem))
                {
                    gfx.FillRectangle(brush, 0, 0, 48, 48);
                    gfx.DrawRectangle(_borderPen, 0, 0, 48, 48);
                }

                listViewColors.LargeImageList.Images.Add(colorItem.ToString(), result);

                ListViewItem item = new ListViewItem
                {
                    ToolTipText = string.Format("R: {0} G: {1} B: {2}", colorItem.R, colorItem.G, colorItem.B),
                    ImageKey = colorItem.ToString(),
                    Tag = colorItem
                };

                listViewColors.Items.Add(item);
            }
            listViewColors.EndUpdate();
            buttonAddColor.Enabled = true;
        }
开发者ID:jaredb7,项目名称:vixen,代码行数:33,代码来源:ColorCollectionLibrary_Form.cs


示例16: ScaledPalette

    public static ColorCollection ScaledPalette(IEnumerable<Color> topRow)
    {
      ColorCollection results;

      results = new ColorCollection();

      topRow = topRow.ToArray();
      results.AddRange(topRow);

      for (int i = 5; i >= 0; i--)
      {
        foreach (Color color in topRow)
        {
          HslColor hsl;

          hsl = new HslColor(color);
          hsl.L = (5 + i + (16 * i)) / 100D;

          results.Add(hsl.ToRgbColor());
        }
      }

      return results;
    }
开发者ID:koponk,项目名称:Cyotek.Windows.Forms.ColorPicker,代码行数:24,代码来源:ColorPalettes.cs


示例17: DefineColorRegions

        protected void DefineColorRegions(ColorCollection colors, int rangeStart, int offset)
        {
            if (colors != null)
              {
            int rows;
            int index;

            rows = this.GetRows(colors.Count);
            index = 0;

            for (int row = 0; row < rows; row++)
            {
              for (int column = 0; column < this.ActualColumns; column++)
              {
            if (index < colors.Count)
            {
              this.ColorRegions.Add(rangeStart + index, new Rectangle(this.Padding.Left + (column * (this.CellSize.Width + this.Spacing.Width)), offset + (row * (this.CellSize.Height + this.Spacing.Height)), this.CellSize.Width, this.CellSize.Height));
            }

            index++;
              }
            }
              }
        }
开发者ID:psistorma,项目名称:PrivateSublimeSettings,代码行数:24,代码来源:ColorGrid.cs


示例18: ColorGrid

 public ColorGrid(ColorCollection colors)
     : this(colors, new ColorCollection(Enumerable.Repeat(Color.White, 16)))
 {
 }
开发者ID:psistorma,项目名称:PrivateSublimeSettings,代码行数:4,代码来源:ColorGrid.cs


示例19: ReadPalette

    protected virtual ColorCollection ReadPalette(Stream stream, AdobePhotoshopColorSwatchFileVersion version)
    {
      int colorCount;
      ColorCollection results;

      results = new ColorCollection();

      // read the number of colors, which also occupies two bytes
      colorCount = this.ReadInt16(stream);

      for (int i = 0; i < colorCount; i++)
      {
        AdobePhotoshopColorSwatchColorSpace colorSpace;
        int value1;
        int value2;
        int value3;
        string name;

        // again, two bytes for the color space
        colorSpace = (AdobePhotoshopColorSwatchColorSpace)(this.ReadInt16(stream));

        value1 = this.ReadInt16(stream);
        value2 = this.ReadInt16(stream);
        value3 = this.ReadInt16(stream);
        this.ReadInt16(stream); // only CMYK supports this field. As we can't handle CMYK colors, we read the value to advance the stream but don't do anything with it

        if (version == AdobePhotoshopColorSwatchFileVersion.Version2)
        {
          int length;

          // need to read the name even though currently our colour collection doesn't support names
          length = ReadInt32(stream);
          name = this.ReadString(stream, length);
        }
        else
        {
          name = string.Empty;
        }

        switch (colorSpace)
        {
          case AdobePhotoshopColorSwatchColorSpace.Rgb:
            int red;
            int green;
            int blue;

            // RGB.
            // The first three values in the color data are red , green , and blue . They are full unsigned
            //  16-bit values as in Apple's RGBColor data structure. Pure red = 65535, 0, 0.

            red = value1 / 256;
            green = value2 / 256;
            blue = value3 / 256;

            results.Add(Color.FromArgb(red, green, blue));
            break;

          case AdobePhotoshopColorSwatchColorSpace.Hsb:
            double hue;
            double saturation;
            double brightness;

            // HSB.
            // The first three values in the color data are hue , saturation , and brightness . They are full 
            // unsigned 16-bit values as in Apple's HSVColor data structure. Pure red = 0,65535, 65535.

            hue = value1 / 182.04;
            saturation = value2 / 655.35;
            brightness = value3 / 655.35;

            results.Add(new HslColor(hue, saturation, brightness).ToRgbColor());
            break;

          case AdobePhotoshopColorSwatchColorSpace.Grayscale:

            int gray;

            // Grayscale.
            // The first value in the color data is the gray value, from 0...10000.
            gray = (int)(value1 / 39.0625);

            results.Add(Color.FromArgb(gray, gray, gray));
            break;

          default:
            throw new InvalidDataException(string.Format("Color space '{0}' not supported.", colorSpace));
        }

#if USENAMEHACK
        results.SetName(i, name);
#endif
      }

      return results;
    }
开发者ID:FrankGITDeveloper,项目名称:Landsknecht_GreenScreen,代码行数:95,代码来源:AdobePhotoShopColorSwatchSerializer.cs


示例20: 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



注:本文中的ColorCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ColorFormat类代码示例发布时间:2022-05-24
下一篇:
C# ColorBgra类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap