Exemple #1
0
        public ScreenShot(IntRect screenBounds, bool keepBitmap)
        {
            this.Capture(screenBounds);

            if (!keepBitmap)
                this.bitmap = null;
        }
Exemple #2
0
        public static Rect ScreenToClient(FrameworkElement element, IntRect rect)
        {
            Point topLeft = NativeMethods.ScreenToClient(element, rect.TopLeft);
            Point bottomRight = NativeMethods.ScreenToClient(element, rect.BottomRight);

            return new Rect(topLeft, bottomRight);
        }
        public VirtualizedScreenShot()
        {
            this.bounds = ScreenShot.FullScreenBounds;

            int countX = (int)Math.Ceiling(this.bounds.Width / (double)tileWidth);
            int countY = (int)Math.Ceiling(this.bounds.Height / (double)tileHeight);

            this.screenShots = new ScreenShot[tileWidth,tileHeight];
        }
        public VirtualizedScreenShot()
        {
            this.bounds = ScreenShot.FullScreenBounds;

            var countX = (int)Math.Ceiling(this.bounds.Width / (double)tileWidth) + 1;
            var countY = (int)Math.Ceiling(this.bounds.Height / (double)tileHeight) + 1;

            this.screenShots = new ScreenShot[countX, countY];
        }
        public static IntRect Collapse(IntRect rect, IScreenShot screenshot)
        {
            int left = ScreenCoordinates.FindNearestX(rect.Left, rect.Top, rect.Bottom, 1, screenshot).X;
            int right = ScreenCoordinates.FindNearestX(rect.Right, rect.Top, rect.Bottom, -1, screenshot).X + 1;

            int top = ScreenCoordinates.FindNearestY(rect.Left, rect.Right, rect.Top, 1, screenshot).Y - 1;
            int bottom = ScreenCoordinates.FindNearestY(rect.Left, rect.Right, rect.Bottom, -1, screenshot).Y;

            if (right > left && bottom > top)
                return new IntRect(left, top + 1, right - left, bottom - top);
            return IntRect.Empty;
        }
 public static IntRect Collapse(IntRect rect)
 {
     return ScreenCoordinates.Collapse(rect, new ScreenShot());
 }
Exemple #7
0
 public ScreenShot(IntRect screenBounds)
     : this(screenBounds, true)
 {
 }
Exemple #8
0
        private void Capture(IntRect bounds)
        {
            this.bounds = bounds;

            BitmapSource bitmap = null;

            using (NativeMethods.DC hdcScreen = NativeMethods.CreateDC("Display", null, null, IntPtr.Zero)) {
                using (NativeMethods.DC hdcDest = hdcScreen.CreateCompatibleDC()) {
                    using (NativeMethods.GdiObject hBitmap = hdcScreen.CreateCompatibleBitmap(bounds.Width, bounds.Height)) {
                        NativeMethods.GdiObject oldBitmap = hdcDest.SelectObject(hBitmap);
                        hdcDest.BitBlt(0, 0, bounds.Width, bounds.Height, hdcScreen, bounds.Left, bounds.Top, 0xcc0020);

                        bitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap.IntPtr, IntPtr.Zero, new Int32Rect(0, 0, bounds.Width, bounds.Height), null);
                        hdcDest.SelectObject(oldBitmap);
                    }
                }
            }

            //IntPtr hdcScreen = NativeMethods.CreateDC("Display", null, null, IntPtr.Zero);
            //if (hdcScreen != IntPtr.Zero) {
            //    IntPtr hdcDest = NativeMethods.CreateCompatibleDC(hdcScreen);
            //    if (hdcDest != IntPtr.Zero) {
            //        IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hdcScreen, bounds.Width, bounds.Height);
            //        if (hBitmap != IntPtr.Zero) {
            //            IntPtr oldBitmap = NativeMethods.SelectObject(hdcDest, hBitmap);
            //            NativeMethods.BitBlt(hdcDest, 0, 0, bounds.Width, bounds.Height, hdcScreen, bounds.X, bounds.Y, 0xcc0020);

            //            bitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, new Int32Rect(0, 0, bounds.Width, bounds.Height), null);
            //            NativeMethods.SelectObject(hdcDest, oldBitmap);
            //            NativeMethods.DeleteObject(hBitmap);
            //        }
            //        NativeMethods.DeleteDC(hdcDest);
            //    }
            //    NativeMethods.DeleteDC(hdcScreen);
            //}

            if (bitmap != null) {
                this.Init(bitmap);
            }
        }
Exemple #9
0
 public bool Equals(IntRect value)
 {
     return this.Left == value.Left && this.Width == value.Width && this.Top == value.Top && this.Height == value.Height;
 }
Exemple #10
0
        public void Union(IntRect rect)
        {
            if (this.IsEmpty)
                this = rect;

            else if (!rect.IsEmpty) {
                int left = Math.Min(this.Left, rect.Left);
                int top = Math.Min(this.Top, rect.Top);

                int right = Math.Max(this.Right, rect.Right);
                this.Width = Math.Max(right - left, 0);

                int bottom = Math.Max(this.Bottom, rect.Bottom);
                this.Height = Math.Max(bottom - top, 0);

                this.Left = left;
                this.Top = top;
            }
        }
