Пример #1
0
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            PrinterSettings printerSettings = null;

            using (Image image = surface.GetImageForExport()) {
                if (!string.IsNullOrEmpty(printerName))
                {
                    printerSettings = new PrintHelper(image, captureDetails).PrintTo(printerName);
                }
                else if (!manuallyInitiated)
                {
                    PrinterSettings settings = new PrinterSettings();
                    printerSettings = new PrintHelper(image, captureDetails).PrintTo(settings.PrinterName);
                }
                else
                {
                    printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog();
                }
                if (printerSettings != null)
                {
                    surface.Modified = false;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.editor_senttoprinter, printerSettings.PrinterName));
                }
            }

            return(printerSettings != null);
        }
Пример #2
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description);

            // Make sure we collect the garbage before opening the screenshot
            GC.Collect();
            GC.WaitForPendingFinalizers();

            bool modified = surface.Modified;

            if (editor == null)
            {
                if (editorConfiguration.ReuseEditor)
                {
                    foreach (IImageEditor openedEditor in ImageEditorForm.Editors)
                    {
                        if (!openedEditor.Surface.Modified)
                        {
                            openedEditor.Surface         = surface;
                            exportInformation.ExportMade = true;
                            break;
                        }
                    }
                }
                if (!exportInformation.ExportMade)
                {
                    try {
                        ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified);                         // Output made??

                        if (!string.IsNullOrEmpty(captureDetails.Filename))
                        {
                            editorForm.SetImagePath(captureDetails.Filename);
                        }
                        editorForm.Show();
                        editorForm.Activate();
                        LOG.Debug("Finished opening Editor");
                        exportInformation.ExportMade = true;
                    } catch (Exception e) {
                        LOG.Error(e);
                        exportInformation.ErrorMessage = e.Message;
                    }
                }
            }
            else
            {
                try {
                    using (Image image = surface.GetImageForExport()) {
                        editor.Surface.AddImageContainer(image, 10, 10);
                    }
                    exportInformation.ExportMade = true;
                } catch (Exception e) {
                    LOG.Error(e);
                    exportInformation.ErrorMessage = e.Message;
                }
            }
            ProcessExport(exportInformation, surface);
            // Workaround for the modified flag when using the editor.
            surface.Modified = modified;
            return(exportInformation);
        }
Пример #3
0
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            if (editor == null)
            {
                // Make sure we collect the garbage before opening the screenshot
                GC.Collect();
                GC.WaitForPendingFinalizers();

                try {
                    ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified);                     // Output made??

                    if (!string.IsNullOrEmpty(captureDetails.Filename))
                    {
                        editorForm.SetImagePath(captureDetails.Filename);
                    }
                    editorForm.Show();
                    editorForm.Activate();
                    LOG.Debug("Finished opening Editor");
                    return(true);
                } catch (Exception e) {
                    LOG.Error(e);
                }
            }
            else
            {
                using (Bitmap image = (Bitmap)surface.GetImageForExport()) {
                    editor.Surface.AddBitmapContainer(image, 10, 10);
                }
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            }
            return(false);
        }
Пример #4
0
        /// <summary>
        /// Upload the capture to imgur
        /// </summary>
        /// <param name="captureDetails">ICaptureDetails</param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="uploadUrl">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, _config.UploadReduceColors);

            try {
                string    filename  = Path.GetFileName(FilenameHelper.GetFilenameFromPattern(_config.FilenamePattern, _config.UploadFormat, captureDetails));
                ImgurInfo imgurInfo = null;

                // Run upload in the background
                new PleaseWaitForm().ShowAndWait("Imgur plug-in", Language.GetString("imgur", LangKey.communication_wait),
                                                 delegate
                {
                    imgurInfo = ImgurUtils.UploadToImgur(surfaceToUpload, outputSettings, captureDetails.Title, filename);
                    if (imgurInfo != null && _config.AnonymousAccess)
                    {
                        Log.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
                        _config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
                        _config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
                        CheckHistory();
                    }
                }
                                                 );

                if (imgurInfo != null)
                {
                    // TODO: Optimize a second call for export
                    using (Image tmpImage = surfaceToUpload.GetImageForExport()) {
                        imgurInfo.Image = ImageHelper.CreateThumbnail(tmpImage, 90, 90);
                    }
                    IniConfig.Save();

                    if (_config.UsePageLink)
                    {
                        uploadUrl = imgurInfo.Page;
                    }
                    else
                    {
                        uploadUrl = imgurInfo.Original;
                    }
                    if (!string.IsNullOrEmpty(uploadUrl) && _config.CopyLinkToClipboard)
                    {
                        try
                        {
                            ClipboardHelper.SetClipboardData(uploadUrl);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Can't write to clipboard: ", ex);
                            uploadUrl = null;
                        }
                    }
                    return(true);
                }
            } catch (Exception e) {
                Log.Error("Error uploading.", e);
                MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
            }
            uploadUrl = null;
            return(false);
        }
 public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails)
 {
     using (Image image = surface.GetImageForExport()) {
         bool uploaded = plugin.Upload(captureDetails, image);
         if (uploaded) {
             surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to Dropbox");
             surface.Modified = false;
         }
         return uploaded;
     }
 }
