示例#1
0
        void Contextmenu_window_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
             try
             {
            WindowDetails windowToCapture = (WindowDetails)clickedItem.Tag;
            ICapture capture = new Capture();
            using (Graphics graphics = Graphics.FromHwnd(this.Handle))
            {
               capture.CaptureDetails.DpiX = graphics.DpiY;
               capture.CaptureDetails.DpiY = graphics.DpiY;
            }
            windowToCapture.Restore();
            windowToCapture = CaptureForm.SelectCaptureWindow(windowToCapture);
            if (windowToCapture != null)
            {
               capture = CaptureForm.CaptureWindow(windowToCapture, capture, coreConf.WindowCaptureMode);
               this.Activate();
               WindowDetails.ToForeground(this.Handle);
               if (capture != null && capture.Image != null)
               {
                  surface.AddBitmapContainer((Bitmap)capture.Image, 100, 100);
               }
            }

            if (capture != null)
            {
               capture.Dispose();
            }
             }
             catch (Exception exception)
             {
            LOG.Error(exception);
             }
        }
        private void Contextmenu_window_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem clickedItem = (ToolStripMenuItem)sender;
            try
            {
                WindowDetails windowToCapture = (WindowDetails)clickedItem.Tag;
                ICapture capture = new Capture();
                using (Graphics graphics = Graphics.FromHwnd(this.Handle))
                {
                    capture.CaptureDetails.DpiX = graphics.DpiY;
                    capture.CaptureDetails.DpiY = graphics.DpiY;
                }
                windowToCapture.Restore();
                windowToCapture = CaptureHelper.SelectCaptureWindow(windowToCapture);
                if (windowToCapture != null)
                {
                    capture = CaptureHelper.CaptureWindow(windowToCapture, capture, coreConf.WindowCaptureMode);
                    this.Activate();
                    WindowDetails.ToForeground(this.Handle);
                    if (capture != null && capture.Image != null)
                    {
                        bool addShadow = false;
                        if (addShadow)
                        {
                            Point offset = new Point(6, 6);
                            using (Bitmap shadowImage = ImageHelper.CreateShadow(capture.Image, 1f, 7, offset, PixelFormat.Format32bppArgb))
                            {
                                surface.AddBitmapContainer(shadowImage, 100, 100);
                            }
                        }
                        else
                        {
                            surface.AddBitmapContainer((Bitmap)capture.Image, 100, 100);
                        }
                    }
                }

                if (capture != null)
                {
                    capture.Dispose();
                }
            }
            catch (Exception exception)
            {
                LOG.Error(exception);
            }
        }