Переглянути джерело

摄像头打开时禁止设备检测

优化摄像头显示逻辑
master
张剑 1 рік тому
джерело
коміт
e46a5dec45

+ 2
- 2
XHWK.WKTool/App.config Переглянути файл

@@ -9,8 +9,8 @@
9 9
     <!--参数是否加密 0不加密 1加密-->
10 10
     <add key="IsParameterEncryption" value="0" />
11 11
     <!--版本号-->
12
-    <add key="VersionCode" value="122" />
13
-    <add key="VersionName" value="3.9.5" />
12
+    <add key="VersionCode" value="123" />
13
+    <add key="VersionName" value="3.9.6" />
14 14
     <!--皮肤样式 0白 1蓝 2黑色 -->
15 15
     <add key="SkinStyle" value="0" />
16 16
     <!--是否输出视频记录日志:0否-->

+ 4
- 5
XHWK.WKTool/MainWindow.xaml.cs Переглянути файл

@@ -1036,7 +1036,7 @@ namespace XHWK.WKTool
1036 1036
                 (
1037 1037
                     () =>
1038 1038
                     {
1039
-                        Thread.Sleep(500);
1039
+                        Thread.Sleep(300);
1040 1040
                         _isPressButton = false;
1041 1041
                     }
1042 1042
                 );
@@ -1062,13 +1062,12 @@ namespace XHWK.WKTool
1062 1062
         /// </param>
1063 1063
         /// <param name="e">
1064 1064
         /// </param>
1065
-        private async void BtnDevice_Click(object sender, RoutedEventArgs e)
1065
+        private void BtnDevice_Click(object sender, RoutedEventArgs e)
1066 1066
         {
1067 1067
             if (_isRbnOpen)
1068 1068
             {
1069
-                RbnTurnOff.IsChecked = true;
1070
-                RbnTurnOff_Click(null, null);
1071
-                await Task.Delay(1000);
1069
+                MessageWindow.Show("请从应用右下角关闭摄像头后再进行设备检测!");
1070
+                return;
1072 1071
             }
1073 1072
             DeviceWindow deviceWin = new DeviceWindow();
1074 1073
             deviceWin.ShowDialog();

+ 2
- 2
XHWK.WKTool/Utils/ZAudioRecordHelper.cs Переглянути файл

@@ -142,7 +142,7 @@ namespace XHWK.WKTool.Utils
142 142
         public static bool IsDeviceGood(RecordType type)
143 143
         {
144 144
             string tempPath = Path.GetTempPath();
145
-            Console.WriteLine("临时路径:" + tempPath);
145
+            // Console.WriteLine("临时路径:" + tempPath);
146 146
             WaveInEvent mWaveIn = null;
147 147
             WaveFileWriter mWriter = null;
148 148
             WasapiLoopbackCapture mCapture = null;
@@ -219,4 +219,4 @@ namespace XHWK.WKTool.Utils
219 219
             return true;
220 220
         }
221 221
     }
222
-}
222
+}

+ 13
- 63
XHWK.WKTool/system/CameraHelper.cs Переглянути файл

@@ -2,21 +2,16 @@
2 2
 {
3 3
     using System;
4 4
     using System.Collections.Generic;
5
-    using System.Drawing;
6 5
     using System.Drawing.Imaging;
7 6
     using System.IO;
8 7
     using System.Windows.Media.Imaging;
9 8
     using System.Windows.Threading;
10
-    using AForge.Controls;
11 9
     using AForge.Video.DirectShow;
12 10
 
13 11
     public static class CameraHelper
14 12
     {
15 13
         private static List<FilterInfo> _cameraDevices;
16
-        private static VideoCaptureDevice _div;
17
-        private static readonly VideoSourcePlayer SourcePlayer = new VideoSourcePlayer();
18
-
19
-        //指示_isDisplay设置为true后,是否设置了其他的sourcePlayer,若未设置则_isDisplay重设为false
14
+        private static VideoCaptureDevice _vedioCapture;
20 15
 
21 16
         private static Dispatcher _dispatcher;
22 17
         public static Action<BitmapImage> imageCallback;
@@ -68,15 +63,13 @@
68 63
                 return false;
69 64
             }
70 65
             // 设定初始视频设备
71
-            _div = new VideoCaptureDevice(_cameraDevices[index].MonikerString);
72
-            _div.NewFrame += _div_NewFrame;
73
-            SourcePlayer.VideoSource = _div;
74
-            _div.Start();
75
-            SourcePlayer.Start();
66
+            _vedioCapture = new VideoCaptureDevice(_cameraDevices[index].MonikerString);
67
+            _vedioCapture.NewFrame += VedioCaptureNewFrame;
68
+            _vedioCapture.Start();
76 69
             return true;
77 70
         }
78 71
 
79
-        private static void _div_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
72
+        private static void VedioCaptureNewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
80 73
         {
81 74
             _dispatcher?.Invoke
82 75
             (
@@ -96,68 +89,25 @@
96 89
         }
97 90
 
98 91
         /// <summary>
99
-        /// 截取一帧图像并保存
92
+        /// 关闭摄像头设备
100 93
         /// </summary>
101
-        /// <param name="filePath">图像保存路径</param>
102
-        /// <param name="fileName">保存的图像文件名</param>
103
-        /// <returns>如果保存成功,则返回完整路径,否则为 null</returns>
104
-        public static string CaptureImage(string filePath, string fileName = null)
94
+        public static void CloseDevice()
105 95
         {
106
-            if (SourcePlayer.VideoSource == null)
107
-            {
108
-                return null;
109
-            }
110
-            if (!Directory.Exists(filePath))
111
-            {
112
-                Directory.CreateDirectory(filePath);
113
-            }
114 96
             try
115 97
             {
116
-                Image bitmap = SourcePlayer.GetCurrentVideoFrame();
117
-                if (bitmap != null)
98
+                if (_vedioCapture != null)
118 99
                 {
119
-                    if (fileName == null)
100
+                    _vedioCapture.NewFrame -= VedioCaptureNewFrame;
101
+                    if (_vedioCapture.IsRunning)
120 102
                     {
121
-                        fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
103
+                        _vedioCapture.SignalToStop();
122 104
                     }
123
-                    string fullPath = Path.Combine(filePath, fileName + "-cap.jpg");
124
-                    Bitmap objNewPic = new Bitmap
125
-                    (
126
-                        bitmap,
127
-                        172,
128
-                        124
129
-                    ); //图片保存的大小尺寸  
130
-                    objNewPic.Save(fullPath, ImageFormat.Jpeg);
131
-                    //bitmap.Save(fullPath, ImageFormat.Jpeg);
132
-                    bitmap.Dispose();
133
-                    objNewPic.Dispose();
134
-                    return fullPath;
105
+                    _vedioCapture = null;
135 106
                 }
136
-                return null;
137 107
             }
138 108
             catch (Exception)
139 109
             {
140
-                return null;
141
-            }
142
-        }
143
-
144
-        /// <summary>
145
-        /// 关闭摄像头设备
146
-        /// </summary>
147
-        public static void CloseDevice()
148
-        {
149
-            if (_div != null)
150
-            {
151
-                _div.NewFrame -= _div_NewFrame;
152
-                if (SourcePlayer.IsRunning)
153
-                {
154
-                    SourcePlayer.Stop();
155
-                }
156
-                if (_div.IsRunning)
157
-                {
158
-                    _div.SignalToStop();
159
-                }
160
-                _div = null;
110
+                // ignored
161 111
             }
162 112
         }
163 113
     }

+ 1
- 1
星火微课/星火微课-测试.iss Переглянути файл

@@ -3,7 +3,7 @@
3 3
 
4 4
 #define MyAppName "星火微课测试版"  
5 5
 #define MyAppDir "xhwk_test"
6
-#define MyAppVersion "3.9.5"
6
+#define MyAppVersion "3.9.6"
7 7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8 8
 #define MyAppURL "http://www.xhkjedu.com/"
9 9
 #define MySourcePath "D:\Project\CSharp\xh-wkclient\XHWK.WKTool\bin\x86\Debug\"

Завантаження…
Відмінити
Зберегти