Exemple #11
0
        private void HandleTick(object sender, EventArgs e)
        {
            IntPoint mousePoint = NativeMethods.GetCursorPos();

            if (mousePoint == this.lastMousePoint && DateTime.Now - this.lastCapture < TimeSpan.FromSeconds(.2))
            {
                return;
            }

            this.lastCapture    = DateTime.Now;
            this.lastMousePoint = mousePoint;

            this.MouseX.Text = string.Format(@"X: {0}", mousePoint.X - this.basePoint.X);
            this.MouseY.Text = string.Format(@"Y: {0}", mousePoint.Y - this.basePoint.Y);

            if (this.isPaused)
            {
                return;
            }


            double width  = this.Image.ActualWidth / this.Scale;
            double height = this.Image.ActualHeight / this.Scale;



            double left = (mousePoint.X - width / 2).Clamp(ScreenShot.FullScreenBounds.Left, ScreenShot.FullScreenBounds.Width - width);
            double top  = (mousePoint.Y - height / 2).Clamp(ScreenShot.FullScreenBounds.Top, ScreenShot.FullScreenBounds.Height - height);


            double deltaX = left - (mousePoint.X - width / 2);
            double deltaY = top - (mousePoint.Y - height / 2);

            if (deltaX != 0)
            {
                this.CenterX.Width = new GridLength((this.Image.ActualWidth / 2 - deltaX * this.Scale) + 2 * this.Scale);
            }
            else
            {
                this.CenterX.Width = new GridLength(this.Image.ActualWidth / 2 + 8);
            }

            if (deltaY != 0)
            {
                this.CenterY.Height = new GridLength((this.Image.ActualHeight / 2 - deltaY * this.Scale) + 2 * this.Scale);
            }
            else
            {
                this.CenterY.Height = new GridLength(this.Image.ActualHeight / 2 + 8);
            }



            IntRect rect = new IntRect((int)left, (int)top, (int)width, (int)height);

            ScreenShot screenShot = new ScreenShot(rect);

            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();

            newFormatedBitmapSource.BeginInit();
            newFormatedBitmapSource.Source            = screenShot.Image;
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
            newFormatedBitmapSource.EndInit();

            this.Image.Source = newFormatedBitmapSource;

            if (width == 0 || height == 0)
            {
                return;
            }

            uint centerPixel = (uint)screenShot.GetScreenPixel((int)mousePoint.X, (int)mousePoint.Y);

            centerPixel = centerPixel | 0xFF000000;
            byte r = (byte)((centerPixel >> 16) & 0xFF);
            byte g = (byte)((centerPixel >> 8) & 0xFF);
            byte b = (byte)((centerPixel >> 0) & 0xFF);

            Brush brush = new SolidColorBrush(Color.FromRgb(r, g, b));

            this.ColorSwatch.Fill = brush;

            this.PixelColor.Text = string.Format(@"#{0:X8}", centerPixel);
        }
Exemple #12
0
 public ScreenShot(IntRect screenBounds) : this(screenBounds, true)
 {
 }
Exemple #13
0
        private void HandleTick(object sender, EventArgs e)
        {
            IntPoint mousePoint = NativeMethods.GetCursorPos();

            if (mousePoint == this.lastMousePoint && DateTime.Now - this.lastCapture < TimeSpan.FromSeconds(.2)) {
                return;
            }

            this.lastCapture = DateTime.Now;
            this.lastMousePoint = mousePoint;

            this.MouseX.Text = string.Format(@"X: {0}", mousePoint.X - this.basePoint.X);
            this.MouseY.Text = string.Format(@"Y: {0}", mousePoint.Y - this.basePoint.Y);

            if (this.isPaused)
                return;

            double width = this.Image.ActualWidth / this.Scale;
            double height = this.Image.ActualHeight / this.Scale;

            double left = (mousePoint.X - width / 2).Clamp(ScreenShot.FullScreenBounds.Left, ScreenShot.FullScreenBounds.Width - width);
            double top = (mousePoint.Y - height / 2).Clamp(ScreenShot.FullScreenBounds.Top, ScreenShot.FullScreenBounds.Height - height);

            double deltaX = left - (mousePoint.X - width / 2);
            double deltaY = top - (mousePoint.Y - height / 2);

            if (deltaX != 0)
                this.CenterX.Width = new GridLength((this.Image.ActualWidth / 2 - deltaX * this.Scale) + 2 * this.Scale);
            else
                this.CenterX.Width = new GridLength(this.Image.ActualWidth / 2 + 8);

            if (deltaY != 0)
                this.CenterY.Height = new GridLength((this.Image.ActualHeight / 2 - deltaY * this.Scale) + 2 * this.Scale);
            else
                this.CenterY.Height = new GridLength(this.Image.ActualHeight / 2 + 8);

            IntRect rect = new IntRect((int)left, (int)top, (int)width, (int)height);

            ScreenShot screenShot = new ScreenShot(rect);

            FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
            newFormatedBitmapSource.BeginInit();
            newFormatedBitmapSource.Source = screenShot.Image;
            newFormatedBitmapSource.DestinationFormat = PixelFormats.Rgb24;
            newFormatedBitmapSource.EndInit();

            this.Image.Source = newFormatedBitmapSource;

            if (width == 0 || height == 0)
                return;

            uint centerPixel = (uint)screenShot.GetScreenPixel((int)mousePoint.X, (int)mousePoint.Y);
            centerPixel = centerPixel | 0xFF000000;
            byte r = (byte)((centerPixel >> 16) & 0xFF);
            byte g = (byte)((centerPixel >> 8) & 0xFF);
            byte b = (byte)((centerPixel >> 0) & 0xFF);

            Brush brush = new SolidColorBrush(Color.FromRgb(r, g, b));
            this.ColorSwatch.Fill = brush;

            this.PixelColor.Text = string.Format(@"#{0:X8}", centerPixel);
        }
Exemple #14
0
 public bool Equals(IntRect value)
 {
     return(Left == value.Left && Width == value.Width && Top == value.Top && Height == value.Height);
 }
 public static IntRect Collapse(IntRect rect)
 {
     return(ScreenCoordinates.Collapse(rect, new ScreenShot()));
 }