Пример #6
0
 public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
 {
     using (Image image = surface.GetImageForExport()) {
         bool uploaded = plugin.Upload(captureDetails, image);
         if (uploaded)
         {
             surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to TFS");
             surface.Modified = false;
         }
         return(new ExportInformation("TFS", "", uploaded));
     }
 }
Пример #7
0
 public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails)
 {
     using (Image image = surface.GetImageForExport()) {
         bool uploaded = plugin.Upload(captureDetails, image);
         if (uploaded)
         {
             surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to Box");
             surface.Modified = false;
         }
         return(uploaded);
     }
 }
Пример #8
0
 public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
 {
     using (Image image = surface.GetImageForExport()) {
         if (page != null)
         {
             try {
                 OneNoteExporter.ExportToPage((Bitmap)image, page);
             } catch (Exception ex) {
                 LOG.Error(ex);
             }
         }
     }
     return(true);
 }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            try {
                using (Image image = surface.GetImageForExport()) {
                    ClipboardHelper.SetClipboardData(image);
                    surface.Modified = false;
                }
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetString(LangKey.editor_storedtoclipboard));
                return(true);
            } catch (Exception) {
                surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed));
            }

            return(false);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            bool   outputMade = false;
            string pattern    = "${title}";

            if (string.IsNullOrEmpty(pattern))
            {
                pattern = "greenshot ${capturetime}";
            }
            string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails);
            string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
            string fullPath = Path.Combine(filepath, filename);

            // 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
            using (Image image = surface.GetImageForExport())
            {
                try
                {
                    // TODO: For now we overwrite, but this should be fixed some time
                    ImageOutput.Save(image, fullPath, true);
                    outputMade = true;
                }
                catch (Exception e)
                {
                    LOG.Error("Error saving screenshot!", e);
                    // Show the problem
                    MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error));
                    // when save failed we present a SaveWithDialog
                    fullPath   = ImageOutput.SaveWithDialog(image, captureDetails);
                    outputMade = (fullPath != null);
                }
            }
            // Don't overwite filename if no output is made
            if (outputMade)
            {
                surface.LastSaveFullPath = fullPath;
                surface.Modified         = false;
                captureDetails.Filename  = fullPath;
                surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath));
            }
            else
            {
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "");
            }
            return(outputMade);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string savedTo = null;

            using (Image image = surface.GetImageForExport()) {
                // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
                savedTo = ImageOutput.SaveWithDialog(image, captureDetails);
                if (savedTo != null)
                {
                    surface.Modified         = false;
                    surface.LastSaveFullPath = savedTo;
                    captureDetails.Filename  = savedTo;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath));
                }
            }
            return(savedTo != null);
        }
Пример #12
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
			CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
			OutputSettings outputSettings = new OutputSettings();

			string file = FilenameHelper.GetFilename(OutputFormat.png, null);
			string filePath = Path.Combine(config.OutputFilePath, file);
			using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
				using (Image image = surface.GetImageForExport()) {
					ImageOutput.SaveToStream(image, stream, outputSettings);
				}
			}
			exportInformation.Filepath = filePath;
			exportInformation.ExportMade = true;
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            CoreConfiguration config            = IniConfig.GetIniSection <CoreConfiguration>();
            OutputSettings    outputSettings    = new OutputSettings();

            string file     = FilenameHelper.GetFilename(OutputFormat.png, null);
            string filePath = Path.Combine(config.OutputFilePath, file);

            using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
                using (Image image = surface.GetImageForExport()) {
                    ImageOutput.SaveToStream(image, stream, outputSettings);
                }
            }
            exportInformation.Filepath   = filePath;
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Пример #14
0
        /// <summary>
        /// Create an image from a surface with the settings from the output settings applied
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="outputSettings"></param>
        /// <param name="imageToSave"></param>
        /// <returns>true if the image must be disposed</returns>
        public static bool CreateImageFromSurface(ISurface surface, SurfaceOutputSettings outputSettings, out Image imageToSave)
        {
            bool disposeImage = false;

            if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly)
            {
                // We save the image of the surface, this should not be disposed
                imageToSave = surface.Image;
            }
            else
            {
                // We create the export image of the surface to save
                imageToSave  = surface.GetImageForExport();
                disposeImage = true;
            }

            // The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
            if (outputSettings.Format == OutputFormat.greenshot)
            {
                return(disposeImage);
            }
            Image tmpImage;

            if (outputSettings.Effects != null && outputSettings.Effects.Count > 0)
            {
                // apply effects, if there are any
                using (Matrix matrix = new Matrix())
                {
                    tmpImage = ImageHelper.ApplyEffects(imageToSave, outputSettings.Effects, matrix);
                }
                if (tmpImage != null)
                {
                    if (disposeImage)
                    {
                        imageToSave.Dispose();
                    }
                    imageToSave  = tmpImage;
                    disposeImage = true;
                }
            }

            return(disposeImage);
        }
