Beispiel #1
0
 private void palettesListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (palettesListBox.SelectedIndex != -1)
     {
         colorGrid.Colors = ColorCollection.LoadPalette(Path.Combine(this.PalettePath, palettesListBox.SelectedItem.ToString()));
     }
 }
Beispiel #2
0
        private void ScratchForm_Load(object sender, EventArgs e)
        {
            string          fileName;
            ColorCollection source;
            ColorCollection destination;
            AdobePhotoshopColorSwatchSerializer serializer;

            fileName = Path.GetTempFileName();
            //source = ColorCollection.LoadPalette(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "palettes"), "grayscale.pal"));
            source     = ColorCollection.LoadPalette(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "palettes"), "db32.gpl"));
            serializer = new AdobePhotoshopColorSwatchSerializer();

            using (Stream stream = File.Create(fileName))
            {
                serializer.Serialize(stream, source, AdobePhotoshopColorSwatchColorSpace.Hsb);
                //serializer.Serialize(stream, source, AdobePhotoShopColorSwatchColorSpace.Grayscale);
            }

            destination = ColorCollection.LoadPalette(fileName);

            colorGrid1.Colors = source;
            colorGrid2.Colors = destination;

            File.Delete(fileName);
        }
        public void SerializeGrayscaleTest()
        {
            // arrange
            AdobePhotoshopColorSwatchSerializer target;
            ColorCollection expected;
            ColorCollection actual;
            MemoryStream    write;

            target = new AdobePhotoshopColorSwatchSerializer();

            expected = ColorCollection.LoadPalette(Path.Combine(this.DataPath, "grayscale.pal"));
            write    = new MemoryStream();

            // act
            target.Serialize(write, expected, AdobePhotoshopColorSwatchColorSpace.Grayscale);

            using (MemoryStream read = new MemoryStream(write.ToArray()))
            {
                actual = new AdobePhotoshopColorSwatchSerializer().Deserialize(read);
            }

            // assert
            // TODO: The grayscale color space suffers the same problem as HSB - see that test for more details
            actual.Count.Should().Be(expected.Count);
            for (int i = 0; i < actual.Count; i++)
            {
                Color actualColor;
                Color expectedColor;

                actualColor   = actual[i];
                expectedColor = expected[i];

                ((int)actualColor.R).Should().BeInRange(expectedColor.R - 1, expectedColor.R + 1);
                ((int)actualColor.G).Should().BeInRange(expectedColor.G - 1, expectedColor.G + 1);
                ((int)actualColor.B).Should().BeInRange(expectedColor.B - 1, expectedColor.B + 1);
            }
        }