Пример #1
0
        /// <summary>
        /// If there is an expected error, the Error property of the results is set to a DFOToolboxException with a message
        /// suitable for display.
        /// </summary>
        /// <param name="imgPath"></param>
        /// <param name="frameIndex"></param>
        /// <returns></returns>
        public QuickSaveResults QuickSaveAsPng(string imgPath, int frameIndex)
        {
            if (imgPath == null)
            {
                throw new ArgumentNullException("imgPath");
            }

            QuickSaveResults results = new QuickSaveResults();

            string filename = "{0}.{1}.png".F(SanitizeImgPathForFilename(imgPath), frameIndex);
            string path     = Path.Combine(_quicksaveFolderPath, filename);

            results.OutputFolder = _quicksaveFolderPath;
            results.OutputPath   = path;

            // Save to (folder)/(sanitized img path).(frame number).png
            if (!Directory.Exists(_quicksaveFolderPath))
            {
                try
                {
                    Directory.CreateDirectory(_quicksaveFolderPath);
                }
                catch (Exception ex)
                {
                    results.Error = new DFOToolboxException("Could not create quicksave directory {0}".F(_quicksaveFolderPath), ex);
                    return(results);
                }
            }

            try
            {
                using (FileStream pngOutput = File.Open(path, FileMode.Create))
                {
                    Export.ToPng(_editor, imgPath, frameIndex, pngOutput);
                }
            }
            catch (Exception ex)
            {
                results.Error = new DFOToolboxException("Error saving to {0}".F(path), ex);
                return(results);
            }

            return(results);
        }
Пример #2
0
        /// <summary>
        /// If there is an expected error, the Error property of the results is set to a DFOToolboxException with a message
        /// suitable for display.
        /// </summary>
        /// <param name="imgPath"></param>
        /// <param name="frameIndex"></param>
        /// <returns></returns>
        public QuickSaveResults QuickSaveAsPng(string imgPath, int frameIndex)
        {
            if (imgPath == null) throw new ArgumentNullException("imgPath");

            QuickSaveResults results = new QuickSaveResults();

            string filename = "{0}.{1}.png".F(SanitizeImgPathForFilename(imgPath), frameIndex);
            string path = Path.Combine(_quicksaveFolderPath, filename);
            results.OutputFolder = _quicksaveFolderPath;
            results.OutputPath = path;

            // Save to (folder)/(sanitized img path).(frame number).png
            if (!Directory.Exists(_quicksaveFolderPath))
            {
                try
                {
                    Directory.CreateDirectory(_quicksaveFolderPath);
                }
                catch (Exception ex)
                {
                    results.Error = new DFOToolboxException("Could not create quicksave directory {0}".F(_quicksaveFolderPath), ex);
                    return results;
                }
            }

            try
            {
                using (FileStream pngOutput = File.Open(path, FileMode.Create))
                {
                    Export.ToPng(_npk, imgPath, frameIndex, pngOutput);
                }
            }
            catch (Exception ex)
            {
                results.Error = new DFOToolboxException("Error saving to {0}".F(path), ex);
                return results;
            }

            return results;
        }