private void timer1_Tick(object sender, EventArgs e) { DateTime start0 = DateTime.UtcNow; if (this.Handle != ScreenCapture.GetForegroundWindow() && goRecorder == null) { windowHandle = ScreenCapture.GetForegroundWindow(); } if (windowHandle == IntPtr.Zero) { return; } Window window = new Window(windowHandle); WindowTitle.Text = window.Title; if (windowHandle != ScreenCapture.GetForegroundWindow()) //Capturing background windows is buggy { return; } Pixels pix = capturer.Capture(windowHandle); //allocStats.Text = "Alloc:" + capturer.CacheMissAllocs + "/" + capturer.TotalAllocs; //bmp.Save("ScreenShot.bmp"); if (!Pixels.DataEquals(oldPixels, pix)) { frameCounter++; FrameCounterLabel.Text = frameCounter.ToString(); BoardInfo board = null; ImageToBoardInfo imageToBoardInfo = new ImageToBoardInfo(); if (!(found && pix.Width == size.Width && pix.Height == size.Height)) { found = imageToBoardInfo.GetBoardParameters(pix, out bp); size = pix.Size; } if (found) { board = imageToBoardInfo.ProcessImage(bp, pix); } if (board != null) { if (goRecorder != null) { goRecorder.Add(Duration, board); goRecorder.Replay.Save("Capture.GoVideo"); } GameState gameState = GoVideoToReplay.BoardToGameState(board); StateRenderer renderer = new StateRenderer(new GoClient.Drawing.GraphicsSystem()); renderer.BlockSize = 16; renderer.State = gameState; Preview.Image = ((GoClient.Drawing.Bitmap)renderer.Render()).InternalBitmap; } } ProcessingTime.Text = TS(DateTime.UtcNow - start0); timeLabel.Text = TimeSpan.FromSeconds(Math.Round(Duration.TotalSeconds)).ToString(); capturer.Release(oldPixels); oldPixels = pix; }