Example #1
0
        public void Slice_Typical()
        {
            var tiles = new[]
            {
                new Pair <Rectangle, string>(DeepZoomImage.CreateRectangle(new Point(0, 0), new Point(254, 254)), "0_0"),
                new Pair <Rectangle, string>(DeepZoomImage.CreateRectangle(new Point(0, 253), new Point(254, 374)), "0_1"),

                new Pair <Rectangle, string>(DeepZoomImage.CreateRectangle(new Point(253, 0), new Point(299, 254)), "1_0"),
                new Pair <Rectangle, string>(DeepZoomImage.CreateRectangle(new Point(253, 253), new Point(299, 374)), "1_1"),
            };
            var streams = new Dictionary <string, MemoryStream>
            {
                { "0_0", new MemoryStream() },
                { "0_1", new MemoryStream() },
                { "1_0", new MemoryStream() },
                { "1_1", new MemoryStream() },
            };
            var settings = new Settings {
                PostImageEncoding = ImageFormat.Png,
            };
            var dzi = new DeepZoomImage(settings);

            try
            {
                using (var inputStream = AssemblyExtensions.OpenScopedResourceStream <DeepZoomImageTest> ("300x375.png"))
                    using (var sourceBitmap = new Bitmap(inputStream))
                    {
                        dzi.Slice(sourceBitmap, tiles, tilename => streams[tilename]);
                    }

                foreach (var keyValuePair in streams)
                {
                    var expectedResourceFileName = keyValuePair.Key + ".png";
                    var actualStream             = keyValuePair.Value;
                    ProgramTest.AssertStreamsAreEqual <DeepZoomImageTest> (expectedResourceFileName, actualStream);
                }
            }
            finally
            {
                foreach (var stream in streams.Values)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
        }
Example #2
0
        public void Slice_SquareLogo()
        {
            Assert.AreEqual(10, DeepZoomImage.DetermineMaximumLevel(SquareLogoSize));
            using (var sourceBitmap = new Bitmap(SquareLogoSize.Width, SquareLogoSize.Height))
            {
                var tester = new Action <int, IEnumerable <Size> > ((level, expectedSliceSizes) =>
                {
                    var levelSize        = DeepZoomImage.ComputeLevelSize(SquareLogoSize, level);
                    var tiles            = DeepZoomImage.ComputeTiles(levelSize, 254, 1);
                    var slices           = DeepZoomImage.Slice(sourceBitmap, tiles);
                    var actualSliceSizes = slices.Map(pair => pair.First.Size);
                    EnumerableExtensions.EnumerateSame(expectedSliceSizes, actualSliceSizes);
                }
                                                                    );

                tester(10, new[]
                {
                    new Size(255, 255), new Size(255, 256), new Size(255, 193),
                    new Size(256, 255), new Size(256, 256), new Size(256, 193),
                    new Size(193, 255), new Size(193, 256), new Size(193, 193),
                }
                       );
                tester(9, new[]
                {
                    new Size(255, 255), new Size(255, 97),
                    new Size(97, 255), new Size(97, 97),
                }
                       );
                tester(8, new[] { new Size(175, 175) });
                tester(7, new[] { new Size(88, 88) });
                tester(6, new[] { new Size(44, 44) });
                tester(5, new[] { new Size(22, 22) });
                tester(4, new[] { new Size(11, 11) });
                tester(3, new[] { new Size(6, 6) });
                tester(2, new[] { new Size(3, 3) });
                tester(1, new[] { new Size(2, 2) });
                tester(0, new[] { new Size(1, 1) });
            }
        }
        public void Slice_Typical ()
        {
            var tiles = new[]
            {
                new Pair<Rectangle, string>(DeepZoomImage.CreateRectangle (new Point(  0,   0), new Point(254, 254)), "0_0"),
                new Pair<Rectangle, string>(DeepZoomImage.CreateRectangle (new Point(  0, 253), new Point(254, 374)), "0_1"),

                new Pair<Rectangle, string>(DeepZoomImage.CreateRectangle (new Point(253,   0), new Point(299, 254)), "1_0"),
                new Pair<Rectangle, string>(DeepZoomImage.CreateRectangle (new Point(253, 253), new Point(299, 374)), "1_1"),
            };
            var streams = new Dictionary<string, MemoryStream>
            {
                {"0_0", new MemoryStream()},
                {"0_1", new MemoryStream()},
                {"1_0", new MemoryStream()},
                {"1_1", new MemoryStream()},
            };
            var settings = new Settings { PostImageEncoding = ImageFormat.Png, };
            var dzi = new DeepZoomImage (settings);

            try
            {
                using (var inputStream = AssemblyExtensions.OpenScopedResourceStream<DeepZoomImageTest> ("300x375.png"))
                using (var sourceBitmap = new Bitmap (inputStream))
                {
                    dzi.Slice (sourceBitmap, tiles, tilename => streams[tilename]);
                }

                foreach (var keyValuePair in streams)
                {
                    var expectedResourceFileName = keyValuePair.Key + ".png";
                    var actualStream = keyValuePair.Value;
                    ProgramTest.AssertStreamsAreEqual<DeepZoomImageTest> (expectedResourceFileName, actualStream);
                }

            }
            finally
            {
                foreach (var stream in streams.Values)
                {
                    stream.Close ();
                    stream.Dispose ();
                }
            }
        }