Пример #15
0
        /// <summary>
        /// Create an image from a surface with the settings from the output settings applied
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="outputSettings"></param>
        /// <param name="imageToSave"></param>
        /// <returns>true if the image must be disposed</returns>
        public static bool CreateImageFromSurface(ISurface surface, SurfaceOutputSettings outputSettings, out Image imageToSave)
        {
            bool disposeImage = false;

            if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly)
            {
                // We save the image of the surface, this should not be disposed
                imageToSave = surface.Image;
            }
            else
            {
                // We create the export image of the surface to save
                imageToSave = surface.GetImageForExport();
                disposeImage = true;
            }

            // The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
            if (outputSettings.Format == OutputFormat.greenshot)
            {
                return disposeImage;
            }
            Image tmpImage;
            if (outputSettings.Effects != null && outputSettings.Effects.Count > 0)
            {
                // apply effects, if there are any
                using (Matrix matrix = new Matrix())
                {
                    tmpImage = ImageHelper.ApplyEffects(imageToSave, outputSettings.Effects, matrix);
                }
                if (tmpImage != null)
                {
                    if (disposeImage)
                    {
                        imageToSave.Dispose();
                    }
                    imageToSave = tmpImage;
                    disposeImage = true;
                }
            }

            return disposeImage;
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile   = captureDetails.Filename;
            Size   imageSize = Size.Empty;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile   = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                    imageSize = image.Size;
                }
            }
            if (presentationName != null)
            {
                PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> presentations = PowerpointExporter.GetPowerpointPresentations();
                    if (presentations != null && presentations.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new PowerpointDestination());
                        foreach (string presentation in presentations)
                        {
                            destinations.Add(new PowerpointDestination(presentation));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;
            return(true);
        }
Пример #17
0
        private static bool CreateImageFromSurface(ISurface surface, OutputSettings outputSettings,
                                                   out Image imageToSave)
        {
            try {
                imageToSave = surface.GetImageForExport();
            }
            catch (Exception ex) {
                imageToSave = null;
                log.Error("Failed to GetImageForExport of surface, " + ex.Message);
            }

            if (imageToSave == null)
            {
                return(false);
            }

            if (outputSettings.Effects != null && outputSettings.Effects.Count > 0)
            {
                // apply effects, if there are any
                Image tmpImage;
                Point ignoreOffset;
                try {
                    tmpImage = ImageOperator.ApplyEffects((Bitmap)imageToSave,
                                                          outputSettings.Effects, out ignoreOffset);
                }
                catch (Exception ex) {
                    tmpImage = null;
                    log.Error("Failed to apply output effect, " + ex.Message);
                }

                if (tmpImage != null)
                {
                    imageToSave.Dispose();
                    imageToSave = tmpImage;
                }
            }

            return(true);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            if (documentCaption != null)
            {
                WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new WordDestination());
                        foreach (string document in documents)
                        {
                            destinations.Add(new WordDestination(document));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                WordExporter.InsertIntoNewDocument(tmpFile);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            return(true);
        }
Пример #19
0
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            if (workbookName != null)
            {
                ExcelExporter.InsertIntoExistingWorkbook(workbookName, tmpFile);
            }
            else
            {
                ExcelExporter.InsertIntoNewWorkbook(tmpFile);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;
            return(true);
        }
        /// <summary>
        /// Upload the capture to FogBugz
        /// </summary>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(OutputFormat.jpg, 90, false);

            using (MemoryStream stream = new MemoryStream()) {
                surfaceToUpload.GetImageForExport().Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                try {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(OutputFormat.jpg, captureDetails));

                    CaseSearchForm caseSearchForm = new CaseSearchForm(config, this.host, filename, captureDetails, stream);

                    if (caseSearchForm.ShowDialog() == DialogResult.OK)
                    {
                        IniConfig.Save();
                        return(true);
                    }
                } catch (Exception e) {
                    MessageBox.Show(Language.GetString("fogbugz", LangKey.upload_failure) + " " + e.Message);
                }
            }
            return(false);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            if (!isOutlookUsed) {
                using (Image image = surface.GetImageForExport()) {
                    MapiMailMessage.SendImage(image, captureDetails);
                    surface.Modified = false;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to " + mapiClient);
                }
                return true;
            }

            // Outlook logic
            string tmpFile = captureDetails.Filename;
            if (tmpFile == null || surface.Modified) {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            } else {
                LOG.InfoFormat("Using already available file: {0}", tmpFile);
            }

            // Create a attachment name for the image
            string attachmentName = captureDetails.Title;
            if (!string.IsNullOrEmpty(attachmentName)) {
                attachmentName = attachmentName.Trim();
            }
            // Set default if non is set
            if (string.IsNullOrEmpty(attachmentName)) {
                attachmentName = "Greenshot Capture";
            }
            // Make sure it's "clean" so it doesn't corrupt the header
            attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", "");

            if (outlookInspectorCaption != null) {
                OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName);
            } else {
                if (!manuallyInitiated) {
                    Dictionary<string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings);
                    if (inspectorCaptions != null && inspectorCaptions.Count > 0) {
                        List<IDestination> destinations = new List<IDestination>();
                        destinations.Add(new EmailDestination());
                        foreach (string inspectorCaption in inspectorCaptions.Keys) {
                            destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return false;
                    }
                }
                OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, captureDetails.Title, attachmentName);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            // Don't know how to handle a cancel in the email

            return true;
        }
