예제 #1
0
        public void PackAndDrawHorizontalImageTest()
        {
            var target = new NonphotoIndexedAssemble_Accessor(new WebGreaseContext(new WebGreaseConfiguration()));
            var log    = new ImageMap_Accessor("ReplaceLog.xml");

            log.AppendPadding("0");
            target.ImageXmlMap = log;
            Bitmap actual = null;
            List <BitmapContainer_Accessor> data = null;

            try
            {
                data = GenerateData(WebGrease.ImageAssemble.ImageType_Accessor.NonphotoIndexed);
                Assert.IsTrue(data.Count > 0);
                actual = target.PackHorizontal(data, true, null);
                int totalWidth = data.Sum(bmp => bmp.Width);
                int maxHeight  = data.Max(bmp => bmp.Height);
                Assert.AreEqual(totalWidth, actual.Width);
                Assert.AreEqual(maxHeight, actual.Height);
            }
            finally
            {
                foreach (var entry in data)
                {
                    entry.Bitmap.Dispose();
                }

                if (actual != null)
                {
                    actual.Dispose();
                }
            }
        }
예제 #2
0
        public void AssembleTest_Photo()
        {
            var target = new PhotoAssemble_Accessor(new WebGreaseContext(new WebGreaseConfiguration()))
            {
                PackingType = SpritePackingType_Accessor.Horizontal, AssembleFileName = "Combine.jpg", PaddingBetweenImages = 5
            };

            try
            {
                var log = new ImageMap_Accessor("ReplaceLog.xml");
                target.ImageXmlMap = log;
                var inputImages = GenerateData(WebGrease.ImageAssemble.ImageType_Accessor.Photo);
                target.Assemble(inputImages);
                log.SaveXmlMap();
                Assert.IsTrue(ValidateImageGenerationFromLog("ReplaceLog.xml"));
                ValidateLogFile(inputImages, target.AssembleFileName, target.PackingType);
            }
            finally
            {
                if (File.Exists(target.AssembleFileName))
                {
                    File.Delete(target.AssembleFileName);
                }
            }
        }
예제 #3
0
        public void ImageMapConstructorTest()
        {
            var target = new ImageMap_Accessor(null as string);

            Assert.IsNull(target.xdoc);
            Assert.IsNull(target.root);
            Assert.IsTrue(string.IsNullOrEmpty(target.mapFileName));
        }
예제 #4
0
        public void OptimizeAndSaveTest_NonphotoIndexed()
        {
            Bitmap originalImage           = null;
            var    nonphotoIndexedAccessor = new NonphotoIndexedAssemble_Accessor(new WebGreaseContext(new WebGreaseConfiguration()));

            try
            {
                var log = new ImageMap_Accessor("ReplaceLog.xml");
                log.AppendPadding("0");
                nonphotoIndexedAccessor.ImageXmlMap      = log;
                nonphotoIndexedAccessor.AssembleFileName = "Combine.png";
                var gifData = GenerateData(ImageType_Accessor.NonphotoIndexed);
                originalImage = nonphotoIndexedAccessor.PackVertical(gifData, true, null);
                nonphotoIndexedAccessor.SaveImage(originalImage);
                Assert.IsTrue(File.Exists(nonphotoIndexedAccessor.AssembleFileName));
            }
            finally
            {
                if (originalImage != null)
                {
                    originalImage.Dispose();
                }
            }
        }
예제 #5
0
        public void OptimizeAndSaveTest_Photo()
        {
            Bitmap originalImage = null;

            try
            {
                var log           = new ImageMap_Accessor("ReplaceLog.xml");
                var photoAccessor = new PhotoAssemble_Accessor(new WebGreaseContext(new WebGreaseConfiguration()))
                {
                    ImageXmlMap = log, AssembleFileName = "Combine.jpg"
                };
                var jpegData = GenerateData(WebGrease.ImageAssemble.ImageType_Accessor.Photo);
                originalImage = photoAccessor.PackVertical(jpegData, true, null);
                photoAccessor.SaveImage(originalImage);
                Assert.IsTrue(File.Exists(photoAccessor.AssembleFileName));
            }
            finally
            {
                if (originalImage != null)
                {
                    originalImage.Dispose();
                }
            }
        }
예제 #6
0
        public void PackAndDrawVerticalImageTest()
        {
            Bitmap actual = null;
            var    log    = new ImageMap_Accessor("ReplaceLog.xml");
            var    target = new NonphotoIndexedAssemble_Accessor(new WebGreaseContext(new WebGreaseConfiguration()))
            {
                AssembleFileName = "combine.png", ImageXmlMap = log
            };
            List <BitmapContainer_Accessor> data = null;

            try
            {
                data = GenerateData(ImageType_Accessor.NonphotoIndexed);
                Assert.IsTrue(data.Count > 0);
                actual = target.PackVertical(data, true, null);
                var maxWidth    = data.Max(bmp => bmp.Width);
                var totalHeight = data.Sum(bmp => bmp.Height);
                Assert.AreEqual(maxWidth, actual.Width);
                Assert.AreEqual(totalHeight, actual.Height);
            }
            finally
            {
                if (data != null)
                {
                    foreach (var entry in data)
                    {
                        entry.Bitmap.Dispose();
                    }
                }

                if (actual != null)
                {
                    actual.Dispose();
                }
            }
        }