private void CaptureWithFeedback()
        {
            using (CaptureForm captureForm = new CaptureForm(capture, windows))
            {
                DialogResult result = captureForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    selectedCaptureWindow = captureForm.SelectedCaptureWindow;
                    captureRect           = captureForm.CaptureRectangle;
                    // Get title
                    if (selectedCaptureWindow != null)
                    {
                        capture.CaptureDetails.Title = selectedCaptureWindow.Text;
                    }

                    // Experimental code
                    if (capture.CaptureDetails.CaptureMode == CaptureMode.Video)
                    {
                        if (captureForm.UsedCaptureMode == CaptureMode.Window)
                        {
                            screenCapture = new ScreenCaptureHelper(selectedCaptureWindow);
                        }
                        else if (captureForm.UsedCaptureMode == CaptureMode.Region)
                        {
                            screenCapture = new ScreenCaptureHelper(captureRect);
                        }
                        if (screenCapture != null)
                        {
                            screenCapture.RecordMouse = capture.CursorVisible;
                            if (screenCapture.Start(25))
                            {
                                return;
                            }
                            // User clicked cancel or a problem occured
                            screenCapture.Stop();
                            screenCapture = null;
                            return;
                        }
                    }

                    if (captureRect.Height > 0 && captureRect.Width > 0)
                    {
                        if (windowDetailsThread != null)
                        {
                            windowDetailsThread.Join();
                        }
                        // Take the captureRect, this already is specified as bitmap coordinates
                        capture.Crop(captureRect);
                        // save for re-capturing later and show recapture context menu option
                        RuntimeConfig.LastCapturedRegion = captureRect;
                        HandleCapture();
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Make Capture with specified destinations
        /// </summary>
        /// <param name="mode">CaptureMode</param>
        /// <param name="captureMouseCursor">bool false if the mouse should not be captured, true if the configuration should be checked</param>
        /// <param name="captureDestinations">List<CaptureDestination> with destinations</param>
        private void MakeCapture(CaptureMode mode, bool captureMouseCursor, ICapture newCapture)
        {
            if (screenCapture != null)
             {
            screenCapture.Stop();
            screenCapture = null;
            return;
             }
             if (captureMode != CaptureMode.None)
             {
            LOG.Warn(String.Format("Capture started while capturing, current mode = {0} new capture was {1}.", captureMode, mode));
            return;
             }
             else
             {
            LOG.Debug(String.Format("MakeCapture({0}, {1})", mode, captureMouseCursor));
             }
             captureMode = mode;

             PrepareForCaptureWithFeedback(mode);

             // cleanup the previos information if there is still any
             if (capture != null)
             {
            LOG.Debug("Capture wasn't disposed yet, this would suggest a leak");
            capture.Dispose();
            capture = null;
             }
             // Use the supplied Capture information
             capture = newCapture;
             if (capture == null)
             {
            capture = new Capture();
             }
             capture.CaptureDetails.CaptureMode = mode;

             // Workaround for proble with DPI retrieval, the FromHwnd activates the window...
             WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
             // Workaround for changed DPI settings in Windows 7
             using (Graphics graphics = Graphics.FromHwnd(this.Handle))
             {
            capture.CaptureDetails.DpiX = graphics.DpiX;
            capture.CaptureDetails.DpiY = graphics.DpiY;
             }
             if (previouslyActiveWindow != null)
             {
            // Set previouslyActiveWindow as foreground window
            previouslyActiveWindow.ToForeground();
             }

             // Delay for the Context menu
             if (conf.CaptureDelay > 0)
             {
            System.Threading.Thread.Sleep(conf.CaptureDelay);
             }
             else
             {
            conf.CaptureDelay = 0;
             }

             // Allways capture Mousecursor, only show when needed
             capture = WindowCapture.CaptureCursor(capture);
             capture.CursorVisible = false;
             // Check if needed
             if (captureMouseCursor && mode != CaptureMode.Clipboard && mode != CaptureMode.File)
             {
            capture.CursorVisible = conf.CaptureMousepointer;
             }

             switch (mode)
             {
            case CaptureMode.Window:
               capture = WindowCapture.CaptureScreen(capture);
               capture.CaptureDetails.AddMetaData("source", "Screen");
               CaptureWithFeedback();
               break;
            case CaptureMode.ActiveWindow:
               if (CaptureActiveWindow())
               {
                  // Capture worked, offset mouse according to screen bounds and capture location
                  capture.MoveMouseLocation(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
                  capture.CaptureDetails.AddMetaData("source", "Window");
               }
               else
               {
                  captureMode = CaptureMode.FullScreen;
                  capture = WindowCapture.CaptureScreen(capture);
                  capture.CaptureDetails.AddMetaData("source", "Screen");
                  capture.CaptureDetails.Title = "Screen";
               }
               // Make sure capturing is stopped at any cost
               StopCapturing(false);
               HandleCapture();
               break;
            case CaptureMode.IE:
               if (IECaptureHelper.CaptureIE(capture) != null)
               {
                  capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
                  HandleCapture();
               }
               else
               {
                  StopCapturing(true);
               }
               break;
            case CaptureMode.FullScreen:
               capture = WindowCapture.CaptureScreen(capture);
               HandleCapture();
               break;
            case CaptureMode.Clipboard:
               Image clipboardImage = null;
               string text = "Clipboard";
               if (ClipboardHelper.ContainsImage())
               {
                  clipboardImage = ClipboardHelper.GetImage();
               }
               if (clipboardImage != null)
               {
                  if (capture != null)
                  {
                     capture.Image = clipboardImage;
                  }
                  else
                  {
                     capture = new Capture(clipboardImage);
                  }
                  string title = ClipboardHelper.GetText();
                  if (title == null || title.Trim().Length == 0)
                  {
                     title = "Clipboard";
                  }
                  capture.CaptureDetails.Title = title;
                  capture.CaptureDetails.AddMetaData("source", "Clipboard");
                  // Force Editor
                  capture.CaptureDetails.AddDestination(CaptureDestination.Editor);
                  HandleCapture();
               }
               else
               {
                  MessageBox.Show("Couldn't create bitmap from : " + text);
               }
               break;
            case CaptureMode.File:
               Bitmap fileBitmap = null;
               bool isSaveSupported = true;
               string filename = capture.CaptureDetails.Filename;
               if (!string.IsNullOrEmpty(filename))
               {
                  try
                  {
                     fileBitmap = ImageHelper.LoadBitmap(filename, ref isSaveSupported);
                  }
                  catch (Exception e)
                  {
                     LOG.Error(e.Message, e);
                     MessageBox.Show(lang.GetFormattedString(LangKey.error_openfile, filename));
                  }
               }
               if (fileBitmap != null)
               {
                  capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
                  capture.CaptureDetails.AddMetaData("file", filename);
                  capture.CaptureDetails.AddMetaData("source", "file");
                  if (capture != null)
                  {
                     capture.Image = fileBitmap;
                  }
                  else
                  {
                     capture = new Capture(fileBitmap);
                  }
                  // Force Editor, this is currently the only usefull destination
                  capture.CaptureDetails.AddDestination(CaptureDestination.Editor);
                  if (!isSaveSupported)
                  {
                     // We can't save icon & wmf, don't supply the filename
                     HandleCapture();
                  }
                  else
                  {
                     HandleCapture(filename);
                  }
               }
               else
               {
                  // "semi" Fix for Bug #3430555
                  StopCapturing(true);
               }
               break;
            case CaptureMode.LastRegion:
               if (!RuntimeConfig.LastCapturedRegion.Equals(Rectangle.Empty))
               {
                  capture = WindowCapture.CaptureScreen(capture);
                  capture.Crop(RuntimeConfig.LastCapturedRegion);
                  capture.CaptureDetails.AddMetaData("source", "screen");
                  HandleCapture();
               }
               else
               {
                  // Fix for Bug #3430555
                  StopCapturing(true);
               }
               break;
            case CaptureMode.Region:
               capture = WindowCapture.CaptureScreen(capture);
               capture.CaptureDetails.AddMetaData("source", "screen");
               CaptureWithFeedback();
               break;
            case CaptureMode.Video:
               capture = WindowCapture.CaptureScreen(capture);
               // Set the capturemode to be window
               captureMode = CaptureMode.Window;
               capture.CaptureDetails.AddMetaData("source", "Video");
               CaptureWithFeedback();
               break;
            default:
               LOG.Warn("Unknown capture mode: " + mode);
               break;
             }
        }
Esempio n. 3
0
        /**
           * Finishing the whole Capture with Feedback flow, passing the result on to the HandleCapture
           */
        private void finishCaptureWithFeedback()
        {
            // Get title
             if (selectedCaptureWindow != null)
             {
            if (capture == null)
            {
               capture = new Capture();
            }
            capture.CaptureDetails.Title = selectedCaptureWindow.Text;
             }
             if (capture.CaptureDetails.CaptureMode == CaptureMode.Video)
             {
            if (screenCapture != null)
            {
               screenCapture = null;
            }
            if (captureMode == CaptureMode.Window)
            {
               screenCapture = new ScreenCaptureHelper(selectedCaptureWindow);
            }
            else
            {
               screenCapture = new ScreenCaptureHelper(captureRect);
            }
            screenCapture.RecordMouse = capture.CursorVisible;
            StopCapturing(true);
            screenCapture.Start(10);
             }

             if (captureRect.Height > 0 && captureRect.Width > 0)
             {
            // Take the captureRect, this already is specified as bitmap coordinates
            capture.Crop(captureRect);
            // save for re-capturing later and show recapture context menu option
            RuntimeConfig.LastCapturedRegion = captureRect;

            StopCapturing(false);
            HandleCapture();
             }
        }
        /// <summary>
        /// Make Capture with specified destinations
        /// </summary>
        private void MakeCapture()
        {
            // Experimental code
            if (screenCapture != null)
            {
                screenCapture.Stop();
                screenCapture = null;
                return;
            }

            LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1}", captureMode, captureMouseCursor));
            capture.CaptureDetails.CaptureMode = captureMode;

            // Get the windows details in a seperate thread
            windowDetailsThread = PrepareForCaptureWithFeedback();

            // Add destinations if no-one passed a handler
            if (capture.CaptureDetails.CaptureDestinations == null || capture.CaptureDetails.CaptureDestinations.Count == 0)
            {
                AddConfiguredDestination();
            }

            // Workaround for proble with DPI retrieval, the FromHwnd activates the window...
            WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();

            // Workaround for changed DPI settings in Windows 7
            using (Graphics graphics = Graphics.FromHwnd(MainForm.instance.Handle))
            {
                capture.CaptureDetails.DpiX = graphics.DpiX;
                capture.CaptureDetails.DpiY = graphics.DpiY;
            }
            if (previouslyActiveWindow != null)
            {
                // Set previouslyActiveWindow as foreground window
                previouslyActiveWindow.ToForeground();
            }

            // Delay for the Context menu
            if (conf.CaptureDelay > 0)
            {
                System.Threading.Thread.Sleep(conf.CaptureDelay);
            }
            else
            {
                conf.CaptureDelay = 0;
            }

            // Allways capture Mousecursor, only show when needed
            capture = WindowCapture.CaptureCursor(capture);
            capture.CursorVisible = false;
            // Check if needed
            if (captureMouseCursor && captureMode != CaptureMode.Clipboard && captureMode != CaptureMode.File)
            {
                capture.CursorVisible = conf.CaptureMousepointer;
            }

            switch (captureMode)
            {
            case CaptureMode.Window:
                capture = WindowCapture.CaptureScreen(capture);
                capture.CaptureDetails.AddMetaData("source", "Screen");
                CaptureWithFeedback();
                break;

            case CaptureMode.ActiveWindow:
                if (CaptureActiveWindow())
                {
                    if (windowDetailsThread != null)
                    {
                        windowDetailsThread.Join();
                    }
                    // Capture worked, offset mouse according to screen bounds and capture location
                    capture.MoveMouseLocation(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
                    capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
                    capture.CaptureDetails.AddMetaData("source", "Window");
                }
                else
                {
                    captureMode = CaptureMode.FullScreen;
                    capture     = WindowCapture.CaptureScreen(capture);
                    capture.CaptureDetails.AddMetaData("source", "Screen");
                    capture.CaptureDetails.Title = "Screen";
                }
                HandleCapture();
                break;

            case CaptureMode.IE:
                if (IECaptureHelper.CaptureIE(capture) != null)
                {
                    capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
                    HandleCapture();
                }
                break;

            case CaptureMode.FullScreen:
                // Check how we need to capture the screen
                bool captureTaken = false;
                switch (screenCaptureMode)
                {
                case ScreenCaptureMode.Auto:
                    Point mouseLocation = WindowCapture.GetCursorLocation();
                    foreach (Screen screen in Screen.AllScreens)
                    {
                        if (screen.Bounds.Contains(mouseLocation))
                        {
                            capture      = WindowCapture.CaptureRectangle(capture, screen.Bounds);
                            captureTaken = true;
                            break;
                        }
                    }
                    break;

                case ScreenCaptureMode.Fixed:
                    if (conf.ScreenToCapture > 0 && conf.ScreenToCapture <= Screen.AllScreens.Length)
                    {
                        capture      = WindowCapture.CaptureRectangle(capture, Screen.AllScreens[conf.ScreenToCapture].Bounds);
                        captureTaken = true;
                    }
                    break;

                case ScreenCaptureMode.FullScreen:
                    // Do nothing, we take the fullscreen capture automatically
                    break;
                }
                if (!captureTaken)
                {
                    capture = WindowCapture.CaptureScreen(capture);
                }
                HandleCapture();
                break;

            case CaptureMode.Clipboard:
                Image  clipboardImage = null;
                string text           = "Clipboard";
                if (ClipboardHelper.ContainsImage())
                {
                    clipboardImage = ClipboardHelper.GetImage();
                }
                if (clipboardImage != null)
                {
                    if (capture != null)
                    {
                        capture.Image = clipboardImage;
                    }
                    else
                    {
                        capture = new Capture(clipboardImage);
                    }
                    string title = ClipboardHelper.GetText();
                    if (title == null || title.Trim().Length == 0)
                    {
                        title = "Clipboard";
                    }
                    capture.CaptureDetails.Title = title;
                    capture.CaptureDetails.AddMetaData("source", "Clipboard");
                    // Force Editor, keep picker
                    if (capture.CaptureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION))
                    {
                        capture.CaptureDetails.ClearDestinations();
                        capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.EditorDestination.DESIGNATION));
                        capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.PickerDestination.DESIGNATION));
                    }
                    else
                    {
                        capture.CaptureDetails.ClearDestinations();
                        capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.EditorDestination.DESIGNATION));
                    }
                    HandleCapture();
                }
                else
                {
                    MessageBox.Show("Couldn't create bitmap from : " + text);
                }
                break;

            case CaptureMode.File:
                Bitmap fileBitmap = null;
                string filename   = capture.CaptureDetails.Filename;
                if (!string.IsNullOrEmpty(filename))
                {
                    try
                    {
                        fileBitmap = ImageHelper.LoadBitmap(filename);
                    }
                    catch (Exception e)
                    {
                        LOG.Error(e.Message, e);
                        MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
                    }
                }
                if (fileBitmap != null)
                {
                    capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
                    capture.CaptureDetails.AddMetaData("file", filename);
                    capture.CaptureDetails.AddMetaData("source", "file");
                    if (capture != null)
                    {
                        capture.Image = fileBitmap;
                    }
                    else
                    {
                        capture = new Capture(fileBitmap);
                    }
                    // Force Editor, keep picker, this is currently the only usefull destination
                    if (capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION))
                    {
                        capture.CaptureDetails.ClearDestinations();
                        capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                        capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
                    }
                    else
                    {
                        capture.CaptureDetails.ClearDestinations();
                        capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                    }
                    HandleCapture();
                }
                break;

            case CaptureMode.LastRegion:
                if (!RuntimeConfig.LastCapturedRegion.IsEmpty)
                {
                    capture = WindowCapture.CaptureRectangle(capture, RuntimeConfig.LastCapturedRegion);
                    if (windowDetailsThread != null)
                    {
                        windowDetailsThread.Join();
                    }
                    capture.CaptureDetails.AddMetaData("source", "screen");
                    HandleCapture();
                }
                break;

            case CaptureMode.Region:
                // Check if a region is pre-supplied!
                if (Rectangle.Empty.Equals(captureRect))
                {
                    capture = WindowCapture.CaptureScreen(capture);
                    capture.CaptureDetails.AddMetaData("source", "screen");
                    CaptureWithFeedback();
                }
                else
                {
                    capture = WindowCapture.CaptureRectangle(capture, captureRect);
                    capture.CaptureDetails.AddMetaData("source", "screen");
                    HandleCapture();
                }
                break;

            case CaptureMode.Video:
                capture = WindowCapture.CaptureScreen(capture);
                // Set the capturemode to be window
                captureMode = CaptureMode.Window;
                capture.CaptureDetails.AddMetaData("source", "Video");
                CaptureWithFeedback();
                break;

            default:
                LOG.Warn("Unknown capture mode: " + captureMode);
                break;
            }
            if (windowDetailsThread != null)
            {
                windowDetailsThread.Join();
            }
            if (capture != null)
            {
                LOG.Debug("Disposing capture");
                capture.Dispose();
            }
        }
        /// <summary>
        /// Make Capture with specified destinations
        /// </summary>
        private void MakeCapture()
        {
            // Experimental code
            if (screenCapture != null)
            {
                screenCapture.Stop();
                screenCapture = null;
                return;
            }

            LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1}", captureMode, captureMouseCursor));
            capture.CaptureDetails.CaptureMode = captureMode;

            // Get the windows details in a seperate thread
            windowDetailsThread = PrepareForCaptureWithFeedback();

            // Add destinations if no-one passed a handler
            if (capture.CaptureDetails.CaptureDestinations == null || capture.CaptureDetails.CaptureDestinations.Count == 0)
            {
                AddConfiguredDestination();
            }

            // Workaround for proble with DPI retrieval, the FromHwnd activates the window...
            WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
            // Workaround for changed DPI settings in Windows 7
            using (Graphics graphics = Graphics.FromHwnd(MainForm.instance.Handle))
            {
                capture.CaptureDetails.DpiX = graphics.DpiX;
                capture.CaptureDetails.DpiY = graphics.DpiY;
            }
            if (previouslyActiveWindow != null)
            {
                // Set previouslyActiveWindow as foreground window
                previouslyActiveWindow.ToForeground();
            }

            // Delay for the Context menu
            if (conf.CaptureDelay > 0)
            {
                System.Threading.Thread.Sleep(conf.CaptureDelay);
            }
            else
            {
                conf.CaptureDelay = 0;
            }

            // Allways capture Mousecursor, only show when needed
            capture = WindowCapture.CaptureCursor(capture);
            capture.CursorVisible = false;
            // Check if needed
            if (captureMouseCursor && captureMode != CaptureMode.Clipboard && captureMode != CaptureMode.File)
            {
                capture.CursorVisible = conf.CaptureMousepointer;
            }

            switch (captureMode)
            {
                case CaptureMode.Window:
                    capture = WindowCapture.CaptureScreen(capture);
                    capture.CaptureDetails.AddMetaData("source", "Screen");
                    CaptureWithFeedback();
                    break;
                case CaptureMode.ActiveWindow:
                    if (CaptureActiveWindow())
                    {
                        if (windowDetailsThread != null)
                        {
                            windowDetailsThread.Join();
                        }
                        // Capture worked, offset mouse according to screen bounds and capture location
                        capture.MoveMouseLocation(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
                        capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
                        capture.CaptureDetails.AddMetaData("source", "Window");
                    }
                    else
                    {
                        captureMode = CaptureMode.FullScreen;
                        capture = WindowCapture.CaptureScreen(capture);
                        capture.CaptureDetails.AddMetaData("source", "Screen");
                        capture.CaptureDetails.Title = "Screen";
                    }
                    HandleCapture();
                    break;
                case CaptureMode.IE:
                    if (IECaptureHelper.CaptureIE(capture) != null)
                    {
                        capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
                        HandleCapture();
                    }
                    break;
                case CaptureMode.FullScreen:
                    // Check how we need to capture the screen
                    bool captureTaken = false;
                    switch (screenCaptureMode)
                    {
                        case ScreenCaptureMode.Auto:
                            Point mouseLocation = WindowCapture.GetCursorLocation();
                            foreach (Screen screen in Screen.AllScreens)
                            {
                                if (screen.Bounds.Contains(mouseLocation))
                                {
                                    capture = WindowCapture.CaptureRectangle(capture, screen.Bounds);
                                    captureTaken = true;
                                    break;
                                }
                            }
                            break;
                        case ScreenCaptureMode.Fixed:
                            if (conf.ScreenToCapture > 0 && conf.ScreenToCapture <= Screen.AllScreens.Length)
                            {
                                capture = WindowCapture.CaptureRectangle(capture, Screen.AllScreens[conf.ScreenToCapture].Bounds);
                                captureTaken = true;
                            }
                            break;
                        case ScreenCaptureMode.FullScreen:
                            // Do nothing, we take the fullscreen capture automatically
                            break;
                    }
                    if (!captureTaken)
                    {
                        capture = WindowCapture.CaptureScreen(capture);
                    }
                    HandleCapture();
                    break;
                case CaptureMode.Clipboard:
                    Image clipboardImage = null;
                    string text = "Clipboard";
                    if (ClipboardHelper.ContainsImage())
                    {
                        clipboardImage = ClipboardHelper.GetImage();
                    }
                    if (clipboardImage != null)
                    {
                        if (capture != null)
                        {
                            capture.Image = clipboardImage;
                        }
                        else
                        {
                            capture = new Capture(clipboardImage);
                        }
                        string title = ClipboardHelper.GetText();
                        if (title == null || title.Trim().Length == 0)
                        {
                            title = "Clipboard";
                        }
                        capture.CaptureDetails.Title = title;
                        capture.CaptureDetails.AddMetaData("source", "Clipboard");
                        // Force Editor, keep picker
                        if (capture.CaptureDetails.HasDestination(Destinations.PickerDestination.DESIGNATION))
                        {
                            capture.CaptureDetails.ClearDestinations();
                            capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.EditorDestination.DESIGNATION));
                            capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.PickerDestination.DESIGNATION));
                        }
                        else
                        {
                            capture.CaptureDetails.ClearDestinations();
                            capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(Destinations.EditorDestination.DESIGNATION));
                        }
                        HandleCapture();
                    }
                    else
                    {
                        MessageBox.Show("Couldn't create bitmap from : " + text);
                    }
                    break;
                case CaptureMode.File:
                    Bitmap fileBitmap = null;
                    string filename = capture.CaptureDetails.Filename;
                    if (!string.IsNullOrEmpty(filename))
                    {
                        try
                        {
                            fileBitmap = ImageHelper.LoadBitmap(filename);
                        }
                        catch (Exception e)
                        {
                            LOG.Error(e.Message, e);
                            MessageBox.Show(Language.GetFormattedString(LangKey.error_openfile, filename));
                        }
                    }
                    if (fileBitmap != null)
                    {
                        capture.CaptureDetails.Title = Path.GetFileNameWithoutExtension(filename);
                        capture.CaptureDetails.AddMetaData("file", filename);
                        capture.CaptureDetails.AddMetaData("source", "file");
                        if (capture != null)
                        {
                            capture.Image = fileBitmap;
                        }
                        else
                        {
                            capture = new Capture(fileBitmap);
                        }
                        // Force Editor, keep picker, this is currently the only usefull destination
                        if (capture.CaptureDetails.HasDestination(PickerDestination.DESIGNATION))
                        {
                            capture.CaptureDetails.ClearDestinations();
                            capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                            capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(PickerDestination.DESIGNATION));
                        }
                        else
                        {
                            capture.CaptureDetails.ClearDestinations();
                            capture.CaptureDetails.AddDestination(DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
                        }
                        HandleCapture();
                    }
                    break;
                case CaptureMode.LastRegion:
                    if (!RuntimeConfig.LastCapturedRegion.IsEmpty)
                    {
                        capture = WindowCapture.CaptureRectangle(capture, RuntimeConfig.LastCapturedRegion);
                        if (windowDetailsThread != null)
                        {
                            windowDetailsThread.Join();
                        }
                        capture.CaptureDetails.AddMetaData("source", "screen");
                        HandleCapture();
                    }
                    break;
                case CaptureMode.Region:
                    // Check if a region is pre-supplied!
                    if (Rectangle.Empty.Equals(captureRect))
                    {
                        capture = WindowCapture.CaptureScreen(capture);
                        capture.CaptureDetails.AddMetaData("source", "screen");
                        CaptureWithFeedback();
                    }
                    else
                    {
                        capture = WindowCapture.CaptureRectangle(capture, captureRect);
                        capture.CaptureDetails.AddMetaData("source", "screen");
                        HandleCapture();
                    }
                    break;
                case CaptureMode.Video:
                    capture = WindowCapture.CaptureScreen(capture);
                    // Set the capturemode to be window
                    captureMode = CaptureMode.Window;
                    capture.CaptureDetails.AddMetaData("source", "Video");
                    CaptureWithFeedback();
                    break;
                default:
                    LOG.Warn("Unknown capture mode: " + captureMode);
                    break;
            }
            if (windowDetailsThread != null)
            {
                windowDetailsThread.Join();
            }
            if (capture != null)
            {
                LOG.Debug("Disposing capture");
                capture.Dispose();
            }
        }
        private void CaptureWithFeedback()
        {
            using (CaptureForm captureForm = new CaptureForm(capture, windows))
            {
                DialogResult result = captureForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    selectedCaptureWindow = captureForm.SelectedCaptureWindow;
                    captureRect = captureForm.CaptureRectangle;
                    // Get title
                    if (selectedCaptureWindow != null)
                    {
                        capture.CaptureDetails.Title = selectedCaptureWindow.Text;
                    }

                    // Experimental code
                    if (capture.CaptureDetails.CaptureMode == CaptureMode.Video)
                    {
                        if (captureForm.UsedCaptureMode == CaptureMode.Window)
                        {
                            screenCapture = new ScreenCaptureHelper(selectedCaptureWindow);
                        }
                        else if (captureForm.UsedCaptureMode == CaptureMode.Region)
                        {
                            screenCapture = new ScreenCaptureHelper(captureRect);
                        }
                        if (screenCapture != null)
                        {
                            screenCapture.RecordMouse = capture.CursorVisible;
                            if (screenCapture.Start(25))
                            {
                                return;
                            }
                            // User clicked cancel or a problem occured
                            screenCapture.Stop();
                            screenCapture = null;
                            return;
                        }
                    }

                    if (captureRect.Height > 0 && captureRect.Width > 0)
                    {
                        if (windowDetailsThread != null)
                        {
                            windowDetailsThread.Join();
                        }
                        // Take the captureRect, this already is specified as bitmap coordinates
                        capture.Crop(captureRect);
                        // save for re-capturing later and show recapture context menu option
                        RuntimeConfig.LastCapturedRegion = captureRect;
                        HandleCapture();
                    }
                }
            }
        }