예제 #1
0
        private void CaptureRegion()
        {
            try
            {
                var enableDrawMark = Convert.ToInt32(Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\NiceScreenCapturer", "DrawMark", 0));
                var currScr        = Screen.FromPoint(new Point(Cursor.Position.X, Cursor.Position.Y));
                var scr            = AllScreen.First(m => m.DeviceName == currScr.DeviceName);
                var win            = new Window1
                {
                    Topmost         = true,
                    Left            = scr.WorkingArea.Left,
                    CurrentScreen   = scr,
                    IsCaptureScreen = false,
                    IsDrawMark      = enableDrawMark == 1
                };
                win.SourceInitialized += (snd, arg) => win.WindowState = System.Windows.WindowState.Maximized;
                win.ShowDialog();

                if (win.IsQuitByEscape)
                {
                    return;
                }

                //Starting Capture
                var scaleScreen = win.CurrentScreen;
                var scaleFactor = win.ZoneFirst.ScaleFactor;

                var rightScreenInfo = new ScreenInfo();
                var rightScreenMark = new List <ZoneInfo>();
                if (scaleScreen.Bounds.X == 0)
                {
                    //Get region of primary screen
                    rightScreenInfo.X      = 0;
                    rightScreenInfo.Y      = 0;
                    rightScreenInfo.Width  = (int)(win.ZoneFirst.ZoneWidth * scaleFactor);
                    rightScreenInfo.Height = (int)(win.ZoneFirst.ZoneHeight * scaleFactor);
                    rightScreenInfo.StartX = (int)((win.ZoneFirst.ZoneX - 6.4) * scaleFactor);
                    rightScreenInfo.StartY = (int)((win.ZoneFirst.ZoneY - 6.4) * scaleFactor);
                }
                else
                {
                    //Get region of another screen
                    var scrCurrent = AllScreen.First(m => m.DeviceName == scaleScreen.DeviceName);
                    rightScreenInfo.X      = 0;
                    rightScreenInfo.Y      = 0;
                    rightScreenInfo.Width  = (int)(win.ZoneFirst.ZoneWidth * scaleFactor);
                    rightScreenInfo.Height = (int)(win.ZoneFirst.ZoneHeight * scaleFactor);
                    rightScreenInfo.StartX = (int)((win.ZoneFirst.ZoneX - 6.4) * scaleFactor + scrCurrent.Bounds.X);
                    rightScreenInfo.StartY = (int)((win.ZoneFirst.ZoneY - 6.4) * scaleFactor);
                }

                if (win.ZoneMark != null && win.ZoneMark.Count > 0)
                {
                    //Get region of mark rectangle
                    foreach (var zoneInfo in win.ZoneMark)
                    {
                        var rightScreenMarkItem = new ZoneInfo
                        {
                            ZoneX       = (double)(zoneInfo.ZoneX - win.ZoneFirst.ZoneX) * scaleFactor,
                            ZoneY       = (double)(zoneInfo.ZoneY - win.ZoneFirst.ZoneY) * scaleFactor,
                            ZoneWidth   = zoneInfo.ZoneWidth * scaleFactor,
                            ZoneHeight  = zoneInfo.ZoneHeight * scaleFactor,
                            BorderColor = zoneInfo.BorderColor,
                            Thinkness   = zoneInfo.Thinkness
                        };
                        rightScreenMark.Add(rightScreenMarkItem);
                    }
                }
                win.ZoneFirst = null;
                win.ZoneMark  = null;

                var saveAsImageType = Convert.ToInt32(Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\NiceScreenCapturer", "SaveType", 1));
                CaptureClass.CaptureScreenWithMarktoClipboard(rightScreenInfo.X, rightScreenInfo.Y, rightScreenInfo.Width, rightScreenInfo.Height, rightScreenInfo.StartX, rightScreenInfo.StartY, rightScreenMark, saveAsImageType);

                //clear memory
                rightScreenInfo = null;
                rightScreenMark = null;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }