Пример #1
0
        public async static Task <IEnumerable <SpriteFragment> > MakeImage(SpriteDocument document, string imageFile, Func <string, bool, Task> updateSprite)
        {
            ProjectHelpers.CheckOutFileFromSourceControl(imageFile);

            Dictionary <string, Image> images = await WatchFiles(document, updateSprite);

            int width  = document.IsVertical ? images.Values.Max(i => i.Width) + (document.Margin * 2) : images.Values.Sum(i => i.Width) + (document.Margin * images.Count) + document.Margin;
            int height = document.IsVertical ? images.Values.Sum(img => img.Height) + (document.Margin * images.Count) + document.Margin : images.Values.Max(img => img.Height) + (document.Margin * 2);

            List <SpriteFragment> fragments = new List <SpriteFragment>();

            using (var bitmap = new Bitmap(width, height))
            {
                using (Graphics canvas = Graphics.FromImage(bitmap))
                {
                    if (document.IsVertical)
                    {
                        Vertical(images, fragments, canvas, document.Margin);
                    }
                    else
                    {
                        Horizontal(images, fragments, canvas, document.Margin);
                    }
                }

                bitmap.Save(imageFile, PasteImage.GetImageFormat("." + document.FileExtension));
            }

            return(fragments);
        }
Пример #2
0
        public static IEnumerable <SpriteFragment> CreateImage(SpriteDocument sprite, out string imageFile)
        {
            imageFile = Path.ChangeExtension(sprite.FileName, sprite.FileExtension);
            ProjectHelpers.CheckOutFileFromSourceControl(imageFile);

            Dictionary <string, Image> images = GetImages(sprite);

            int width  = sprite.IsVertical ? images.Values.Max(i => i.Width) : images.Values.Sum(i => i.Width);
            int height = sprite.IsVertical ? images.Values.Sum(img => img.Height) : images.Values.Max(img => img.Height);

            List <SpriteFragment> fragments = new List <SpriteFragment>();

            using (var bitmap = new Bitmap(width, height))
            {
                using (Graphics canvas = Graphics.FromImage(bitmap))
                {
                    if (sprite.IsVertical)
                    {
                        Vertical(images, fragments, canvas);
                    }
                    else
                    {
                        Horizontal(images, fragments, canvas);
                    }
                }

                bitmap.Save(imageFile, PasteImage.GetImageFormat("." + sprite.FileExtension));
            }

            return(fragments);
        }