示例#1
0
        public void Test_Set()
        {
            using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        pixels.Set((QuantumType[])null);
                    });

                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        pixels.Set((Pixel)null);
                    });

                    ExceptionAssert.Throws <ArgumentNullException>(delegate()
                    {
                        pixels.Set((Pixel[])null);
                    });

                    Assert.AreEqual(3, pixels.Channels);
                    Test_Set(pixels, new QuantumType[] { });
                    Test_Set(pixels, new QuantumType[] { 0 });
                    Test_Set(pixels, new QuantumType[] { 0, 0 });

                    pixels.Set(new QuantumType[] { 0, 0, 0 });
                    Test_PixelColor(pixels, MagickColors.Black);
                }

                using (PixelCollection pixels = image.GetPixels())
                {
                    Test_PixelColor(pixels, MagickColors.Black);
                }

                using (PixelCollection pixels = image.GetPixels())
                {
                    pixels.Set(new uint[] { 100000, 0, 0 });
                    Test_PixelColor(pixels, MagickColors.Red);
                    pixels.Set(new ushort[] { 0, 0, 65535 });
                    Test_PixelColor(pixels, MagickColors.Blue);
                    pixels.Set(new byte[] { 0, 255, 0 });
                    Test_PixelColor(pixels, MagickColors.Lime);
                }

                using (PixelCollection pixels = image.GetPixels())
                {
                    pixels.SetArea(3, 3, 1, 1, new uint[] { 100000, 0, 0 });
                    Test_PixelColor(pixels, 3, 3, MagickColors.Red);
                    pixels.SetArea(3, 3, 1, 1, new ushort[] { 0, 0, 65535 });
                    Test_PixelColor(pixels, 3, 3, MagickColors.Blue);
                    pixels.SetArea(3, 3, 1, 1, new byte[] { 0, 255, 0 });
                    Test_PixelColor(pixels, 3, 3, MagickColors.Lime);
                }

                using (PixelCollection pixels = image.GetPixels())
                {
                    for (int x = 0; x < image.Width; x++)
                    {
                        for (int y = 0; y < image.Height; y++)
                        {
                            pixels.Set(x, y, new QuantumType[] { 0, 0, 0 });
                        }
                    }
                }
            }
        }