Пример #22
0
        /// <summary>
        /// Create an image from a surface with the settings from the output settings applied
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="outputSettings"></param>
        /// <param name="imageToSave"></param>
        /// <returns>true if the image must be disposed</returns>
        public static bool CreateImageFromSurface(ISurface surface, SurfaceOutputSettings outputSettings, out Image imageToSave)
        {
            bool        disposeImage = false;
            ImageFormat imageFormat  = null;

            switch (outputSettings.Format)
            {
            case OutputFormat.bmp:
                imageFormat = ImageFormat.Bmp;
                break;

            case OutputFormat.gif:
                imageFormat = ImageFormat.Gif;
                break;

            case OutputFormat.jpg:
                imageFormat = ImageFormat.Jpeg;
                break;

            case OutputFormat.tiff:
                imageFormat = ImageFormat.Tiff;
                break;

            case OutputFormat.greenshot:
            case OutputFormat.png:
            default:
                imageFormat = ImageFormat.Png;
                break;
            }

            if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly)
            {
                // We save the image of the surface, this should not be disposed
                imageToSave = surface.Image;
            }
            else
            {
                // We create the export image of the surface to save
                imageToSave  = surface.GetImageForExport();
                disposeImage = true;
            }

            // The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
            if (outputSettings.Format != OutputFormat.greenshot)
            {
                Image tmpImage;
                if (outputSettings.Effects != null && outputSettings.Effects.Count > 0)
                {
                    // apply effects, if there are any
                    Point ignoreOffset;
                    tmpImage = ImageHelper.ApplyEffects((Bitmap)imageToSave, outputSettings.Effects, out ignoreOffset);
                    if (tmpImage != null)
                    {
                        if (disposeImage)
                        {
                            imageToSave.Dispose();
                        }
                        imageToSave  = tmpImage;
                        disposeImage = true;
                    }
                }

                // check for color reduction, forced or automatically, only when the DisableReduceColors is false
                if (!outputSettings.DisableReduceColors && (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors))
                {
                    bool isAlpha = Image.IsAlphaPixelFormat(imageToSave.PixelFormat);
                    if (outputSettings.ReduceColors || (!isAlpha && conf.OutputFileAutoReduceColors))
                    {
                        using (WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave))
                        {
                            int colorCount = quantizer.GetColorCount();
                            LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
                            if (outputSettings.ReduceColors || colorCount < 256)
                            {
                                try
                                {
                                    LOG.Info("Reducing colors on bitmap to 256.");
                                    tmpImage = quantizer.GetQuantizedImage(256);
                                    if (disposeImage)
                                    {
                                        imageToSave.Dispose();
                                    }
                                    imageToSave = tmpImage;
                                    // Make sure the "new" image is disposed
                                    disposeImage = true;
                                }
                                catch (Exception e)
                                {
                                    LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
                                }
                            }
                        }
                    }
                    else if (isAlpha && !outputSettings.ReduceColors)
                    {
                        LOG.Info("Skipping 'optional' color reduction as the image has alpha");
                    }
                }
            }
            return(disposeImage);
        }
 public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
 {
     string tmpFile = captureDetails.Filename;
     if (tmpFile == null || surface.Modified) {
         using (Image image = surface.GetImageForExport()) {
             tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
         }
     }
     if (workbookName != null) {
         ExcelExporter.InsertIntoExistingWorkbook(workbookName, tmpFile);
     } else {
         ExcelExporter.InsertIntoNewWorkbook(tmpFile);
     }
     surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
     surface.Modified = false;
     return true;
 }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            PrinterSettings printerSettings = null;
            using (Image image = surface.GetImageForExport()) {
                if (!string.IsNullOrEmpty(printerName)) {
                    printerSettings = new PrintHelper(image, captureDetails).PrintTo(printerName);
                } else if (!manuallyInitiated) {
                    PrinterSettings settings = new PrinterSettings();
                    printerSettings = new PrintHelper(image, captureDetails).PrintTo(settings.PrinterName);
                } else {
                    printerSettings = new PrintHelper(image, captureDetails).PrintWithDialog();
                }
                if (printerSettings != null) {
                    surface.Modified = false;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.editor_senttoprinter, printerSettings.PrinterName));
                }
            }

            return printerSettings != null;
        }
