Exemple #1
0
 private static void Test_Set(PixelCollection pixels, QuantumType[] value)
 {
     ExceptionAssert.Throws <ArgumentException>(delegate()
     {
         pixels.Set(value);
     });
 }
Exemple #2
0
        public void Test_GetArea()
        {
            using (MagickImage image = new MagickImage(MagickColors.Fuchsia, 10, 10))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    pixels.Set(3, 3, new QuantumType[] { 0, 0, 0 });

                    var valuesA = pixels.GetArea(2, 2, 4, 4);
                    Assert.AreEqual(48, valuesA.Length);

                    var pixelB = pixels.GetArea(new MagickGeometry(3, 3, 1, 1));
                    Assert.AreEqual(3, pixelB.Length);

                    var pixelA = valuesA.Skip(15).Take(3).ToArray();

                    CollectionAssert.AreEqual(pixelA, pixelB);
                }
            }
        }
Exemple #3
0
        public void Test_SetResult()
        {
            using (MagickImage image = new MagickImage(MagickColors.Red, 10, 2))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    QuantumType[] newPixels = new QuantumType[20 * pixels.Channels];
                    for (int i = 0; i < newPixels.Length; i++)
                    {
                        newPixels[i] = Quantum.Max;
                    }

                    pixels.Set(newPixels);
                }

                TestPixels(image, new MagickColor(Quantum.Max, Quantum.Max, Quantum.Max));
            }

            using (MagickImage image = new MagickImage(MagickColors.Black, 10, 2))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    Assert.AreEqual(20, pixels.Count());

                    foreach (Pixel pixel in pixels.Take(10))
                    {
                        pixel.SetChannel(2, Quantum.Max);
                    }

                    foreach (Pixel pixel in pixels.Skip(10))
                    {
                        pixel.SetChannel(0, Quantum.Max);
                    }
                }

                TestPixels(image, MagickColors.Blue, MagickColors.Red);
            }
        }
Exemple #4
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 });
                        }
                    }
                }
            }
        }