private void BackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled == true) { Debug.WriteLine("RunWorkerCompleted: {1}", "", "Canceled!"); } else if (e.Error != null) { Debug.WriteLine("RunWorkerCompleted: {1}", "", "Error: " + e.Error.Message); } else { ClientType client = (ClientType)e.Result; client.DoFinish(); System.Windows.Controls.Image previewCaptureImage = (System.Windows.Controls.Image)RootElement.FindName("previewCaptureImage"); System.Windows.Media.Imaging.BitmapSource bs = client.GetRenderTargetBitmapSource(); // bs.Freeze(); previewCaptureImage.Source = bs; System.Windows.Controls.TextBlock CapturePerSecond = (System.Windows.Controls.TextBlock)RootElement.FindName("CapturePerSecond"); CapturePerSecond.Text = "FPS: " + client.FPS.ToString(); System.Windows.Controls.TextBlock UIRedrawsPerSecond = (System.Windows.Controls.TextBlock)RootElement.FindName("UIRedrawsPerSecond"); UIRedrawsPerSecond.Text = "DPS: " + drawCounter.GetFPS().ToString(); GC.Collect(); drawCounter.IncreaseFrame(); } }
public void FrameReady(object sender, EventArgs e) { try { if (!frameAnalysisInProgress) { frameAnalysisInProgress = true; ClientType client = null; ClientMap clientMap = null; // Capture Screen switch (Settings.AppRunMode) { case SettingsAppRunMode.Normal: // Capture Image Mat capturedImage = capture.getLastFrameAsMat(); if (capturedImage == null) { frameAnalysisInProgress = false; return; } // Cut out current Window string currentClientType = this.GetCurrentClientTyp(); Rect appRect = this.GetCurrentProcessWindowRect(); try { capturedImage = new Mat(capturedImage, appRect); } catch (OpenCvSharp.OpenCVException ocve) { // Debug.WriteLine("OpenCvSharp.OpenCVException: {1}", "", ocve.Message); // Debug.WriteLine("Rect: {1}/{2}/{3}/{4}", "", appRect.X, appRect.Y, appRect.Width, appRect.Height, ocve.Message); // Debug.WriteLine("Mat: {1}/{2}", "", mat.Width, mat.Height); capturedImage = null; } // Detect Client Type clientMap = (from ClientMap in this.ClientMapping where ClientMap.ProcessType == this.GetCurrentClientTyp() select ClientMap).FirstOrDefault(); if (clientMap != null && capturedImage != null) { client = clientMap.Client; client.CaptureResult = capturedImage; } else { client = new ClientTypeNone(); } break; case SettingsAppRunMode.ForceGameCapture: Mat forceCapturedImage = capture.getLastFrameAsMat(); clientMap = (from ClientMap in this.ClientMapping where ClientMap.ProcessType == "gameClient" select ClientMap).FirstOrDefault(); client = clientMap.Client; client.CaptureResult = forceCapturedImage; break; case SettingsAppRunMode.MockLauncher: clientMap = (from ClientMap in this.ClientMapping where ClientMap.ProcessType == "launcher" select ClientMap).FirstOrDefault(); client = clientMap.Client; client.CaptureResult = this.mockImage; break; case SettingsAppRunMode.MockGame: clientMap = (from ClientMap in this.ClientMapping where ClientMap.ProcessType == "gameClient" select ClientMap).FirstOrDefault(); client = clientMap.Client; client.CaptureResult = this.mockImage; break; } // client.SetICueBridge(ref iCueBridge); client.FPS = fpsCounter.GetFPS(); client.SetICueBridge(ref this.ICueBridge); if (backgroundWorker.IsBusy != true) { backgroundWorker.RunWorkerAsync(client); } fpsCounter.IncreaseFrame(); } } catch (Exception myException) { frameAnalysisInProgress = false; } finally { frameAnalysisInProgress = false; } }