Example #1
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);
                }
            }
        }
Example #2
0
        public void Test_IndexOutOfRange()
        {
            using (MagickImage image = new MagickImage(MagickColors.Red, 5, 10))
            {
                using (PixelCollection pixels = image.GetPixels())
                {
                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(4, 0, 2, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(new MagickGeometry(0, 9, 1, 2));
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(-1, 0, 1, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(0, -1, 1, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(0, 0, -1, 1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetArea(0, 0, 1, -1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetValue(5, 0);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetValue(-1, 0);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetValue(0, -1);
                    });

                    ExceptionAssert.Throws <ArgumentOutOfRangeException>(delegate()
                    {
                        pixels.GetValue(0, 10);
                    });
                }
            }
        }