Exemple #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PickModeOn = !PickModeOn;

            if (PickModeOn)
            {
                Timer.Start();

                Point mousePos = MouseHook.GetCursorPosition();
                myPopup.Placement        = System.Windows.Controls.Primitives.PlacementMode.AbsolutePoint;
                myPopup.HorizontalOffset = mousePos.X;
                myPopup.VerticalOffset   = mousePos.Y;
                myPopup.IsOpen           = true;
            }
            else
            {
                Timer.Stop();
                myPopup.IsOpen = false;
            }
        }
Exemple #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            IntPtr handle = IntPtr.Zero;

            try
            {
                Point cursorPosition = MouseHook.GetCursorPosition();
                myPopup.HorizontalOffset = cursorPosition.X;
                myPopup.VerticalOffset   = cursorPosition.Y;

                Bitmap bitmap;
                bitmap = new Bitmap(50, 50, PixelFormat.Format32bppArgb);

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    g.CopyFromScreen((int)cursorPosition.X - 25, (int)cursorPosition.Y - 25, 0, 0, bitmap.Size);
                }

                handle            = bitmap.GetHbitmap();
                imgControl.Source = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty,
                                                                          BitmapSizeOptions.FromEmptyOptions());

                var pixel = bitmap.GetPixel(25, 25);
                PickedColor = Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B);

                if (MouseHook.GetLeftButtonState() < 0)
                {
                    if (!this.IsMouseOver)
                    {
                        PickedColors.Add(PickedColor);
                    }
                }
            }
            catch (Exception)
            { }
            finally
            {
                DeleteObject(handle);
            }
        }