Example #1
0
        private void CountPixel(object sender)
        {
            int bytesPerPixel = CounterImage.Format.BitsPerPixel / 8;
            int stride        = CounterImage.PixelWidth * bytesPerPixel;
            int size          = CounterImage.PixelHeight * stride;

            byte[] pixels = new byte[size];
            CounterImage.CopyPixels(pixels, stride, 0);

            int count = 0;

            for (var i = 0; i < CounterImage.PixelHeight; i++)
            {
                for (var j = 0; j < CounterImage.PixelWidth; j++)
                {
                    if (pixels[i * stride + j * bytesPerPixel + 3] > 0 &&
                        pixels[i * stride + j * bytesPerPixel + 0] == InputB &&
                        pixels[i * stride + j * bytesPerPixel + 1] == InputG &&
                        pixels[i * stride + j * bytesPerPixel + 2] == InputR)
                    {
                        count++;
                    }
                }
            }
            CountedPixel = count;
        }
Example #2
0
        private void GetPixelColorOfLoadedImage(int x, int y)
        {
            int bytesPerPixel = CounterImage.Format.BitsPerPixel / 8;
            int stride        = CounterImage.PixelWidth * bytesPerPixel;
            int size          = CounterImage.PixelHeight * stride;

            byte[] pixels = new byte[size];
            CounterImage.CopyPixels(pixels, stride, 0);

            byte alpha = pixels[y * stride + x * bytesPerPixel + 3];

            if (alpha > 0)
            {
                MouseB = pixels[y * stride + x * bytesPerPixel + 0].ToString();
                MouseG = pixels[y * stride + x * bytesPerPixel + 1].ToString();
                MouseR = pixels[y * stride + x * bytesPerPixel + 2].ToString();
            }
            else
            {
                MouseB = "-";
                MouseG = "-";
                MouseR = "******";
            }
        }