/// <summary> /// Creates a screen handler to get the changed parts of the screen since the last check. /// </summary> /// <param name="screen">A rectangle that represents which part of the screen will be handled.</param> /// <param name="hashOnlyCompare">If true, pixel data will be checked only by its HashCode, otherwise it will be checked with the implemented Equals method</param> public ScreenHandler(Rectangle screen, bool hashOnlyCompare) { if (hashOnlyCompare) { Comparator = new HashComparer(); } else { Comparator = new FullComparer(); } Rectangle2 rect = new Rectangle2(screen); Bounds = rect; //One of the most expensive operations, getting the screen capture. Should be used as less as possible int[] pixels = PixelGrabber.GrabPixels(PixelGrabber.CreateScreenCapture(screen)); LastPixels = pixels; int minTHeight = Bounds.Height / 6; int minTWidth = Bounds.Width / 8; current = new QuadTree(rect, pixels /*, minTHeight, minTWidth*/); previous = current; firstScreen = true; }
private void RefreshCurrent() { Stopwatch o = Stopwatch.StartNew(); Bitmap b = PixelGrabber.CreateScreenCapture(Bounds.ToRectangle()); Stopwatch c = Stopwatch.StartNew(); int[] pixels = PixelGrabber.GrabPixels(b); c.Stop(); Trace.WriteLine("Refresh grab done in: " + c.ElapsedMilliseconds + "ms"); LastPixels = pixels; current = new QuadTree(Bounds, pixels); o.Stop(); Trace.WriteLine("Complete refresh done in: " + o.ElapsedMilliseconds + "ms"); }