Ejemplo n.º 1
0
        /// <summary>
        ///     Do the actual upload to OneDrive
        /// </summary>
        /// <param name="oAuth2Settings">OAuth2Settings</param>
        /// <param name="surfaceToUpload">ISurface to upload</param>
        /// <param name="outputSettings">OutputSettings for the image file format</param>
        /// <param name="title">Title</param>
        /// <param name="filename">Filename</param>
        /// <param name="progress">IProgress</param>
        /// <param name="token">CancellationToken</param>
        /// <returns>ImgurInfo with details</returns>
        public static async Task <OneDriveUploadResponse> UploadToOneDriveAsync(OAuth2Settings oAuth2Settings, ISurface surfaceToUpload,
                                                                                SurfaceOutputSettings outputSettings, string title, string filename, IProgress <int> progress = null,
                                                                                CancellationToken token = default)
        {
            var uploadUri      = new Uri(UrlUtils.GetUploadUrl(filename));
            var localBehaviour = Behaviour.ShallowClone();

            if (progress != null)
            {
                localBehaviour.UploadProgress = percent => { UiContext.RunOn(() => progress.Report((int)(percent * 100)), token); };
            }
            var oauthHttpBehaviour = OAuth2HttpBehaviourFactory.Create(oAuth2Settings, localBehaviour);

            using (var imageStream = new MemoryStream())
            {
                ImageOutput.SaveToStream(surfaceToUpload, imageStream, outputSettings);
                imageStream.Position = 0;
                using (var content = new StreamContent(imageStream))
                {
                    content.Headers.Add("Content-Type", "image/" + outputSettings.Format);
                    oauthHttpBehaviour.MakeCurrent();
                    return(await uploadUri.PostAsync <OneDriveUploadResponse>(content, token));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Export the capture to outlook
        /// </summary>
        /// <param name="manuallyInitiated"></param>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns></returns>
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            // Outlook logic
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified || !Regex.IsMatch(tmpFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
            }
            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);
                exportInformation.ExportMade = true;
            }
            else
            {
                if (!manuallyInitiated)
                {
                    IDictionary <string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets();
                    if (inspectorCaptions != null && inspectorCaptions.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new OutlookDestination());
                        foreach (string inspectorCaption in inspectorCaptions.Keys)
                        {
                            destinations.Add(new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
                        }
                        // Return the ExportInformation from the picker without processing, as this indirectly comes from us self
                        return(ShowPickerMenu(false, surface, captureDetails, destinations));
                    }
                }
                else
                {
                    exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC, null);
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Export the capture to the specified page
 /// </summary>
 /// <param name="oneNoteApplication">IOneNoteApplication</param>
 /// <param name="surfaceToUpload">ISurface</param>
 /// <param name="page">OneNotePage</param>
 /// <returns>bool true if everything worked</returns>
 private static bool ExportToPage(IOneNoteApplication oneNoteApplication, ISurface surfaceToUpload, OneNotePage page)
 {
     if (oneNoteApplication == null)
     {
         return(false);
     }
     using (var pngStream = new MemoryStream())
     {
         var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
         ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
         var base64String   = Convert.ToBase64String(pngStream.GetBuffer());
         var imageXmlStr    = string.Format(XmlImageContent, base64String, surfaceToUpload.Screenshot.Width, surfaceToUpload.Screenshot.Height);
         var pageChangesXml = string.Format(XmlOutline, imageXmlStr, page.ID, OnenoteNamespace2010, page.Name);
         Log.Info().WriteLine("Sending XML: {0}", pageChangesXml);
         oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
         try
         {
             oneNoteApplication.NavigateTo(page.ID, null, false);
         }
         catch (Exception ex)
         {
             Log.Warn().WriteLine(ex, "Unable to navigate to the target page");
         }
         return(true);
     }
 }
Ejemplo n.º 4
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 != null && 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 = conf.OutputFileAllowOverwrite;
            }
            if (conf.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, conf.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 = outputMade;
                exportInformation.Filepath   = fullPath;
                captureDetails.Filename      = fullPath;
                conf.OutputFileAsFullpath    = fullPath;
            }

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            string            tmpFile           = captureDetails.Filename;

            if (tmpFile == null || surface.Modified || !Regex.IsMatch(tmpFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
            }
            if (documentCaption != null)
            {
                try {
                    WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
                    exportInformation.ExportMade = true;
                } catch (Exception) {
                    try {
                        WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
                        exportInformation.ExportMade = true;
                    } catch (Exception ex) {
                        LOG.Error(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description));
                    }
                }
            }
            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));
                        }
                        // Return the ExportInformation from the picker without processing, as this indirectly comes from us self
                        return(ShowPickerMenu(false, surface, captureDetails, destinations));
                    }
                }
                try {
                    WordExporter.InsertIntoNewDocument(tmpFile, null, null);
                    exportInformation.ExportMade = true;
                } catch (Exception) {
                    // Retry once, just in case
                    try {
                        WordExporter.InsertIntoNewDocument(tmpFile, null, null);
                        exportInformation.ExportMade = true;
                    } catch (Exception ex) {
                        LOG.Error(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description));
                    }
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 6
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            base.SetDefaults(surface);
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            bool   createdFile = false;
            string imageFile   = captureDetails.Filename;

            if (imageFile == null || surface.Modified || !Regex.IsMatch(imageFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                imageFile   = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
                createdFile = true;
            }
            if (_workbookName != null)
            {
                ExcelExporter.InsertIntoExistingWorkbook(_workbookName, imageFile, surface.Image.Size);
            }
            else
            {
                ExcelExporter.InsertIntoNewWorkbook(imageFile, surface.Image.Size);
            }
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            // Cleanup imageFile if we created it here, so less tmp-files are generated and left
            if (createdFile)
            {
                ImageOutput.DeleteNamedTmpFile(imageFile);
            }
            return(exportInformation);
        }
Ejemplo n.º 7
0
        static ImageOutput[] TransformToCubeFaces(byte[] srcStream, int width, int height)
        {
            List <ImageOutput> imageOutputs = new List <ImageOutput>();

            for (int i = 0; i <= 5; i++)
            {
                ImageOutput imageOutPut = new ImageOutput
                {
                    Height = outWidth,
                    Width  = outWidth,
                    Data   = new byte[4 * outWidth * outWidth],
                };
                imageOutputs.Add(imageOutPut);
            }

            imageOutputs.ToArray();

            List <ImageOutput> listOutPut = new List <ImageOutput>();

            for (int i = 0; i < 6; i++)
            {
                ImageOutput result = ConvertToCubeFaces(width, height, srcStream, imageOutputs[i], i);

                listOutPut.Add(result);
            }
            return(listOutPut.ToArray());
        }
Ejemplo n.º 8
0
        public static ImageOutput loadByUsingImageSharp(string imageName)
        {
            var image  = Image.Load <Rgba32>(imageName);
            var imgOut = new ImageOutput();

            Console.WriteLine("image.Metadata" + image.Metadata.ToString());
            imgOut.Width  = image.Width;
            imgOut.Height = image.Height;
            imgOut.Data   = MemoryMarshal.AsBytes(image.GetPixelSpan()).ToArray();
            Console.WriteLine("rgbaBytes " + imgOut.Data.Length);
            return(imgOut);

            // using (var image = Image.Load<Rgba32>(imageName, out format))
            // {
            //     Console.WriteLine(image.Width + " " + image.Height);
            //     // using (var ms = new MemoryStream())
            //     // {
            //     //     image.Save(ms, format);
            //     //     var buff = ms.ToArray();
            //     //     Console.WriteLine(format);
            //     //     Console.WriteLine(buff.Length);
            //     // }
            //     return image;
            // }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> UploadImage(IFormFile file, [FromForm] string name, [FromForm] string tags)
        {
            if (file == null)
            {
                file = Request.Form.Files[0];
            }
            ImageOutput output = new ImageOutput();

            if (file != null)
            {
                if (file.Length > 0)
                {
                    //验证是否是图片
                    if (ImageValidation.IsCheck(file))
                    {
                        ImageInput input = new ImageInput();
                        input.File = file;
                        input.Name = name;
                        input.Tags = tags;
                        ImageHandleService handleService = new ImageHandleService();
                        //处理图片
                        output = await handleService.Processing(input, Request);

                        return(Ok(output));
                    }
                }
            }
            return(BadRequest("图片上传失败!"));
        }
        public static string SaveImage(Image img)
        {
            if (img != null)
            {
                return(ImageOutput.SaveWithDialog(img));
            }

            return(string.Empty);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Place the bitmap as HTML on the clipboard
        /// </summary>
        /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
        /// <param name="surface">ISurface</param>
        public static void SetAsHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface)
        {
            var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
            // This file is automatically deleted when Greenshot exits.
            var filename = ImageOutput.SaveNamedTmpFile(surface, surface.CaptureDetails, pngOutputSettings);
            // Set the PNG stream
            var htmlText = GenerateHtmlString(new NativeSize(surface.Width, surface.Height), filename);

            clipboardAccessToken.SetAsHtml(htmlText);
        }
        private void CopyMainImages(IEnumerable <Entity> entities, string inputPath, string outputPath)
        {
            //build the mod input list
            var inputDirectories = StellarisDirectoryHelper
                                   .CreateCombinedList(StellarisDirectoryHelper, modDirectoryHelpers, Last)
                                   .Select(x => Path.Combine(x.Icons, inputPath)).ToList();

            // tech images
            ImageOutput.TransformAndOutputImages(inputDirectories, Path.Combine(outputRoot, outputPath), entities);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Place the bitmap on the clipboard
 /// </summary>
 /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
 /// <param name="surface">ISurface</param>
 /// <param name="outputSettings">SurfaceOutputSettings specifying how to output the surface</param>
 public static void SetAsBitmap(this IClipboardAccessToken clipboardAccessToken, ISurface surface, SurfaceOutputSettings outputSettings)
 {
     using (var bitmapStream = new MemoryStream())
     {
         ImageOutput.SaveToStream(surface, bitmapStream, outputSettings);
         bitmapStream.Seek(0, SeekOrigin.Begin);
         // Set the stream
         var clipboardFormat = ClipboardFormatExtensions.MapFormatToId(outputSettings.Format.ToString().ToUpperInvariant());
         clipboardAccessToken.SetAsStream(clipboardFormat, bitmapStream);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Place the bitmap as embedded HTML on the clipboard
 /// </summary>
 /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
 /// <param name="surface">ISurface</param>
 public static void SetAsEmbeddedHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface)
 {
     using (var pngStream = new MemoryStream())
     {
         var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
         ImageOutput.SaveToStream(surface, pngStream, pngOutputSettings);
         pngStream.Seek(0, SeekOrigin.Begin);
         // Set the PNG stream
         var htmlText = GenerateHtmlDataUrlString(new NativeSize(surface.Width, surface.Height), pngStream);
         clipboardAccessToken.SetAsHtml(htmlText);
     }
 }
 void SaveToolStripMenuItemClick(object sender, System.EventArgs e)
 {
     try
     {
         ImageOutput.Save(surface.GetImageForExport(), lastSaveFullPath);
         updateStatusLabel(lang.GetString("editor_imagesaved").Replace("%storagelocation%", lastSaveFullPath), fileSavedStatusContextMenu);
     }
     catch (System.Runtime.InteropServices.ExternalException)
     {
         MessageBox.Show(lang.GetString("error_nowriteaccess").Replace("%path%", lastSaveFullPath).Replace(@"\\", @"\"), lang.GetString("error"));
     }
 }
Ejemplo n.º 16
0
        protected override void EndRecording(RecordingSession session)
        {
            // Restore the asyncShaderCompilation setting
            EditorSettings.asyncShaderCompilation = m_asyncShaderCompileSetting;
#if OIIO_AVAILABLE
            if (m_imgOutput != null)
            {
                ImageOutput.destroy(m_imgOutput);
            }
#endif
            base.EndRecording(session);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Place the bitmap on the clipboard as DIB
 /// </summary>
 /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
 /// <param name="surface">ISurface</param>
 public static void SetAsDeviceIndependendBitmap(this IClipboardAccessToken clipboardAccessToken, ISurface surface)
 {
     using (var bitmapStream = new MemoryStream())
     {
         ImageOutput.SaveToStream(surface, bitmapStream, new SurfaceOutputSettings {
             Format = OutputFormats.bmp
         });
         bitmapStream.Seek(Marshal.SizeOf(typeof(BitmapFileHeader)), SeekOrigin.Begin);
         // Set the stream
         clipboardAccessToken.SetAsStream(StandardClipboardFormats.DeviceIndependentBitmap, bitmapStream);
     }
 }
 void CopyImageToClipboardToolStripMenuItemClick(object sender, System.EventArgs e)
 {
     try
     {
         ImageOutput.PrepareClipboardObject();
         ImageOutput.CopyToClipboard(surface.GetImageForExport());
         updateStatusLabel(lang.GetString("editor_storedtoclipboard"));
     }
     catch (Exception)
     {
         updateStatusLabel(lang.GetString("editor_clipboardfailed"));
     }
 }
 void SaveAsToolStripMenuItemClick(object sender, System.EventArgs e)
 {
     lastSaveFullPath = ImageOutput.SaveWithDialog(surface.GetImageForExport());
     if (lastSaveFullPath != null)
     {
         SetImagePath(lastSaveFullPath);
         updateStatusLabel(lang.GetString("editor_imagesaved").Replace("%storagelocation%", lastSaveFullPath), fileSavedStatusContextMenu);
     }
     else
     {
         clearStatusLabel();
     }
 }
Ejemplo n.º 20
0
        public void Run()
        {
            Renderer renderer = new Renderer(new OrthoRenderManager(new Math.Vector3f(0, 0, 1), width, height), new PhongDirectContributionModel());

            Scene scene = new Scene();
            scene.AddRenderObject(new Sphere(new Math.Vector3f(320, 320, 650), 150, new Color(1, 0, 1)));
            scene.AddRenderObject(new Sphere(new Math.Vector3f(320, 500, 800), 150, new Color(1, 0, 1)));
            OutputData data = renderer.RenderScene(scene);

            ImageOutput imageOut = new ImageOutput(width, height, data);

            imageOut.WriteOutput(@"C:\users\Ethan\Desktop\RayTraceSceneTest.png");
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Shutdown / cleanup
        /// </summary>
        public void Exit()
        {
            Log.Info().WriteLine("Exit: " + EnvironmentInfo.EnvironmentToString(false));

            ImageOutput.RemoveTmpFiles();

            // make the icon invisible otherwise it stays even after exit!!
            if (notifyIcon != null)
            {
                notifyIcon.Visible = false;
                notifyIcon.Dispose();
                notifyIcon = null;
            }
        }
Ejemplo n.º 22
0
 public static void ExportToPage(ISurface surfaceToUpload, OneNotePage page)
 {
     using (MemoryStream pngStream = new MemoryStream()) {
         SurfaceOutputSettings pngOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false);
         ImageOutput.SaveToStream(surfaceToUpload, pngStream, pngOutputSettings);
         string base64String   = Convert.ToBase64String(pngStream.GetBuffer());
         string imageXmlStr    = string.Format(XML_IMAGE_CONTENT, base64String, surfaceToUpload.Image.Width, surfaceToUpload.Image.Height);
         string pageChangesXml = string.Format(XML_OUTLINE, new object[] { imageXmlStr, page.PageID, ONENOTE_NAMESPACE_2010, page.PageName });
         using (IOneNoteApplication oneNoteApplication = COMWrapper.GetOrCreateInstance <IOneNoteApplication>()) {
             LOG.InfoFormat("Sending XML: {0}", pageChangesXml);
             oneNoteApplication.UpdatePageContent(pageChangesXml, DateTime.MinValue, XMLSchema.xs2010, false);
         }
     }
 }
Ejemplo n.º 23
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);
            // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
            var savedTo = ImageOutput.SaveWithDialog(surface, captureDetails);

            if (savedTo != null)
            {
                exportInformation.ExportMade            = true;
                exportInformation.Filepath              = savedTo;
                captureDetails.Filename                 = savedTo;
                _coreConfiguration.OutputFileAsFullpath = savedTo;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 24
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();


            if (presetCommand != null)
            {
                bool   runInBackground = presetCommand.RunInBackground;
                string fullPath        = captureDetails.Filename;
                if (fullPath == null)
                {
                    fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
                }

                string output = null;
                if (runInBackground)
                {
                    Thread commandThread = new Thread(delegate() {
                        CallExternalCommand(presetCommand, fullPath, out output);
                    });
                    commandThread.Name         = "Running " + presetCommand;
                    commandThread.IsBackground = true;
                    commandThread.Start();
                    exportInformation.ExportMade = true;
                }
                else
                {
                    try {
                        if (CallExternalCommand(presetCommand, fullPath, out output) == 0)
                        {
                            exportInformation.ExportMade = true;
                        }
                        else
                        {
                            exportInformation.ErrorMessage = output;
                        }
                    } catch (Exception ex) {
                        exportInformation.ErrorMessage = ex.Message;
                    }
                }

                //exportInformation.Uri = "file://" + fullPath;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        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);
        }
Ejemplo n.º 26
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            string            savedTo           = null;

            // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
            savedTo = ImageOutput.SaveWithDialog(surface, captureDetails);
            if (savedTo != null)
            {
                exportInformation.ExportMade = true;
                exportInformation.Filepath   = savedTo;
                captureDetails.Filename      = savedTo;
                conf.OutputFileAsFullpath    = savedTo;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 27
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            CoreConfiguration     config            = IniConfig.GetIniSection <CoreConfiguration>();
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();

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

            using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
                ImageOutput.SaveToStream(surface, stream, outputSettings);
            }
            exportInformation.Filepath   = filePath;
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        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);
        }
Ejemplo n.º 29
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(Designation, Description);
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();

            outputSettings.PreventGreenshotFormat();

            if (_presetCommand != null)
            {
                if (!config.RunInbackground.ContainsKey(_presetCommand))
                {
                    config.RunInbackground.Add(_presetCommand, true);
                }
                bool   runInBackground = config.RunInbackground[_presetCommand];
                string fullPath        = captureDetails.Filename;
                if (fullPath == null)
                {
                    fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
                }

                string output;
                string error;
                if (runInBackground)
                {
                    Thread commandThread = new Thread(delegate()
                    {
                        CallExternalCommand(exportInformation, fullPath, out output, out error);
                        ProcessExport(exportInformation, surface);
                    })
                    {
                        Name         = "Running " + _presetCommand,
                        IsBackground = true
                    };
                    commandThread.SetApartmentState(ApartmentState.STA);
                    commandThread.Start();
                    exportInformation.ExportMade = true;
                }
                else
                {
                    CallExternalCommand(exportInformation, fullPath, out output, out error);
                    ProcessExport(exportInformation, surface);
                }
            }
            return(exportInformation);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Upload the capture to qiniu cloud
        /// </summary>
        /// <param name="captureDetails"></param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="albumPath">Path to the album</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 = _config.ImageNamePrefix + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + _config.UploadFormat.ToString().ToLower();
                Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails));

                string path = Directory.GetCurrentDirectory();

                string fullPath = Path.Combine(path, filename);

                // public static void Save(ISurface surface, string fullPath, bool allowOverwrite, SurfaceOutputSettings outputSettings, bool copyPathToClipboard)
                // Run upload in the background
                MemoryStream streamoutput = new MemoryStream();
                ImageOutput.SaveToStream(surfaceToUpload, streamoutput, outputSettings);
                new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("qiniu", LangKey.communication_wait),
                                                 delegate
                {
                    HttpResult result = QiniuUtils.UploadFile(streamoutput, filename);
                }
                                                 );
                // This causes an exeption if the upload failed :)
                //Log.DebugFormat("Uploaded to qiniu page: " + qiniuInfo.Page);

                uploadUrl = _config.DefaultDomain + filename;

                string markdownURL = "![](" + uploadUrl + ")";


                Clipboard.SetText(markdownURL);



                return(true);
            }
            catch (Exception e)
            {
                Log.Error(e);
                MessageBox.Show(Language.GetString("qiniu", LangKey.upload_failure) + " " + e.Message);
            }
            uploadUrl = null;
            return(false);
        }
Ejemplo n.º 31
0
        protected override bool BeginRecording(RecordingSession session)
        {
            if (!base.BeginRecording(session))
            {
                return(false);
            }

            // Save the async compile shader setting to restore it at the end of recording
            m_asyncShaderCompileSetting = EditorSettings.asyncShaderCompilation;
            // Disable async compile shader setting when recording
            EditorSettings.asyncShaderCompilation = false;

            Settings.FileNameGenerator.CreateDirectory(session);
#if OIIO_AVAILABLE
            m_imgOutput = ImageOutput.create("dummy." + m_Settings.extension);
#endif
            return(true);
        }