Пример #25
0
        /// <summary>
        /// Create an image from a surface with the settings from the output settings applied
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="outputSettings"></param>
        /// <param name="imageToSave"></param>
        /// <returns>true if the image must be disposed</returns>
        public static bool CreateImageFromSurface(ISurface surface, SurfaceOutputSettings outputSettings, out Image imageToSave)
        {
            bool disposeImage = false;

            if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly)
            {
                // We save the image of the surface, this should not be disposed
                imageToSave = surface.Image;
            }
            else
            {
                // We create the export image of the surface to save
                imageToSave  = surface.GetImageForExport();
                disposeImage = true;
            }

            // The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
            if (outputSettings.Format == OutputFormat.greenshot)
            {
                return(disposeImage);
            }
            Image tmpImage;

            if (outputSettings.Effects != null && outputSettings.Effects.Count > 0)
            {
                // apply effects, if there are any
                using (Matrix matrix = new Matrix()) {
                    tmpImage = ImageHelper.ApplyEffects(imageToSave, outputSettings.Effects, matrix);
                }
                if (tmpImage != null)
                {
                    if (disposeImage)
                    {
                        imageToSave.Dispose();
                    }
                    imageToSave  = tmpImage;
                    disposeImage = true;
                }
            }

            // check for color reduction, forced or automatically, only when the DisableReduceColors is false
            if (outputSettings.DisableReduceColors || (!CoreConfig.OutputFileAutoReduceColors && !outputSettings.ReduceColors))
            {
                return(disposeImage);
            }
            bool isAlpha = Image.IsAlphaPixelFormat(imageToSave.PixelFormat);

            if (outputSettings.ReduceColors || (!isAlpha && CoreConfig.OutputFileAutoReduceColors))
            {
                using (var quantizer = new WuQuantizer((Bitmap)imageToSave)) {
                    int colorCount = quantizer.GetColorCount();
                    Log.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
                    if (!outputSettings.ReduceColors && colorCount >= 256)
                    {
                        return(disposeImage);
                    }
                    try {
                        Log.Info("Reducing colors on bitmap to 256.");
                        tmpImage = quantizer.GetQuantizedImage(CoreConfig.OutputFileReduceColorsTo);
                        if (disposeImage)
                        {
                            imageToSave.Dispose();
                        }
                        imageToSave = tmpImage;
                        // Make sure the "new" image is disposed
                        disposeImage = true;
                    } catch (Exception e) {
                        Log.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
                    }
                }
            }
            else if (isAlpha && !outputSettings.ReduceColors)
            {
                Log.Info("Skipping 'optional' color reduction as the image has alpha");
            }
            return(disposeImage);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            bool outputMade = false;
            string pattern = "${title}";
            if (string.IsNullOrEmpty(pattern))
            {
                pattern = "greenshot ${capturetime}";
            }
            string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails);
            string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
            string fullPath = Path.Combine(filepath, filename);

            // 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
            using (Image image = surface.GetImageForExport())
            {
                try
                {
                    // TODO: For now we overwrite, but this should be fixed some time
                    ImageOutput.Save(image, fullPath, true);
                    outputMade = true;
                }
                catch (Exception e)
                {
                    LOG.Error("Error saving screenshot!", e);
                    // Show the problem
                    MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error));
                    // when save failed we present a SaveWithDialog
                    fullPath = ImageOutput.SaveWithDialog(image, captureDetails);
                    outputMade = (fullPath != null);
                }
            }
            // Don't overwite filename if no output is made
            if (outputMade)
            {
                surface.LastSaveFullPath = fullPath;
                surface.Modified = false;
                captureDetails.Filename = fullPath;
                surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath));
            }
            else
            {
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "");
            }
            return outputMade;
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            try {
                using (Image image = surface.GetImageForExport()) {
                    ClipboardHelper.SetClipboardData(image);
                    surface.Modified = false;
                }
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetString(LangKey.editor_storedtoclipboard));
                return true;
            } catch (Exception) {
                surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed));
            }

            return false;
        }
 public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
 {
     string savedTo = null;
     using (Image image = surface.GetImageForExport()) {
         // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
         savedTo = ImageOutput.SaveWithDialog(image, captureDetails);
         if (savedTo != null) {
             surface.Modified = false;
             surface.LastSaveFullPath = savedTo;
             captureDetails.Filename = savedTo;
             surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath));
         }
     }
     return savedTo != null;
 }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile = captureDetails.Filename;
            if (tmpFile == null || surface.Modified) {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            if (documentCaption != null) {
                WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
            } else {
                if (!manuallyInitiated) {
                    List<string> documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0) {
                        List<IDestination> destinations = new List<IDestination>();
                        destinations.Add(new WordDestination());
                        foreach (string document in documents) {
                            destinations.Add(new WordDestination(document));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return false;
                    }
                }
                WordExporter.InsertIntoNewDocument(tmpFile);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            return true;
        }
Пример #30
0
        /// <summary>
        /// Create an image from a surface with the settings from the output settings applied
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="outputSettings"></param>
        /// <param name="imageToSave"></param>
        /// <returns>true if the image must be disposed</returns>
        public static bool CreateImageFromSurface(ISurface surface, SurfaceOutputSettings outputSettings, out Image imageToSave)
        {
            bool disposeImage = false;
            ImageFormat imageFormat = null;
            switch (outputSettings.Format)
            {
                case OutputFormat.bmp:
                    imageFormat = ImageFormat.Bmp;
                    break;
                case OutputFormat.gif:
                    imageFormat = ImageFormat.Gif;
                    break;
                case OutputFormat.jpg:
                    imageFormat = ImageFormat.Jpeg;
                    break;
                case OutputFormat.tiff:
                    imageFormat = ImageFormat.Tiff;
                    break;
                case OutputFormat.greenshot:
                case OutputFormat.png:
                default:
                    imageFormat = ImageFormat.Png;
                    break;
            }

            if (outputSettings.Format == OutputFormat.greenshot || outputSettings.SaveBackgroundOnly)
            {
                // We save the image of the surface, this should not be disposed
                imageToSave = surface.Image;
            }
            else
            {
                // We create the export image of the surface to save
                imageToSave = surface.GetImageForExport();
                disposeImage = true;
            }

            // The following block of modifications should be skipped when saving the greenshot format, no effects or otherwise!
            if (outputSettings.Format != OutputFormat.greenshot)
            {
                Image tmpImage;
                if (outputSettings.Effects != null && outputSettings.Effects.Count > 0)
                {
                    // apply effects, if there are any
                    Point ignoreOffset;
                    tmpImage = ImageHelper.ApplyEffects((Bitmap)imageToSave, outputSettings.Effects, out ignoreOffset);
                    if (tmpImage != null)
                    {
                        if (disposeImage)
                        {
                            imageToSave.Dispose();
                        }
                        imageToSave = tmpImage;
                        disposeImage = true;
                    }
                }

                // check for color reduction, forced or automatically, only when the DisableReduceColors is false
                if (!outputSettings.DisableReduceColors && (conf.OutputFileAutoReduceColors || outputSettings.ReduceColors))
                {
                    bool isAlpha = Image.IsAlphaPixelFormat(imageToSave.PixelFormat);
                    if (outputSettings.ReduceColors || (!isAlpha && conf.OutputFileAutoReduceColors))
                    {
                        using (WuQuantizer quantizer = new WuQuantizer((Bitmap)imageToSave))
                        {
                            int colorCount = quantizer.GetColorCount();
                            LOG.InfoFormat("Image with format {0} has {1} colors", imageToSave.PixelFormat, colorCount);
                            if (outputSettings.ReduceColors || colorCount < 256)
                            {
                                try
                                {
                                    LOG.Info("Reducing colors on bitmap to 256.");
                                    tmpImage = quantizer.GetQuantizedImage(256);
                                    if (disposeImage)
                                    {
                                        imageToSave.Dispose();
                                    }
                                    imageToSave = tmpImage;
                                    // Make sure the "new" image is disposed
                                    disposeImage = true;
                                }
                                catch (Exception e)
                                {
                                    LOG.Warn("Error occurred while Quantizing the image, ignoring and using original. Error: ", e);
                                }
                            }
                        }
                    }
                    else if (isAlpha && !outputSettings.ReduceColors)
                    {
                        LOG.Info("Skipping 'optional' color reduction as the image has alpha");
                    }
                }
            }
            return disposeImage;
        }
 public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
 {
     string tmpFile = captureDetails.Filename;
     Size imageSize = Size.Empty;
     if (tmpFile == null || surface.Modified) {
         using (Image image = surface.GetImageForExport()) {
             tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
             imageSize = image.Size;
         }
     }
     if (presentationName != null) {
         PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
     } else {
         if (!manuallyInitiated) {
             List<string> presentations = PowerpointExporter.GetPowerpointPresentations();
             if (presentations != null && presentations.Count > 0) {
                 List<IDestination> destinations = new List<IDestination>();
                 destinations.Add(new PowerpointDestination());
                 foreach (string presentation in presentations) {
                     destinations.Add(new PowerpointDestination(presentation));
                 }
                 ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                 PickerDestination.ShowMenuAtCursor(menu);
                 return false;
             }
         }
         PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
     }
     surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
     surface.Modified = false;
     return true;
 }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            if (editor == null) {
                // Make sure we collect the garbage before opening the screenshot
                GC.Collect();
                GC.WaitForPendingFinalizers();

                try {
                    ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified); // Output made??

                    if (!string.IsNullOrEmpty(captureDetails.Filename)) {
                        editorForm.SetImagePath(captureDetails.Filename);
                    }
                    editorForm.Show();
                    editorForm.Activate();
                    LOG.Debug("Finished opening Editor");
                    return true;
                } catch (Exception e) {
                    LOG.Error(e);
                }
            } else {
                using (Bitmap image = (Bitmap)surface.GetImageForExport()) {
                    editor.Surface.AddBitmapContainer(image, 10, 10);
                }
                surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            }
            return false;
        }
