public void CaptureActiveControl(IntPtr handle) { IntPtr activeControl = Win.GetActiveControl(handle); if (activeControl != IntPtr.Zero) { Win.RECT activeWindowRect; Win.GetWindowRect(activeControl, out activeWindowRect); Rect myRect; System.Drawing.Point caretPosition = GetCaretPosition(); if (caretPosition == System.Drawing.Point.Empty) { double width = activeWindowRect.Right - activeWindowRect.Left; double height = activeWindowRect.Bottom - activeWindowRect.Top; ConversionHelper.ResizeToArea(ref width, ref height, 900); myRect = new Rect(activeWindowRect.Left, activeWindowRect.Top, width, height); } else { if (PointIsOutsideRect(caretPosition, activeWindowRect)) { myRect = new Rect(activeWindowRect.Left, activeWindowRect.Top, Math.Max(50, Math.Min(activeWindowRect.Right - activeWindowRect.Left, 200)), Math.Max(25, Math.Min(activeWindowRect.Bottom - activeWindowRect.Top, 100))); } else { myRect = new Rect(caretPosition.X, caretPosition.Y, 1, 1); myRect.Inflate(100, 50); } } ScreenCapture.SetAreaOfFocus(myRect); CaptureScreen(); } }
int GetScreenGrabHeight(BitmapSource initialScreenGrab) { if (maxPixelsInScreenGrabPreview == int.MinValue) { return(initialScreenGrab.PixelHeight); } else { double width = initialScreenGrab.PixelWidth; double height = initialScreenGrab.PixelHeight; ConversionHelper.ResizeToArea(ref width, ref height, maxPixelsInScreenGrabPreview); return((int)Math.Round(height)); } }