Browse Source

zhao:1解决录制不全的问题,2解决录制时间不准画面和声音有偏差的问题

tags/录制修改前
耀 4 years ago
parent
commit
8f3b2b3a73

+ 1
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml View File

257
                     </StackPanel>
257
                     </StackPanel>
258
                 </Button>
258
                 </Button>
259
             </StackPanel>
259
             </StackPanel>
260
-        </Grid>
260
+            </Grid>
261
 
261
 
262
         <!--主内容-->
262
         <!--主内容-->
263
         <Grid Grid.Row="1" x:Name="GridMain" Visibility="Visible">
263
         <Grid Grid.Row="1" x:Name="GridMain" Visibility="Visible">

+ 54
- 15
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

2191
                     #endregion
2191
                     #endregion
2192
                     IsFirstR = false;
2192
                     IsFirstR = false;
2193
                     RsImgName = new List<string>();
2193
                     RsImgName = new List<string>();
2194
-                    ///启动截图
2195
-                    timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 200);
2196
                     SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
2194
                     SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
2195
+                    ///启动截图
2196
+                    timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
2197
                     //{
2197
                     //{
2198
                     //    AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
2198
                     //    AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
2199
                     //};//设置执行一次(false)还是一直执行(true)
2199
                     //};//设置执行一次(false)还是一直执行(true)
2233
                         Thread.Sleep(1000);
2233
                         Thread.Sleep(1000);
2234
                         Dispatcher.Invoke(() =>
2234
                         Dispatcher.Invoke(() =>
2235
                         {
2235
                         {
2236
+                            Recorddt = DateTime.Now;
2236
                             IsStartCount = true;
2237
                             IsStartCount = true;
2237
                             //Stack();
2238
                             //Stack();
2238
                             //timer.Start();
2239
                             //timer.Start();
2288
             }
2289
             }
2289
         }
2290
         }
2290
         /// <summary>
2291
         /// <summary>
2291
-        /// 录制保存图片
2292
+        /// 记录上次截图时间
2293
+        /// </summary>
2294
+        DateTime Recorddt = DateTime.Now;
2295
+        /// <summary>
2296
+        /// 录制保存图片计时器
2292
         /// </summary>
2297
         /// </summary>
2293
         /// <param name="sender"></param>
2298
         /// <param name="sender"></param>
2294
         private void Timer_Elapsed(object sender)
2299
         private void Timer_Elapsed(object sender)
2295
         {
2300
         {
2296
             if (IsStartCount)
2301
             if (IsStartCount)
2297
             {
2302
             {
2298
-                try
2303
+                DateTime dt = DateTime.Now;
2304
+                TimeSpan ts = dt.Subtract(Recorddt);//时间差   
2305
+                double tsmi = ts.TotalMilliseconds;
2306
+                if (tsmi > 200.0)
2299
                 {
2307
                 {
2300
-                    Dispatcher.Invoke(() =>
2308
+                    Recorddt = Recorddt.AddMilliseconds(200);
2309
+                    Thread thread = new Thread(RecordSaveImage);
2310
+                    //开启线程
2311
+                    thread.Start();
2312
+                }
2313
+            }
2314
+        }
2315
+        /// <summary>
2316
+        /// 录制保存图片
2317
+        /// </summary>
2318
+        void RecordSaveImage()
2319
+        {
2320
+            try
2321
+            {
2322
+                Dispatcher.Invoke(() =>
2323
+                {
2324
+                    if (IsStartCount)
2301
                     {
2325
                     {
2302
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
2326
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
2303
                         RsImgName.Add(FilePathName);
2327
                         RsImgName.Add(FilePathName);
2304
-                        ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)ActualWidth, (int)ActualHeight);
2305
-                        SRTime=SRTime.AddMilliseconds(200);
2328
+                        ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)));
2329
+                        SRTime = SRTime.AddMilliseconds(200);
2330
+                        if (txbTime.Visibility == Visibility.Hidden)
2331
+                        {
2332
+                            txbTime.Visibility = Visibility.Visible;
2333
+                        }
2306
                         if (SRTime.Hour > 0)
2334
                         if (SRTime.Hour > 0)
2307
                         {
2335
                         {
2336
+                            //Dispatcher.Invoke(() =>
2337
+                            //{
2308
                             txbTime.Text = SRTime.ToString("HH:mm:ss");
2338
                             txbTime.Text = SRTime.ToString("HH:mm:ss");
2339
+                            //});
2309
                         }
2340
                         }
2310
                         else
2341
                         else
2311
                         {
2342
                         {
2343
+                            //Dispatcher.Invoke(() =>
2344
+                            //{
2312
                             txbTime.Text = SRTime.ToString("mm:ss");
2345
                             txbTime.Text = SRTime.ToString("mm:ss");
2346
+                            //});
2313
                         }
2347
                         }
2314
-                    });
2315
-                }
2316
-                catch (Exception ex)
2317
-                {
2318
-                    LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
2319
-                }
2348
+                    }
2349
+                });
2350
+            }
2351
+            catch (Exception ex)
2352
+            {
2353
+                LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
2320
             }
2354
             }
2321
         }
2355
         }
2322
-
2323
         /// <summary>
2356
         /// <summary>
2324
         /// 停止录制并生成录制文件
2357
         /// 停止录制并生成录制文件
2325
         /// </summary>
2358
         /// </summary>
2412
                     APP.FFmpeg.StopFFmpeg(AudioPathName);
2445
                     APP.FFmpeg.StopFFmpeg(AudioPathName);
2413
                     new Thread(new ThreadStart(new Action(() =>
2446
                     new Thread(new ThreadStart(new Action(() =>
2414
                     {
2447
                     {
2448
+                        IsStartCount = false;
2415
                         //停止截图
2449
                         //停止截图
2416
                         while (APP.FFmpeg.myProcess != null)
2450
                         while (APP.FFmpeg.myProcess != null)
2417
                         {
2451
                         {
2419
                         }
2453
                         }
2420
                         Dispatcher.Invoke(() =>
2454
                         Dispatcher.Invoke(() =>
2421
                         {
2455
                         {
2422
-                            IsStartCount = false;
2423
                             timer.Change(-1, 0);
2456
                             timer.Change(-1, 0);
2424
                             timer.Dispose();
2457
                             timer.Dispose();
2425
                                     //End();
2458
                                     //End();
4059
         {
4092
         {
4060
             Thread.Sleep(2000);
4093
             Thread.Sleep(2000);
4061
         }
4094
         }
4095
+
4096
+        private void Button_Click_2(object sender, RoutedEventArgs e)
4097
+        {
4098
+            
4099
+            MessageWindow.Show("A:"+ActualWidth*(PrimaryScreen.DpiX / 96f)+"x" +ActualHeight * (PrimaryScreen.DpiY / 96f) + "  wh:"+Width+"x"+Height);
4100
+        }
4062
     }
4101
     }
4063
 }
4102
 }

Loading…
Cancel
Save