Пример #33
0
        /// <summary>
        /// Share the screenshot with a windows app
        /// </summary>
        /// <param name="manuallyInitiated"></param>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns>ExportInformation</returns>
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);

            try
            {
                var handle = PluginUtils.Host.GreenshotForm.Handle;

                var exportTarget = Task.Run(async() =>
                {
                    var taskCompletionSource = new TaskCompletionSource <string>();

                    using (var imageStream = new MemoryRandomAccessStream())
                        using (var logoStream = new MemoryRandomAccessStream())
                            using (var thumbnailStream = new MemoryRandomAccessStream())
                            {
                                var outputSettings = new SurfaceOutputSettings();
                                outputSettings.PreventGreenshotFormat();

                                // Create capture for export
                                ImageOutput.SaveToStream(surface, imageStream, outputSettings);
                                imageStream.Position = 0;
                                Log.Info("Created RandomAccessStreamReference for the image");
                                var imageRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(imageStream);
                                RandomAccessStreamReference thumbnailRandomAccessStreamReference;
                                RandomAccessStreamReference logoRandomAccessStreamReference;

                                // Create thumbnail
                                using (var tmpImageForThumbnail = surface.GetImageForExport())
                                {
                                    using (var thumbnail = ImageHelper.CreateThumbnail(tmpImageForThumbnail, 240, 160))
                                    {
                                        ImageOutput.SaveToStream(thumbnail, null, thumbnailStream, outputSettings);
                                        thumbnailStream.Position             = 0;
                                        thumbnailRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(thumbnailStream);
                                        Log.Info("Created RandomAccessStreamReference for the thumbnail");
                                    }
                                }
                                // Create logo
                                using (var logo = GreenshotResources.getGreenshotIcon().ToBitmap())
                                {
                                    using (var logoThumbnail = ImageHelper.CreateThumbnail(logo, 30, 30))
                                    {
                                        ImageOutput.SaveToStream(logoThumbnail, null, logoStream, outputSettings);
                                        logoStream.Position             = 0;
                                        logoRandomAccessStreamReference = RandomAccessStreamReference.CreateFromStream(logoStream);
                                        Log.Info("Created RandomAccessStreamReference for the logo");
                                    }
                                }
                                string applicationName        = null;
                                var dataTransferManagerHelper = new DataTransferManagerHelper(handle);
                                dataTransferManagerHelper.DataTransferManager.TargetApplicationChosen += (dtm, args) =>
                                {
                                    Log.InfoFormat("Trying to share with {0}", args.ApplicationName);
                                    applicationName = args.ApplicationName;
                                };
                                var filename    = FilenameHelper.GetFilename(OutputFormat.png, captureDetails);
                                var storageFile = await StorageFile.CreateStreamedFileAsync(filename, async streamedFileDataRequest =>
                                {
                                    // Information on how was found here: https://socialeboladev.wordpress.com/2013/03/15/how-to-use-createstreamedfileasync/
                                    Log.DebugFormat("Creating deferred file {0}", filename);
                                    try
                                    {
                                        using (var deferredStream = streamedFileDataRequest.AsStreamForWrite())
                                        {
                                            await imageStream.CopyToAsync(deferredStream).ConfigureAwait(false);
                                            await imageStream.FlushAsync().ConfigureAwait(false);
                                        }
                                        // Signal that the stream is ready
                                        streamedFileDataRequest.Dispose();
                                    }
                                    catch (Exception)
                                    {
                                        streamedFileDataRequest.FailAndClose(StreamedFileFailureMode.Incomplete);
                                    }
                                    // Signal transfer ready to the await down below
                                    taskCompletionSource.TrySetResult(applicationName);
                                }, imageRandomAccessStreamReference).AsTask().ConfigureAwait(false);

                                dataTransferManagerHelper.DataTransferManager.DataRequested += (sender, args) =>
                                {
                                    var deferral = args.Request.GetDeferral();
                                    args.Request.Data.OperationCompleted += (dp, eventArgs) =>
                                    {
                                        Log.DebugFormat("OperationCompleted: {0}, shared with", eventArgs.Operation);
                                        taskCompletionSource.TrySetResult(applicationName);
                                    };
                                    var dataPackage = args.Request.Data;
                                    dataPackage.Properties.Title               = captureDetails.Title;
                                    dataPackage.Properties.ApplicationName     = "Greenshot";
                                    dataPackage.Properties.Description         = "Share a screenshot";
                                    dataPackage.Properties.Thumbnail           = thumbnailRandomAccessStreamReference;
                                    dataPackage.Properties.Square30x30Logo     = logoRandomAccessStreamReference;
                                    dataPackage.Properties.LogoBackgroundColor = Color.FromArgb(0xff, 0x3d, 0x3d, 0x3d);
                                    dataPackage.SetStorageItems(new List <IStorageItem> {
                                        storageFile
                                    });
                                    dataPackage.SetBitmap(imageRandomAccessStreamReference);
                                    dataPackage.Destroyed += (dp, o) =>
                                    {
                                        Log.Debug("Destroyed.");
                                    };
                                    deferral.Complete();
                                };
                                dataTransferManagerHelper.ShowShareUi();
                                return(await taskCompletionSource.Task.ConfigureAwait(false));
                            }
                }).Result;
                if (string.IsNullOrWhiteSpace(exportTarget))
                {
                    exportInformation.ExportMade = false;
                }
                else
                {
                    exportInformation.ExportMade             = true;
                    exportInformation.DestinationDescription = exportTarget;
                }
            }
            catch (Exception ex)
            {
                exportInformation.ExportMade   = false;
                exportInformation.ErrorMessage = ex.Message;
            }

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
 public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
 {
     using (Image image = surface.GetImageForExport()) {
         if (page != null) {
             try {
                 OneNoteExporter.ExportToPage((Bitmap)image, page);
             } catch (Exception ex) {
                 LOG.Error(ex);
             }
         }
     }
     return true;
 }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            if (!isOutlookUsed)
            {
                using (Image image = surface.GetImageForExport()) {
                    MapiMailMessage.SendImage(image, captureDetails);
                    surface.Modified = false;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to " + mapiClient);
                }
                return(true);
            }

            // Outlook logic
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            else
            {
                LOG.InfoFormat("Using already available file: {0}", tmpFile);
            }

            // Create a attachment name for the image
            string attachmentName = captureDetails.Title;

            if (!string.IsNullOrEmpty(attachmentName))
            {
                attachmentName = attachmentName.Trim();
            }
            // Set default if non is set
            if (string.IsNullOrEmpty(attachmentName))
            {
                attachmentName = "Greenshot Capture";
            }
            // Make sure it's "clean" so it doesn't corrupt the header
            attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", "");

            if (outlookInspectorCaption != null)
            {
                OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    Dictionary <string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings);
                    if (inspectorCaptions != null && inspectorCaptions.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new EmailDestination());
                        foreach (string inspectorCaption in inspectorCaptions.Keys)
                        {
                            destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, captureDetails.Title, attachmentName);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            // Don't know how to handle a cancel in the email

            return(true);
        }
