示例#1
0
        /// <summary>
        /// Creates a new instance of <see cref="WindowProvider"/>.
        /// </summary>
        public WindowProvider(IWindow Window, IPreviewWindow PreviewWindow, bool IncludeCursor)
        {
            _window        = Window ?? throw new ArgumentNullException(nameof(Window));
            _includeCursor = IncludeCursor;

            var size = Window.Rectangle.Even().Size;

            Width  = size.Width;
            Height = size.Height;

            PointTransform = GetTransformer(Window);

            _hdcSrc = User32.GetDC(IntPtr.Zero);

            if (WindowsModule.ShouldUseGdi)
            {
                _dcTarget = new GdiTargetDeviceContext(_hdcSrc, Width, Height);
            }
            else
            {
                _dcTarget = new DxgiTargetDeviceContext(PreviewWindow, Width, Height);
            }
        }
示例#2
0
        public RegionProvider(Rectangle Region,
                              IPreviewWindow PreviewWindow,
                              bool IncludeCursor,
                              Func <Point> LocationFunc = null)
        {
            _region        = Region;
            _includeCursor = IncludeCursor;
            _locationFunc  = LocationFunc ?? (() => Region.Location);

            // Width and Height must be even.
            // Use these for Bitmap size, but capture as per region size
            Width = _region.Width;
            if (Width % 2 == 1)
            {
                ++Width;
            }

            Height = _region.Height;
            if (Height % 2 == 1)
            {
                ++Height;
            }

            PointTransform = P => new Point(P.X - _region.X, P.Y - _region.Y);

            _hdcSrc = User32.GetDC(IntPtr.Zero);

            if (WindowsModule.Windows8OrAbove)
            {
                _dcTarget = new DxgiTargetDeviceContext(PreviewWindow, Width, Height);
            }
            else
            {
                _dcTarget = new GdiTargetDeviceContext(_hdcSrc, Width, Height);
            }
        }