private static Bitmap TakeScrollingScreenshot(Point centerPoint, Rectangle rect, Point mousePoint, bool click, ScreenshotFunction screenshot, HighlightFunction highlight, out int scrollCount) { scrollCount = 0; Cursor.Position = mousePoint; Bitmap buffer = screenshot(rect); int usedHeight = buffer.Height; buffer = ResizeBitmap(buffer, buffer.Height * 4); bool lastMayBeIncomplete = false; while (Cursor.Position == mousePoint) { scrollCount++; if (click) { KeyboardKey.InjectMouseEvent(0x0002, 0, 0, 0, UIntPtr.Zero); KeyboardKey.InjectMouseEvent(0x0004, 0, 0, 0, UIntPtr.Zero); } else { KeyboardKey.InjectMouseEvent(0x0800, 0, 0, unchecked((uint)-120), UIntPtr.Zero); } Application.DoEvents(); highlight(rect); Bitmap nextPart = screenshot(rect); int scrollHeight = AppendBelow(buffer, usedHeight, nextPart, false); foreach (int delay in new int[] { 0, 2, 10, 100, 200, 1000 }) { if (scrollHeight > 0 || Cursor.Position != mousePoint) break; Thread.Sleep(delay); Application.DoEvents(); highlight(rect); nextPart = screenshot(rect); scrollHeight = AppendBelow(buffer, usedHeight, nextPart, false); } if (scrollHeight == -1) { if (lastMayBeIncomplete) { scrollHeight = AppendBelow(buffer, usedHeight, nextPart, true); } lastMayBeIncomplete = false; } else { lastMayBeIncomplete = true; } if (scrollHeight == -1) { CropToSimilarRange(centerPoint, ref rect, ref buffer, ref usedHeight, ref nextPart); highlight(rect); scrollHeight = AppendBelow(buffer, usedHeight, nextPart, false); } if (scrollHeight <= 0) break; usedHeight += scrollHeight; if (buffer.Height - usedHeight < rect.Height) buffer = ResizeBitmap(buffer, buffer.Height * 2); } return ResizeBitmap(buffer, usedHeight); }
private static Bitmap TakeScrollingScreenshot(Point centerPoint, Rectangle rect, Point mousePoint, bool click, ScreenshotFunction screenshot, HighlightFunction highlight, out int scrollCount) { scrollCount = 0; Cursor.Position = mousePoint; Bitmap buffer = screenshot(rect); int usedHeight = buffer.Height; buffer = ResizeBitmap(buffer, buffer.Height * 4); bool lastMayBeIncomplete = false; while (Cursor.Position == mousePoint) { scrollCount++; if (click) { KeyboardKey.InjectMouseEvent(0x0002, 0, 0, 0, UIntPtr.Zero); KeyboardKey.InjectMouseEvent(0x0004, 0, 0, 0, UIntPtr.Zero); } else { KeyboardKey.InjectMouseEvent(0x0800, 0, 0, unchecked ((uint)-120), UIntPtr.Zero); } Application.DoEvents(); highlight(rect); Bitmap nextPart = screenshot(rect); int scrollHeight = AppendBelow(buffer, usedHeight, nextPart, false); foreach (int delay in new int[] { 0, 2, 10, 100, 200, 1000 }) { if (scrollHeight > 0 || Cursor.Position != mousePoint) { break; } Thread.Sleep(delay); Application.DoEvents(); highlight(rect); nextPart = screenshot(rect); scrollHeight = AppendBelow(buffer, usedHeight, nextPart, false); } if (scrollHeight == -1) { if (lastMayBeIncomplete) { scrollHeight = AppendBelow(buffer, usedHeight, nextPart, true); } lastMayBeIncomplete = false; } else { lastMayBeIncomplete = true; } if (scrollHeight == -1) { CropToSimilarRange(centerPoint, ref rect, ref buffer, ref usedHeight, ref nextPart); highlight(rect); scrollHeight = AppendBelow(buffer, usedHeight, nextPart, false); } if (scrollHeight <= 0) { break; } usedHeight += scrollHeight; if (buffer.Height - usedHeight < rect.Height) { buffer = ResizeBitmap(buffer, buffer.Height * 2); } } return(ResizeBitmap(buffer, usedHeight)); }