Пример #36
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(Designation, Description);
			// Make sure we collect the garbage before opening the screenshot
			GC.Collect();
			GC.WaitForPendingFinalizers();

			bool modified = surface.Modified;
			if (editor == null) {
				if (editorConfiguration.ReuseEditor) {
					foreach(IImageEditor openedEditor in ImageEditorForm.Editors) {
						if (!openedEditor.Surface.Modified) {
							openedEditor.Surface = surface;
							exportInformation.ExportMade = true;
							break;
						}
					}
				}
				if (!exportInformation.ExportMade) {
					try {
						ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified); // Output made??

						if (!string.IsNullOrEmpty(captureDetails.Filename)) {
							editorForm.SetImagePath(captureDetails.Filename);
						}
						editorForm.Show();
						editorForm.Activate();
						LOG.Debug("Finished opening Editor");
						exportInformation.ExportMade = true;
					} catch (Exception e) {
						LOG.Error(e);
						exportInformation.ErrorMessage = e.Message;
					}
				}
			} else {
				try {
					using (Image image = surface.GetImageForExport()) {
						editor.Surface.AddImageContainer(image, 10, 10);
					}
					exportInformation.ExportMade = true;
				} catch (Exception e) {
					LOG.Error(e);
					exportInformation.ErrorMessage = e.Message;
				}
			}
			ProcessExport(exportInformation, surface);
			// Workaround for the modified flag when using the editor.
			surface.Modified = modified;
			return exportInformation;
		}
