private static Image ReadBitmap(GeckoWebBrowser webBrowser, CaptureZone captureZone, IActiveDocument activeDocument) { webBrowser.Stop(); var rectangle = captureZone.GetZone(activeDocument); if (rectangle.Width == 0 || rectangle.Height == 0) { throw new CaptureEngineException($"Selected zone is 0 area {rectangle}", CaptureEngineState.InvalidCaptureZone); } try { return(webBrowser.GetBitmap( (uint)rectangle.X, (uint)rectangle.Y, (uint)rectangle.Width, (uint)rectangle.Height)); } catch (InvalidOperationException) { throw new CaptureEngineException("Out of memory. Result bitmap size is too large", CaptureEngineState.InternalError); } }