Наследование: IScreenShot
Пример #1
0
        public int GetLocalPixel(int x, int y)
        {
            int xIndex = x / this.tileWidth;
            int yIndex = y / this.tileHeight + this.bounds.Top;

            ScreenShot ss = this.screenShots[xIndex, yIndex];
            if (ss == null) {
                try {
                    ss = new ScreenShot(new IntRect(xIndex * this.tileWidth + this.bounds.Left, yIndex * tileHeight + this.bounds.Top, tileWidth + 1, tileHeight + 1), false);
                    this.screenShots[xIndex, yIndex] = ss;
                }
                catch (Exception) { }
            }

            if (ss != null) {
                //int x0 = ss.GetLocalPixel(x - xIndex * this.tileWidth, y - yIndex * this.tileHeight);
                //int x1 = ss.GetLocalPixel((x + 1) - xIndex * this.tileWidth, y - yIndex * this.tileHeight);

                return ss.GetLocalPixel(x - xIndex * this.tileWidth, y - yIndex * this.tileHeight);
            }
            return xIndex ^ yIndex;
        }
Пример #2
0
        public static IntRect ExpandPoint(IntPoint position)
        {
            ScreenShot screenshot = new ScreenShot();

            return(ScreenCoordinates.ExpandPoint(position, screenshot));
        }
Пример #3
0
 public static IntRect ExpandPoint(IntPoint position)
 {
     ScreenShot screenshot = new ScreenShot();
     return ScreenCoordinates.ExpandPoint(position, screenshot);
 }
Пример #4
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;
            uint centerPixelX = (uint)screenShot.GetScreenPixel((int)mousePoint.X + 90, (int)mousePoint.Y + 90);

            centerPixel = centerPixelX | 0xFF000000;
            byte  rX     = (byte)((centerPixelX >> 16) & 0xFF);
            byte  gX     = (byte)((centerPixelX >> 8) & 0xFF);
            byte  bX     = (byte)((centerPixelX >> 0) & 0xFF);
            Brush brushX = new SolidColorBrush(Color.FromRgb(rX, gX, bX));

            this.ColorSwatchX.Fill = brushX;
            uint centerPixelY = (uint)screenShot.GetScreenPixel((int)mousePoint.X - 90, (int)mousePoint.Y - 90);

            centerPixel = centerPixelY | 0xFF000000;
            byte  rY     = (byte)((centerPixelY >> 16) & 0xFF);
            byte  gY     = (byte)((centerPixelY >> 8) & 0xFF);
            byte  bY     = (byte)((centerPixelY >> 0) & 0xFF);
            Brush brushY = new SolidColorBrush(Color.FromRgb(rY, gY, bY));

            this.ColorSwatchY.Fill = brushY;
            this.PixelColor.Text   = "HEX: " + string.Format(@"#{0:X8}", centerPixel);
            PixelRGBColor.Text     = "RGB: " + r + ", " + g + ", " + b;
            float _R = (r / 255f);
            float _G = (g / 255f);
            float _B = (b / 255f);

            float _Min   = Math.Min(Math.Min(_R, _G), _B);
            float _Max   = Math.Max(Math.Max(_R, _G), _B);
            float _Delta = _Max - _Min;

            float H = 0;
            float S = 0;
            float L = (float)((_Max + _Min) / 2.0f);

            if (_Delta != 0)
            {
                if (L < 0.5f)
                {
                    S = (float)(_Delta / (_Max + _Min));
                }
                else
                {
                    S = (float)(_Delta / (2.0f - _Max - _Min));
                }


                if (_R == _Max)
                {
                    H = (_G - _B) / _Delta;
                }
                else if (_G == _Max)
                {
                    H = 2f + (_B - _R) / _Delta;
                }
                else if (_B == _Max)
                {
                    H = 4f + (_R - _G) / _Delta;
                }
            }
            PixelHSLColor.Text = "HSL: " + Math.Round(H * 100) + ", " + Math.Round(S * 100).ToString() + "%, " + Math.Round(L * 100).ToString() + "%";
        }
Пример #5
0
        private void HandleTick(object sender, EventArgs e)
        {
            IntPoint mousePoint = NativeMethods.GetCursorPos();

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

            lastCapture    = DateTime.Now;
            lastMousePoint = mousePoint;

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

            if (isPaused)
            {
                return;
            }

            double width  = Image.ActualWidth / Scale;
            double height = Image.ActualHeight / 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)
            {
                CenterX.Width = new GridLength((Image.ActualWidth / 2 - deltaX * Scale) + 2 * Scale);
            }
            else
            {
                CenterX.Width = new GridLength(Image.ActualWidth / 2 + 8);
            }

            if (deltaY != 0)
            {
                CenterY.Height = new GridLength((Image.ActualHeight / 2 - deltaY * Scale) + 2 * Scale);
            }
            else
            {
                CenterY.Height = new GridLength(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();

            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));

            ColorSwatch.Fill = brush;

            PixelColor.Text = string.Format(@"#{0:X8}", centerPixel);
        }
Пример #6
0
        private void CaptureIt()
        {
            IntRect bounds = NativeMethods.ClientToScreen(this, this.Bounds);

            ScreenShot screenshot = new ScreenShot(bounds);

            Clipboard.SetImage(screenshot.Image);

            this.CloseService();
        }
Пример #7
0
        protected override void OnLostMouseCapture(MouseEventArgs e)
        {
            base.OnLostMouseCapture(e);

            if (this.bounds.Width < 3 || this.bounds.Height < 3) {
                this.CloseService();

                return;
            }

            this.Cursor = Cursors.Arrow;

            IntRect startRect = NativeMethods.ClientToScreen(this, this.bounds);

            this.screenshot = new ScreenShot(startRect);

            startRect.Width -= 1;
            startRect.Height -= 1;

            IntRect screenBounds = ScreenCoordinates.Collapse(startRect, this.screenshot);
            Rect bounds = NativeMethods.ScreenToClient(this, screenBounds);

            if (!bounds.IsEmpty) {
                this.AnimateBounds(bounds);
            }

            this.isInDrawMode = false;
            this.Dimensions.CanClose = true;
        }
Пример #8
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);
        }