public static string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors) { string pattern = conf.OutputFileFilenamePattern; if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) { pattern = "greenshot ${capturetime}"; } string filename = FilenameHelper.GetFilenameFromPattern(pattern, outputFormat, captureDetails); // Prevent problems with "other characters", which causes a problem in e.g. Outlook 2007 or break our HTML filename = Regex.Replace(filename, @"[^\d\w\.]", "_"); // Remove multiple "_" filename = Regex.Replace(filename, @"_+", "_"); string tmpFile = Path.Combine(Path.GetTempPath(), filename); LOG.Debug("Creating TMP File: " + tmpFile); // 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 try { ImageOutput.Save(image, tmpFile, true, quality, reduceColors, false); tmpFileCache.Add(tmpFile, tmpFile); } catch (Exception e) { // Show the problem MessageBox.Show(e.Message, "Error"); // when save failed we present a SaveWithDialog tmpFile = ImageOutput.SaveWithDialog(image, captureDetails); } return(tmpFile); }
public string GetFilename(OutputFormat format, ICaptureDetails captureDetails) { string pattern = conf.OutputFileFilenamePattern; if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) { pattern = "greenshot ${capturetime}"; } return(FilenameHelper.GetFilenameFromPattern(pattern, format, captureDetails)); }
/// <summary> /// Helper Method for creating an Email with Image Attachment /// </summary> /// <param name="image">The image to send</param> /// <param name="captureDetails">ICaptureDetails</param> public static void SendImage(Image image, ICaptureDetails captureDetails) { string pattern = conf.OutputFileFilenamePattern; if (pattern == null || string.IsNullOrEmpty(pattern.Trim())) { pattern = "greenshot ${capturetime}"; } string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails); // Prevent problems with "other characters", which causes a problem in e.g. Outlook 2007 or break our HTML filename = Regex.Replace(filename, @"[^\d\w\.]", "_"); // Remove multiple "_" filename = Regex.Replace(filename, @"_+", "_"); string tmpFile = Path.Combine(Path.GetTempPath(), filename); LOG.Debug("Creating TMP File for Email: " + tmpFile); // 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 try { ImageOutput.Save(image, tmpFile, true, conf.OutputFileJpegQuality, false); } catch (Exception e) { // Show the problem MessageBox.Show(e.Message, "Error"); // when save failed we present a SaveWithDialog tmpFile = ImageOutput.SaveWithDialog(image, captureDetails); } if (tmpFile != null) { // Store the list of currently active windows, so we can make sure we show the email window later! List <WindowDetails> windowsBefore = WindowDetails.GetVisibleWindows(); bool isEmailSend = false; if (EmailConfigHelper.HasOutlook() && (conf.OutputEMailFormat == EmailFormat.OUTLOOK_HTML || conf.OutputEMailFormat == EmailFormat.OUTLOOK_TXT)) { isEmailSend = OutlookExporter.ExportToOutlook(tmpFile, captureDetails); } if (!isEmailSend && EmailConfigHelper.HasMAPI()) { // Fallback to MAPI // Send the email and Cleanup the tmp files on exit SendImage(tmpFile, captureDetails.Title, true); } WindowDetails.ActiveNewerWindows(windowsBefore); } }