From 432cc3825e360cd453c569765d898d9ea9d45374 Mon Sep 17 00:00:00 2001 From: CJKmkp <2564608840@qq.com> Date: Thu, 19 Feb 2026 18:18:47 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=B1=95=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ink Canvas/MainWindow.xaml | 31 +++++++++-------- Ink Canvas/MainWindow.xaml.cs | 18 ++++++++++ Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs | 33 ++++++++++++++++--- 3 files changed, 61 insertions(+), 21 deletions(-) diff --git a/Ink Canvas/MainWindow.xaml b/Ink Canvas/MainWindow.xaml index a37ed2b8..13c5e9fd 100644 --- a/Ink Canvas/MainWindow.xaml +++ b/Ink Canvas/MainWindow.xaml @@ -4964,24 +4964,23 @@ - - - - - - - - - - - - + + diff --git a/Ink Canvas/MainWindow.xaml.cs b/Ink Canvas/MainWindow.xaml.cs index b205f2c0..a9a87c7e 100644 --- a/Ink Canvas/MainWindow.xaml.cs +++ b/Ink Canvas/MainWindow.xaml.cs @@ -1481,6 +1481,24 @@ namespace Ink_Canvas { SystemEvents.DisplaySettingsChanged -= SystemEventsOnDisplaySettingsChanged; + try + { + // 清理视频展台资源 + if (_cameraService != null) + { + _cameraService.FrameReceived -= CameraService_FrameReceived; + _cameraService.ErrorOccurred -= CameraService_ErrorOccurred; + _cameraService.Dispose(); + _cameraService = null; + } + lock (_videoPresenterFrameLock) + { + _lastFrame?.Dispose(); + _lastFrame = null; + } + } + catch { } + // 释放PPT管理器资源 DisposePPTManagers(); diff --git a/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs b/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs index 03183f60..c43fd3d5 100644 --- a/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs +++ b/Ink Canvas/MainWindow_cs/MW_VideoPresenter.cs @@ -46,6 +46,7 @@ namespace Ink_Canvas VideoPresenterSidebar.Visibility = Visibility.Visible; EnsureCameraService(); + if (BtnCapturePhoto != null) BtnCapturePhoto.IsEnabled = false; RefreshVideoPresenterDeviceList(); if (CheckBoxEnablePhotoCorrection != null) @@ -86,16 +87,25 @@ namespace Ink_Canvas try { - Bitmap copy; + Bitmap serviceCopy; + try + { + serviceCopy = (Bitmap)frame.Clone(); + } + catch + { + // 可能在下一帧到来时被 CameraService 释放,直接忽略这一帧 + return; + } + lock (_videoPresenterFrameLock) { _lastFrame?.Dispose(); - _lastFrame = (Bitmap)frame.Clone(); - copy = (Bitmap)_lastFrame.Clone(); + _lastFrame = (Bitmap)serviceCopy.Clone(); } - var preview = ConvertBitmapToBitmapImage(copy); - copy.Dispose(); + var preview = ConvertBitmapToBitmapImage(serviceCopy); + serviceCopy.Dispose(); if (preview == null) return; Dispatcher.BeginInvoke(new Action(() => @@ -154,6 +164,19 @@ namespace Ink_Canvas rb.Checked += (s, e) => StartVideoPresenterPreview(idx); CameraDevicesStackPanel.Children.Add(rb); } + + // 自动启动第一个摄像头 + if (_cameraService.AvailableCameras.Count > 0) + { + if (CameraDevicesStackPanel.Children.Count > 0 && CameraDevicesStackPanel.Children[0] is RadioButton first) + { + first.IsChecked = true; + } + else + { + StartVideoPresenterPreview(0); + } + } } private void StartVideoPresenterPreview(int cameraIndex)