public ImageCaptureWindow(System.Drawing.Rectangle rect, AreaSelection areaSelection) { InitializeComponent(); MouseUp += OnMouseUp; MouseDown += OnMouseDown; MouseMove += OnMouseMove; Loaded += OnMainWindowLoaded; _scalor = DpiUtilities.GetVirtualPixelScale(this); _areaSelection = areaSelection; var monitors = _areaSelection.GetMonitorsInformation(); _screenShotImage = new ScreenshotImage(); _screenScalor = DpiUtilities.GetScreenScalingFactor(); _screenShotImage.SnapShot(rect, _screenScalor); WindowStartupLocation = WindowStartupLocation.Manual; SourceInitialized += (sender, e) => { IntPtr hWnd = new WindowInteropHelper(this).Handle; NativeMethods.SetWindowPos(hWnd, (IntPtr)NativeMethods.SetWindowPosInsertAfter.HWND_TOP, rect.Left, rect.Top, rect.Width, rect.Height, 0); }; var bmDesktopSource = ScreenCapture.GetBitmapSource(_screenShotImage.ScreenSnapshotImage); BackgroundImage.Fill = new ImageBrush(bmDesktopSource); // MagnifierBackgroundImage.Source = bmDesktopSource; }
/// <summary> /// Returns DPI (X, Y) /// </summary> /// <param name="window"></param> /// <returns></returns> public static DpiScale GetDpiScale(Window window) { return(DpiUtilities.GetVirtualPixelScale(window)); }