private void HandleCapture()
        {
            // Flag to see if the image was "exported" so the FileEditor doesn't
            // ask to save the file as long as nothing is done.
            bool outputMade = false;

            // Make sure the user sees that the capture is made
            if (capture.CaptureDetails.CaptureMode == CaptureMode.File || capture.CaptureDetails.CaptureMode == CaptureMode.Clipboard)
            {
                // Maybe not "made" but the original is still there... somehow
                outputMade = true;
            }
            else
            {
                DoCaptureFeedback();
            }

            LOG.Debug("A capture of: " + capture.CaptureDetails.Title);

            // check if someone has passed a destination
            if (capture.CaptureDetails.CaptureDestinations == null || capture.CaptureDetails.CaptureDestinations.Count == 0)
            {
                AddConfiguredDestination();
            }

            // Create Surface with capture, this way elements can be added automatically (like the mouse cursor)
            Surface surface = new Surface(capture);

            surface.Modified = !outputMade;

            // Let the processors do their job
            foreach (IProcessor processor in ProcessorHelper.GetAllProcessors())
            {
                if (processor.isActive)
                {
                    LOG.InfoFormat("Calling processor {0}", processor.Description);
                    processor.ProcessCapture(surface, capture.CaptureDetails);
                }
            }

            // As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory)
            capture.Image = null;

            // Get CaptureDetails as we need it even after the capture is disposed
            ICaptureDetails captureDetails    = capture.CaptureDetails;
            bool            canDisposeSurface = true;

            if (captureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION))
            {
                DestinationHelper.ExportCapture(false, Destinations.PickerDestination.DESIGNATION, surface, captureDetails);
                captureDetails.CaptureDestinations.Clear();
                canDisposeSurface = false;
            }

            // Disable capturing
            captureMode = CaptureMode.None;
            // Dispose the capture, we don't need it anymore (the surface copied all information and we got the title (if any)).
            capture.Dispose();
            capture = null;

            int destinationCount = captureDetails.CaptureDestinations.Count;

            if (destinationCount > 0)
            {
                // Flag to detect if we need to create a temp file for the email
                // or use the file that was written
                foreach (IDestination destination in captureDetails.CaptureDestinations)
                {
                    if (PickerDestination.DESIGNATION.Equals(destination.Designation))
                    {
                        continue;
                    }
                    LOG.InfoFormat("Calling destination {0}", destination.Description);

                    bool destinationOk = destination.ExportCapture(false, surface, captureDetails);
                    if (Destinations.EditorDestination.DESIGNATION.Equals(destination.Designation) && destinationOk)
                    {
                        canDisposeSurface = false;
                    }
                }
            }
            if (canDisposeSurface)
            {
                surface.Dispose();
            }
        }
Esempio n. 2
0
        private void HandleCapture()
        {
            // Flag to see if the image was "exported" so the FileEditor doesn't
            // ask to save the file as long as nothing is done.
            bool outputMade = false;

            // Make sure the user sees that the capture is made
            if (_capture.CaptureDetails.CaptureMode == CaptureMode.File || _capture.CaptureDetails.CaptureMode == CaptureMode.Clipboard)
            {
                // Maybe not "made" but the original is still there... somehow
                outputMade = true;
            }
            else
            {
                // Make sure the resolution is set correctly!
                if (_capture.CaptureDetails != null)
                {
                    ((Bitmap)_capture.Image)?.SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY);
                }
                DoCaptureFeedback();
            }

            Log.Debug("A capture of: " + _capture.CaptureDetails.Title);

            // check if someone has passed a destination
            if (_capture.CaptureDetails.CaptureDestinations == null || _capture.CaptureDetails.CaptureDestinations.Count == 0)
            {
                AddConfiguredDestination();
            }

            // Create Surface with capture, this way elements can be added automatically (like the mouse cursor)
            Surface surface = new Surface(_capture)
            {
                Modified = !outputMade
            };

            // Register notify events if this is wanted
            if (CoreConfig.ShowTrayNotification && !CoreConfig.HideTrayicon)
            {
                surface.SurfaceMessage += SurfaceMessageReceived;
            }
            // Let the processors do their job
            foreach (IProcessor processor in ProcessorHelper.GetAllProcessors())
            {
                if (processor.isActive)
                {
                    Log.InfoFormat("Calling processor {0}", processor.Description);
                    processor.ProcessCapture(surface, _capture.CaptureDetails);
                }
            }

            // As the surfaces copies the reference to the image, make sure the image is not being disposed (a trick to save memory)
            _capture.Image = null;

            // Get CaptureDetails as we need it even after the capture is disposed
            ICaptureDetails captureDetails    = _capture.CaptureDetails;
            bool            canDisposeSurface = true;

            if (captureDetails.HasDestination(PickerDestination.DESIGNATION))
            {
                DestinationHelper.ExportCapture(false, PickerDestination.DESIGNATION, surface, captureDetails);
                captureDetails.CaptureDestinations.Clear();
                canDisposeSurface = false;
            }

            // Disable capturing
            _captureMode = CaptureMode.None;
            // Dispose the capture, we don't need it anymore (the surface copied all information and we got the title (if any)).
            _capture.Dispose();
            _capture = null;

            int destinationCount = captureDetails.CaptureDestinations.Count;

            if (destinationCount > 0)
            {
                // Flag to detect if we need to create a temp file for the email
                // or use the file that was written
                foreach (IDestination destination in captureDetails.CaptureDestinations)
                {
                    if (PickerDestination.DESIGNATION.Equals(destination.Designation))
                    {
                        continue;
                    }
                    Log.InfoFormat("Calling destination {0}", destination.Description);

                    ExportInformation exportInformation = destination.ExportCapture(false, surface, captureDetails);
                    if (EditorDestination.DESIGNATION.Equals(destination.Designation) && exportInformation.ExportMade)
                    {
                        canDisposeSurface = false;
                    }
                }
            }
            if (canDisposeSurface)
            {
                surface.Dispose();
            }
        }