Beispiel #1
0
		public static BackgroundForm ShowAndWait(string title, string text) {
			BackgroundForm backgroundForm = new BackgroundForm(title, text);
			// Show form in background thread
			Thread backgroundTask = new Thread (new ThreadStart(backgroundForm.BackgroundShowDialog));
			backgroundForm.Name = "Background form";
			backgroundTask.IsBackground = true;
			backgroundTask.SetApartmentState(ApartmentState.STA);
			backgroundTask.Start();
			return backgroundForm;
		}
        /// <summary>
        /// Here the logic for capturing the IE Content is located
        /// </summary>
        /// <param name="capture">ICapture where the capture needs to be stored</param>
        /// <returns>ICapture with the content (if any)</returns>
        public static ICapture CaptureIE(ICapture capture)
        {
            WindowDetails activeWindow = WindowDetails.GetActiveWindow();

            // Show backgroundform after retrieving the active window..
            BackgroundForm backgroundForm = new BackgroundForm(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
            backgroundForm.Show();
            //BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
            try {
                //Get IHTMLDocument2 for the current active window
                DocumentContainer documentContainer = GetDocument(activeWindow);

                // Nothing found
                if (documentContainer == null) {
                    LOG.Debug("Nothing to capture found");
                    return null;
                }
                LOG.DebugFormat("Window class {0}", documentContainer.ContentWindow.ClassName);
                LOG.DebugFormat("Window location {0}", documentContainer.ContentWindow.Location);

                // The URL is available unter "document2.url" and can be used to enhance the meta-data etc.
                capture.CaptureDetails.AddMetaData("url", documentContainer.Url);

                // bitmap to return
                Bitmap returnBitmap = null;
                try {
                    returnBitmap = capturePage(documentContainer, capture);
                } catch (Exception e) {
                    LOG.Error("Exception found, ignoring and returning nothing! Error was: ", e);
                }

                if (returnBitmap == null) {
                    return null;
                }

                // Store the bitmap for further processing
                capture.Image = returnBitmap;
                // Store the location of the window
                capture.Location = documentContainer.ContentWindow.Location;
                // Store the title of the Page
                if (documentContainer.Name != null) {
                    capture.CaptureDetails.Title = documentContainer.Name;
                } else {
                    capture.CaptureDetails.Title = activeWindow.Text;
                }

                // Only move the mouse to correct for the capture offset
                capture.MoveMouseLocation(-documentContainer.ViewportRectangle.X, -documentContainer.ViewportRectangle.Y);
                // Used to be: capture.MoveMouseLocation(-(capture.Location.X + documentContainer.CaptureOffset.X), -(capture.Location.Y + documentContainer.CaptureOffset.Y));
            } finally {
                // Always close the background form
                backgroundForm.CloseDialog();
            }
            return capture;
        }
Beispiel #3
0
        public static BackgroundForm ShowAndWait(string title, string text)
        {
            BackgroundForm backgroundForm = new BackgroundForm(title, text);
            // Show form in background thread
            Thread backgroundTask = new Thread(new ThreadStart(backgroundForm.BackgroundShowDialog));

            backgroundTask.IsBackground = true;
            backgroundTask.SetApartmentState(ApartmentState.STA);
            backgroundTask.Start();
            return(backgroundForm);
        }
 /// <summary>
 /// Apply a bitmap effect to the surface
 /// </summary>
 /// <param name="effect"></param>
 public void ApplyBitmapEffect(IEffect effect)
 {
     BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait");
     backgroundForm.Show();
     Application.DoEvents();
     try
     {
         Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
         Matrix matrix = new Matrix();
         Image newImage = ImageHelper.ApplyEffect(Image, effect, matrix);
         if (newImage != null)
         {
             // Make sure the elements move according to the offset the effect made the bitmap move
             _elements.Transform(matrix);
             // Make undoable
             MakeUndoable(new SurfaceBackgroundChangeMemento(this, matrix), false);
             SetImage(newImage, false);
             Invalidate();
             if (_surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
             {
                 _surfaceSizeChanged(this, null);
             }
         }
         else
         {
             // clean up matrix, as it hasn't been used in the undo stack.
             matrix.Dispose();
         }
     }
     finally
     {
         // Always close the background form
         backgroundForm.CloseDialog();
     }
 }
Beispiel #5
0
 /// <summary>
 /// Apply a bitmap effect to the surface
 /// </summary>
 /// <param name="effect"></param>
 public void ApplyBitmapEffect(IEffect effect)
 {
     BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait");
     backgroundForm.Show();
     Application.DoEvents();
     try
     {
         Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
         Point offset;
         Image newImage = ImageHelper.ApplyEffect(Image, effect, out offset);
         if (newImage != null)
         {
             // Make sure the elements move according to the offset the effect made the bitmap move
             elements.MoveBy(offset.X, offset.Y);
             // Make undoable
             MakeUndoable(new SurfaceBackgroundChangeMemento(this, offset), false);
             SetImage(newImage, false);
             Invalidate();
             if (surfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size)))
             {
                 surfaceSizeChanged(this, null);
             }
         }
     }
     finally
     {
         // Always close the background form
         backgroundForm.CloseDialog();
     }
 }
        /// <summary>
        /// Apply a bitmap effect to the surface
        /// </summary>
        /// <param name="effect"></param>
        public void ApplyBitmapEffect(Effects effect)
        {
            BackgroundForm backgroundForm = new BackgroundForm("Effect", "Please wait");
            backgroundForm.Show();
            Application.DoEvents();
            try {
                Rectangle imageRectangle = new Rectangle(Point.Empty, Image.Size);
                Bitmap newImage = null;
                Point offset = Point.Empty;
                switch (effect) {
                    case Effects.Shadow:
                        offset = new Point(6, 6);
                        newImage = ImageHelper.CreateShadow((Bitmap)Image, 1f, 7, offset, PixelFormat.Format32bppRgb); //Image.PixelFormat);
                        break;
                    case Effects.TornEdge:
                        offset = new Point(5, 5);
                        using (Bitmap tmpImage = ImageHelper.CreateTornEdge((Bitmap)Image)) {
                            newImage = ImageHelper.CreateShadow(tmpImage, 1f, 6, offset, PixelFormat.Format32bppRgb); //Image.PixelFormat);
                        }
                        break;
                    case Effects.Border:
                        newImage = ImageHelper.CreateBorder((Bitmap)Image, 2, Color.Black, Image.PixelFormat, out offset);
                        break;
                    case Effects.Grayscale:
                        newImage = ImageHelper.CreateGrayscale((Bitmap)Image);
                        break;
                    case Effects.Invert:
                        newImage = ImageHelper.CreateNegative((Bitmap)Image);
                        break;
                    case Effects.RotateClockwise:
                    case Effects.RotateCounterClockwise:
                        MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false);
                        RotateFlipType rotateFlipType = RotateFlipType.Rotate270FlipNone;
                        if (effect == Effects.RotateClockwise) {
                            rotateFlipType = RotateFlipType.Rotate90FlipNone;
                        }
                        foreach (DrawableContainer drawableContainer in elements) {
                            if (drawableContainer.CanRotate) {
                                drawableContainer.Rotate(rotateFlipType);
                            }
                        }
                        newImage = ImageHelper.RotateFlip((Bitmap)Image, rotateFlipType);
                        break;
                }
                // The following was added to correct any unneeded pixels, had the bad effect that sometimes everything was cropped... :(
                //Rectangle autoCropRectangle = ImageHelper.FindAutoCropRectangle(newImage, 0);
                //if (!Size.Empty.Equals(autoCropRectangle.Size) && !autoCropRectangle.Size.Equals(newImage.Size)) {
                //    LOG.InfoFormat("Crop to {0}", autoCropRectangle);
                //    using (Bitmap tmpImage = newImage) {
                //        newImage = ImageHelper.CloneArea(newImage, autoCropRectangle, PixelFormat.DontCare);
                //    }
                //    // Fix offset
                //    offset = new Point(offset.X - autoCropRectangle.X, offset.Y - autoCropRectangle.Y);
                //} else {
                //    LOG.DebugFormat("No cropping needed!");
                //}

                if (newImage != null) {
                    // Make sure the elements move according to the offset the effect made the bitmap move
                    elements.MoveBy(offset.X, offset.Y);
                    // Make undoable
                    MakeUndoable(new SurfaceBackgroundChangeMemento(this, offset), false);
                    SetImage(newImage, false);
                    Invalidate();
                    if (SurfaceSizeChanged != null && !imageRectangle.Equals(new Rectangle(Point.Empty, newImage.Size))) {
                        SurfaceSizeChanged(this);
                    }
                }
            } finally {
                // Always close the background form
                backgroundForm.CloseDialog();
            }
        }
        /// <summary>
        /// Here the logic for capturing the IE Content is located
        /// </summary>
        /// <param name="capture">ICapture where the capture needs to be stored</param>
        /// <returns>ICapture with the content (if any)</returns>
        public static ICapture CaptureIE(ICapture capture)
        {
            WindowDetails activeWindow = WindowDetails.GetActiveWindow();

            // Show backgroundform after retrieving the active window..
            BackgroundForm backgroundForm = new BackgroundForm(Language.GetString(LangKey.contextmenu_captureie), Language.GetString(LangKey.wait_ie_capture));
            backgroundForm.Show();
            //BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(language.GetString(LangKey.contextmenu_captureie), language.GetString(LangKey.wait_ie_capture));
            try {
                //Get IHTMLDocument2 for the current active window
                DocumentContainer documentContainer = GetDocument(activeWindow);

                // Nothing found
                if (documentContainer == null) {
                    LOG.Debug("Nothing to capture found");
                    return null;
                }
                LOG.DebugFormat("Window class {0}", documentContainer.ContentWindow.ClassName);
                LOG.DebugFormat("Window location {0}", documentContainer.ContentWindow.Location);

                // The URL is available unter "document2.url" and can be used to enhance the meta-data etc.
                capture.CaptureDetails.AddMetaData("url", documentContainer.Url);

                // bitmap to return
                Bitmap returnBitmap = null;
                Size pageSize = Size.Empty;
                try {
                    pageSize = PrepareCapture(documentContainer, capture);
                    returnBitmap = capturePage(documentContainer, capture, pageSize);
                } catch (Exception captureException) {
                    LOG.Error("Exception found, ignoring and returning nothing! Error was: ", captureException);
                }
                // Capture the element on the page
                try {
                    if (configuration.IEFieldCapture && capture.CaptureDetails.HasDestination("Editor")) {
                        // clear the current elements, as they are for the window itself
                        capture.Elements.Clear();
                        CaptureElement documentCaptureElement = documentContainer.CreateCaptureElements(pageSize);
                        foreach(DocumentContainer frameDocument in documentContainer.Frames) {
                            CaptureElement frameCaptureElement = frameDocument.CreateCaptureElements(Size.Empty);
                            if (frameCaptureElement != null) {
                                documentCaptureElement.Children.Add(frameCaptureElement);
                            }
                        }
                        capture.AddElement(documentCaptureElement);
                        // Offset the elements, as they are "back offseted" later...
                        Point windowLocation = documentContainer.ContentWindow.WindowRectangle.Location;
                        capture.MoveElements(-(capture.ScreenBounds.Location.X-windowLocation.X), -(capture.ScreenBounds.Location.Y-windowLocation.Y));
                    }
                } catch (Exception elementsException) {
                    LOG.Warn("An error occurred while creating the capture elements: ", elementsException);
                }

                if (returnBitmap == null) {
                    return null;
                }

                // Store the bitmap for further processing
                capture.Image = returnBitmap;
                // Store the location of the window
                capture.Location = documentContainer.ContentWindow.Location;

                // Store the title of the page
                if (documentContainer.Name != null) {
                    capture.CaptureDetails.Title = documentContainer.Name;
                } else {
                    capture.CaptureDetails.Title = activeWindow.Text;
                }

                // Store the URL of the page
                if (documentContainer.Url != null) {
                    Uri uri = new Uri(documentContainer.Url);
                    capture.CaptureDetails.AddMetaData("URL", uri.OriginalString);
                    // As the URL can hardly be used in a filename, the following can be used
                    if (!string.IsNullOrEmpty(uri.Scheme)) {
                        capture.CaptureDetails.AddMetaData("URL_SCHEME", uri.Scheme);
                    }
                    if (!string.IsNullOrEmpty(uri.DnsSafeHost)) {
                        capture.CaptureDetails.AddMetaData("URL_HOSTNAME", uri.DnsSafeHost);
                    }
                    if (!string.IsNullOrEmpty(uri.AbsolutePath)) {
                        capture.CaptureDetails.AddMetaData("URL_PATH", uri.AbsolutePath);
                    }
                    if (!string.IsNullOrEmpty(uri.Query)) {
                        capture.CaptureDetails.AddMetaData("URL_QUERY", uri.Query);
                    }
                    if (!string.IsNullOrEmpty(uri.UserInfo)) {
                        capture.CaptureDetails.AddMetaData("URL_USER", uri.UserInfo);
                    }
                    capture.CaptureDetails.AddMetaData("URL_PORT", uri.Port.ToString());
                }

                // Only move the mouse to correct for the capture offset
                capture.MoveMouseLocation(-documentContainer.ViewportRectangle.X, -documentContainer.ViewportRectangle.Y);
                // Used to be: capture.MoveMouseLocation(-(capture.Location.X + documentContainer.CaptureOffset.X), -(capture.Location.Y + documentContainer.CaptureOffset.Y));
            } finally {
                // Always close the background form
                backgroundForm.CloseDialog();
            }
            return capture;
        }