diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml index 427565ac..3666d73a 100644 --- a/BetterGenshinImpact/View/Pages/HomePage.xaml +++ b/BetterGenshinImpact/View/Pages/HomePage.xaml @@ -188,6 +188,33 @@ Content="测试图像捕获" /> + + + + + + + + + + + + + + @@ -275,6 +302,7 @@ Command="{Binding SelectInstallPathCommand}" Content="浏览" /> + diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs index f1a51860..4b29b600 100644 --- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs +++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs @@ -90,17 +90,6 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware [RelayCommand] private void OnStartCaptureTest() { - //var hWnd = SystemControl.FindGenshinImpactHandle(); - //if (hWnd == IntPtr.Zero) - //{ - // System.Windows.MessageBox.Show("未找到原神窗口"); - // return; - //} - - //CaptureTestWindow captureTestWindow = new(); - //captureTestWindow.StartCapture(hWnd, Config.CaptureMode.ToCaptureMode()); - //captureTestWindow.Show(); - var picker = new PickerWindow(); var hWnd = picker.PickCaptureTarget(new WindowInteropHelper(UIDispatcherHelper.MainWindow).Handle); if (hWnd != IntPtr.Zero) @@ -111,6 +100,21 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware } } + [RelayCommand] + private void OnManualPickWindow() + { + var picker = new PickerWindow(); + var hWnd = picker.PickCaptureTarget(new WindowInteropHelper(UIDispatcherHelper.MainWindow).Handle); + if (hWnd != IntPtr.Zero) + { + Start(hWnd); + } + else + { + System.Windows.MessageBox.Show("选择的窗体句柄为空!"); + } + } + [RelayCommand] private async Task OpenDisplayAdvancedGraphicsSettingsAsync() { @@ -139,6 +143,11 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware } } + Start(hWnd); + } + + private void Start(IntPtr hWnd) + { if (!_taskDispatcherEnabled) { _taskDispatcher.Start(hWnd, Config.CaptureMode.ToCaptureMode(), Config.TriggerInterval); diff --git a/Fischless.GameCapture/Graphics/GraphicsCapture.cs b/Fischless.GameCapture/Graphics/GraphicsCapture.cs index 065abaf8..1ddbe861 100644 --- a/Fischless.GameCapture/Graphics/GraphicsCapture.cs +++ b/Fischless.GameCapture/Graphics/GraphicsCapture.cs @@ -21,7 +21,7 @@ public class GraphicsCapture : IGameCapture private ResourceRegion? _region; - private Bitmap _currentBitmap; + private Bitmap? _currentBitmap; public void Dispose() => Stop(); @@ -126,6 +126,11 @@ public class GraphicsCapture : IGameCapture // } // // return null; + + if (_currentBitmap == null) + { + return null; + } return (Bitmap)_currentBitmap.Clone(); }