Exemple #1
0
        public void ExportFrames(string outputDir, Func <string, string, bool> overwriteCallback)
        {
            try
            {
                if (!Directory.Exists(outputDir))
                {
                    Directory.CreateDirectory(outputDir);
                }

                foreach (var frame in Frames)
                {
                    var outputFileName = Path.Combine(outputDir, $"{frame.Name}.png");

                    // overwrite confirmation
                    if (File.Exists(outputFileName) &&
                        overwriteCallback != null &&
                        overwriteCallback.Invoke(frame.Name, outputFileName) == false)
                    {
                        continue;
                    }

                    var sprite = new CroppedBitmap(Texture, new Int32Rect()
                    {
                        X      = frame.Left,
                        Y      = frame.Top,
                        Width  = frame.Right - frame.Left,
                        Height = frame.Bottom - frame.Top
                    });

                    sprite.Save(outputFileName);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
            }
        }