Example #1
0
        public UnsafeMemoryBitmap CaptureViewPort(int x, int y, int width, int height)
        {
            Bitmap             bmp  = new Bitmap("C:\\Temp\\CaptureAgent\\still.jpg");
            UnsafeMemoryBitmap ubmp = new UnsafeMemoryBitmap(bmp, bmp.PixelFormat, ImageLockMode.ReadWrite, true);

            return(ubmp);
        }
Example #2
0
        public override void Run()
        {
            base.Run();
            logger.Info("Capturing screen");
            ICaptureAgent      captureAgent = new SimpleCaptureAgent();
            Rectangle          rect         = ApplicationWindow.ToRectangle();
            UnsafeMemoryBitmap bmp          = captureAgent.CaptureViewPort(rect.X, rect.Y, rect.Width, rect.Height);

            Console.ReadLine();
        }
Example #3
0
        public UnsafeMemoryBitmap CaptureViewPort(int x, int y, int width, int height)
        {
            _actionTimer = new Stopwatch();
            _actionTimer.Start();
            Bitmap bmp = new Bitmap(width, height);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.CopyFromScreen(x, y, 0, 0, new Size(width, height));
            }
            UnsafeMemoryBitmap ubmp = new UnsafeMemoryBitmap(bmp);

            _actionTimer.Stop();

            return(ubmp);
        }
Example #4
0
        public static unsafe void ProcessImageForColor(Color color, ref UnsafeMemoryBitmap bmp, ref bool foundColor)
        {
            Stopwatch s = new Stopwatch();

            s.Start();

            int depth = Image.GetPixelFormatSize(bmp.Data.PixelFormat);
            //logger.Info($"W:{bmp.Data.Width}, H:{bmp.Data.Height}, depth: {depth}");

            //Gets the first pixel data pointer(Ptr)
            byte *scan0 = (byte *)bmp.Data.Scan0.ToPointer();

            for (int i = 0; i < bmp.Data.Height; i++)
            {
                for (int j = 0; j < bmp.Data.Width; j++)
                {
                    Pixel pixel = new Pixel();
                    Pixel.Read(bmp.Data, i, j, depth, scan0, ref pixel);

                    if (pixel.IsEmpty)
                    {
                        continue;
                    }
                    if (pixel.IsColor(color))
                    {
                        foundColor = true;
                        return;
                    }
                    else
                    {
                        pixel.Blank();
                    }
                }
            }
            //logger.Trace($"Bitmap Processing took: {s.ElapsedMilliseconds}ms");
        }