Пример #37
0
		/// <summary>
		/// Upload the capture to imgur
		/// </summary>
		/// <param name="captureDetails"></param>
		/// <param name="image"></param>
		/// <param name="uploadURL">out string for the url</param>
		/// <returns>true if the upload succeeded</returns>
		public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL) {
			SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
			try {
				string filename = Path.GetFileName(FilenameHelper.GetFilenameFromPattern(config.FilenamePattern, config.UploadFormat, captureDetails));
				ImgurInfo imgurInfo = null;

				// Run upload in the background
				new PleaseWaitForm().ShowAndWait("Imgur plug-in", Language.GetString("imgur", LangKey.communication_wait),
					delegate() {
						imgurInfo = ImgurUtils.UploadToImgur(surfaceToUpload, outputSettings, captureDetails.Title, filename);
						if (imgurInfo != null && config.AnonymousAccess) {
							LOG.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
							config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
							config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
							CheckHistory();
						}
					}
				);

				if (imgurInfo != null) {
					// TODO: Optimize a second call for export
					using (Image tmpImage = surfaceToUpload.GetImageForExport()) {
						imgurInfo.Image = ImageHelper.CreateThumbnail(tmpImage, 90, 90);
					}
					IniConfig.Save();

					if (config.UsePageLink)
					{
						uploadURL = imgurInfo.Page;
					}
					else
					{
						uploadURL = imgurInfo.Original;
					}
					if (!string.IsNullOrEmpty(uploadURL) && config.CopyLinkToClipboard)
					{
						try
						{
							ClipboardHelper.SetClipboardData(uploadURL);

						}
						catch (Exception ex)
						{
							LOG.Error("Can't write to clipboard: ", ex);
							uploadURL = null;
						}
					}
					return true;
				}
			} catch (Exception e) {
				LOG.Error("Error uploading.", e);
				MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
			}
			uploadURL = null;
			return false;
		}