Example #1
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            bool   outputMade;
            bool   overwrite;
            string fullPath;
            // Get output settings from the configuration
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings();

            if (captureDetails?.Filename != null)
            {
                // As we save a pre-selected file, allow to overwrite.
                overwrite = true;
                Log.InfoFormat("Using previous filename");
                fullPath = captureDetails.Filename;
                outputSettings.Format = ImageOutput.FormatForFilename(fullPath);
            }
            else
            {
                fullPath = CreateNewFilename(captureDetails);
                // As we generate a file, the configuration tells us if we allow to overwrite
                overwrite = CoreConfig.OutputFileAllowOverwrite;
            }
            if (CoreConfig.OutputFilePromptQuality)
            {
                QualityDialog qualityDialog = new QualityDialog(outputSettings);
                qualityDialog.ShowDialog();
            }

            // Catching any exception to prevent that the user can't write in the directory.
            // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642
            try {
                ImageOutput.Save(surface, fullPath, overwrite, outputSettings, CoreConfig.OutputFileCopyPathToClipboard);
                outputMade = true;
            } catch (ArgumentException ex1) {
                // Our generated filename exists, display 'save-as'
                Log.InfoFormat("Not overwriting: {0}", ex1.Message);
                // when we don't allow to overwrite present a new SaveWithDialog
                fullPath   = ImageOutput.SaveWithDialog(surface, captureDetails);
                outputMade = fullPath != null;
            } catch (Exception ex2) {
                Log.Error("Error saving screenshot!", ex2);
                // Show the problem
                MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error));
                // when save failed we present a SaveWithDialog
                fullPath   = ImageOutput.SaveWithDialog(surface, captureDetails);
                outputMade = fullPath != null;
            }
            // Don't overwrite filename if no output is made
            if (outputMade)
            {
                exportInformation.ExportMade = true;
                exportInformation.Filepath   = fullPath;
                if (captureDetails != null)
                {
                    captureDetails.Filename = fullPath;
                }
                CoreConfig.OutputFileAsFullpath = fullPath;
            }

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        /// <summary>
        /// saves img to fullpath
        /// </summary>
        /// <param name="img">the image to save</param>
        /// <param name="fullPath">the absolute destination path including file name</param>
        /// <param name="allowOverwrite">true if overwrite is allowed, false if not</param>
        public static void Save(Image img, string fullPath, bool allowOverwrite)
        {
            int quality;
            bool reduceColors = false;

            // Fix for bug 2912959
            string extension = fullPath.Substring(fullPath.LastIndexOf(".") + 1);
            bool isJPG = false;
            if (extension != null) {
                isJPG = "JPG".Equals(extension.ToUpper()) || "JPEG".Equals(extension.ToUpper());
            }

            if(conf.OutputFilePromptQuality) {
                QualityDialog qualityDialog = new QualityDialog(isJPG);
                qualityDialog.ShowDialog();
                quality = qualityDialog.Quality;
                reduceColors = qualityDialog.ReduceColors;
            } else {
                quality = conf.OutputFileJpegQuality;
                reduceColors = conf.OutputFileReduceColors;
            }
            Save(img, fullPath, allowOverwrite, quality, reduceColors, conf.OutputFileCopyPathToClipboard);
        }