Example #1
0
        private Sprite CreateFromStrip(CookingContext context, string path)
        {
            var    name        = Path.GetFileNameWithoutExtension(path);
            var    directory   = Path.GetDirectoryName(path);
            var    bitmapPath1 = Path.Combine(directory, string.Format("{0}.png", name));
            var    bitmapPath2 = Path.Combine(directory, string.Format("{0}.bmp", name));
            var    bitmapPath3 = Path.Combine(directory, string.Format("{0}.jpg", name));
            Bitmap bitmap      = BitmapExtension.CreateOne(bitmapPath1, bitmapPath2, bitmapPath3);

            if (bitmap == null)
            {
                return(null);
            }

            context.AddDependency(bitmapPath1);
            context.AddDependency(bitmapPath2);
            context.AddDependency(bitmapPath3);

            var data   = JsonSerializer.DeserializeDataFromFile(path) as Dictionary <string, object>;
            var frames = data.Get("frames", 0);
            var size   = data.Get("size", Size.Empty);
            var sprite = CreateSprite(EnumerateStrip(bitmap, frames, size), data);

            bitmap.Dispose();

            return(sprite);
        }
Example #2
0
        public override ImageSet Cook(CookingContext context)
        {
            string actualPath = Path.Combine(context.BaseDirectory, context.Directory, context.ExpandVariables(Input));

            Dictionary <string, Image> items = new Dictionary <string, Image>();

            foreach (var item in Directory.GetFiles(actualPath))
            {
                string name   = Path.GetFileNameWithoutExtension(item);
                Bitmap bitmap = BitmapExtension.CreateOne(item);
                if (bitmap == null)
                {
                    continue;
                }

                if (UniformSize.IsEmpty == false)
                {
                    bitmap = bitmap.ResizeAndDispose(UniformSize.Width, UniformSize.Height);
                }

                items.Add(name, new Image(string.Empty, Rectangle.Empty)
                {
                    Tag = new ImageCookingTag(bitmap)
                });
            }

            return(new ImageSet(items));
        }
Example #3
0
        private IEnumerable <Bitmap> EnumerateCels(string directory)
        {
            var q = Directory.EnumerateFiles(directory, "*.*", SearchOption.TopDirectoryOnly);

            foreach (var item in q.OrderBy(x => x))
            {
                var bitmap = BitmapExtension.CreateOne(item);
                if (bitmap != null)
                {
                    yield return(bitmap);
                }
            }
        }