Exemplo n.º 1
0
        // This helper function assumes that the input Bitmap24 has already been locked bits.
        private int CountDark(Bitmap24 bmp24, System.Drawing.Rectangle rect)
        {
            int cnt = 0;

            for (int x = rect.Left; x < rect.Right; ++x)
            {
                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    int[] px = bmp24.GetPixel(x, y);
                    if (IsDarkPixel(px))
                    {
                        ++cnt;
                    }
                }
            }
            return(cnt);
        }
Exemplo n.º 2
0
        private void ProcessGlobalKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control && e.Shift && e.Alt)
            {
                switch (e.KeyCode)
                {
                // Shortcuts for changing bot settings.
                case Keys.F6:
                    this.chkEnableConveienceKeys.IsChecked ^= true;
                    break;

                // Shortcuts for setting the bounds of the region.
                case Keys.I:
                {
                    System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                    SetTop(pt.Y);
                }
                break;

                case Keys.J:
                {
                    System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                    SetLeft(pt.X);
                }
                break;

                case Keys.K:
                {
                    System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                    SetRight(pt.X);
                }
                break;

                case Keys.M:
                {
                    System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                    SetBottom(pt.Y);
                }
                break;

                // Shortcuts for defininig the top-left and bottom-right points of the region.
                case Keys.U:
                {
                    System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                    SetLeft(pt.X);
                    SetTop(pt.Y);
                }
                break;

                case Keys.Oemcomma:
                {
                    System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                    SetRight(pt.X);
                    SetBottom(pt.Y);
                }
                break;

                // Debugging shortcuts
                case Keys.L:
                {
                    System.Drawing.Point     pt   = System.Windows.Forms.Cursor.Position;
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(pt.X, pt.Y, 1, 1);
                    using (System.Drawing.Bitmap bmp = WindowWrapper.ScreenCapture(rect))
                    {
                        using (Bitmap24 bmp24 = Bitmap24.FromImage(bmp))
                        {
                            bmp24.Lock();
                            int[]  px  = bmp24.GetPixel(0, 0);
                            double lum = Bitmap24.CalculateLuminance(px);
                            Console.WriteLine("({0}, {1}) -> ({1}) -> {2}", pt.X, pt.Y, string.Join(", ", px), lum);
                        }
                    }
                }
                break;

                case Keys.O:
                {
                    System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(
                        _left,
                        _top,
                        _right - _left + 1,
                        _bottom - _top + 1
                        );
                    using (System.Drawing.Bitmap bmp = WindowWrapper.ScreenCapture(bounds))
                    {
                        bmp.Save(@"tmp.bmp");
                    }
                }
                break;
                }
            }
        }