void OnCapture() { if (!_window.IsAlive) { throw new WindowClosedException(); } var rect = _window.Rectangle.Even(); var ratio = Math.Min((float)Width / rect.Width, (float)Height / rect.Height); var resizeWidth = (int)(rect.Width * ratio); var resizeHeight = (int)(rect.Height * ratio); var hdcDest = _dcTarget.GetDC(); void ClearRect(RECT Rect) { User32.FillRect(hdcDest, ref Rect, IntPtr.Zero); } if (Width != resizeWidth) { ClearRect(new RECT { Left = resizeWidth, Right = Width, Bottom = Height }); } else if (Height != resizeHeight) { ClearRect(new RECT { Top = resizeHeight, Right = Width, Bottom = Height }); } Gdi32.StretchBlt(hdcDest, 0, 0, resizeWidth, resizeHeight, _hdcSrc, rect.X, rect.Y, rect.Width, rect.Height, (int)CopyPixelOperation.SourceCopy); if (_includeCursor) { MouseCursor.Draw(hdcDest, PointTransform); } }
public IEditableFrame Capture() { // Update Location _region.Location = _locationFunc(); var hdcDest = _dcTarget.GetDC(); Gdi32.BitBlt(hdcDest, 0, 0, _region.Width, _region.Height, _hdcSrc, _region.X, _region.Y, (int)CopyPixelOperation.SourceCopy); if (_includeCursor) { MouseCursor.Draw(hdcDest, PointTransform); } var img = _dcTarget.GetEditableFrame(); return(img); }