星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenRecordingToolbarWindow.xaml.cs 20KB

hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
hace 4 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. using Common.system;
  2. using System;
  3. using System.Configuration;
  4. using System.IO;
  5. using System.Threading;
  6. using System.Windows;
  7. using System.Windows.Ink;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using System.Windows.Threading;
  11. using XHWK.Model;
  12. namespace XHWK.WKTool
  13. {
  14. /// <summary>
  15. /// 录屏工具栏
  16. /// </summary>
  17. public partial class ScreenRecordingToolbarWindow : Window
  18. {
  19. #region 初始变量
  20. /// <summary>
  21. /// 视频存储路径
  22. /// </summary>
  23. string RecordingPath;
  24. /// <summary>
  25. /// 视频保存名称
  26. /// </summary>
  27. string VideoSavePathName;
  28. /// <summary>
  29. /// 是否首次录屏
  30. /// </summary>
  31. bool IsFirstRS = true;
  32. /// <summary>
  33. /// 是否暂停
  34. /// </summary>
  35. bool IsSuspend = true;
  36. /// <summary>
  37. /// 视频信息
  38. /// </summary>
  39. Model_Video VideoInfo = null;
  40. //声明一个 DrawingAttributes 类型的变量
  41. DrawingAttributes drawingAttributes;
  42. private DispatcherTimer t = null;
  43. /// <summary>
  44. /// 计时器状态
  45. /// </summary>
  46. private enum State
  47. {
  48. Start,
  49. Pause,
  50. End
  51. }
  52. /// <summary>
  53. /// 状态
  54. /// </summary>
  55. private State _state = State.End;
  56. /// <summary>
  57. /// 计时用
  58. /// </summary>
  59. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  60. #endregion
  61. #region 初始化
  62. /// <summary>
  63. /// 录屏工具栏
  64. /// </summary>
  65. public ScreenRecordingToolbarWindow()
  66. {
  67. InitializeComponent();
  68. }
  69. /// <summary>
  70. /// 初始化
  71. /// </summary>
  72. public void Initialize()
  73. {
  74. //创建 DrawingAttributes 类的一个实例
  75. drawingAttributes = new DrawingAttributes();
  76. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  77. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  78. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  79. drawingAttributes.FitToCurve = true;
  80. //隐藏画笔工具栏
  81. //BtnToolbarDown_Click(null, null);
  82. gridToolbar.Visibility = Visibility.Hidden;
  83. gridColour.Visibility = Visibility.Hidden;
  84. gridThickness.Visibility = Visibility.Hidden;
  85. if (t == null)
  86. {
  87. t = new DispatcherTimer();
  88. t.Tick += OnTimer;
  89. t.Interval = new TimeSpan(0, 0, 0, 1);
  90. t.IsEnabled = true;
  91. t.Start();
  92. }
  93. t.Interval = new TimeSpan(0, 0, 0, 1);
  94. Stack();
  95. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  96. BtnRecordingScreen_Click(null, null);
  97. }
  98. #endregion
  99. #region 事件
  100. /// <summary>
  101. /// 时钟回调
  102. /// </summary>
  103. /// <param name="sender"></param>
  104. /// <param name="e"></param>
  105. private void OnTimer(object sender, EventArgs e)
  106. {
  107. switch (_state)
  108. {
  109. case State.Start:
  110. {
  111. _timeSpan += new TimeSpan(0, 0, 0, 1);
  112. }
  113. break;
  114. case State.Pause:
  115. {
  116. }
  117. break;
  118. case State.End:
  119. {
  120. _timeSpan = new TimeSpan();
  121. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  122. }
  123. break;
  124. }
  125. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  126. //char[] times = time.ToCharArray();
  127. txbTime.Text = time;
  128. }
  129. /// <summary>
  130. /// 开始
  131. /// </summary>
  132. /// <param name="sender"></param>
  133. /// <param name="e"></param>
  134. private void Stack()
  135. {
  136. _state = State.Start;
  137. }
  138. /// <summary>
  139. /// 暂停
  140. /// </summary>
  141. private void TimeOut()
  142. {
  143. _state = State.Pause;
  144. }
  145. /// <summary>
  146. /// 结束
  147. /// </summary>
  148. /// <param name="sender"></param>
  149. /// <param name="e"></param>
  150. private void End()
  151. {
  152. _state = State.End;
  153. }
  154. #region 录制
  155. /// <summary>
  156. /// 开始或暂停录制
  157. /// </summary>
  158. /// <param name="sender"></param>
  159. /// <param name="e"></param>
  160. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  161. {
  162. if (IsSuspend)
  163. {
  164. Stack();
  165. if (IsFirstRS)
  166. {
  167. VideoInfo = new Model_Video();
  168. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  169. VideoInfo.WkType = Enum_WKVidetype.RecordingScreen;
  170. RecordingPath = APP.WKData.WkPath;
  171. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  172. FileToolsCommon.CreateDirectory(RecordingPath);
  173. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  174. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  175. {
  176. MessageBoxResult dr = System.Windows.MessageBox.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  177. if (dr == MessageBoxResult.OK)
  178. {
  179. try
  180. {
  181. FileToolsCommon.DeleteFile(VideoSavePathName);
  182. APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  183. }
  184. catch (Exception ex)
  185. {
  186. LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  187. }
  188. }
  189. else
  190. {
  191. return;
  192. }
  193. }
  194. IsFirstRS = false;
  195. }
  196. IsSuspend = false;
  197. //#region 录像倒计时
  198. //if (APP.W_CountdownWindow == null)
  199. //{
  200. // APP.W_CountdownWindow = new CountdownWindow();
  201. // //APP.W_CountdownWindow.Topmost = true;
  202. //}
  203. //else
  204. //{
  205. // APP.W_CountdownWindow.Initialize();
  206. // //APP.W_CountdownWindow.Topmost = true;
  207. //}
  208. //APP.W_CountdownWindow.Show();
  209. //#endregion
  210. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  211. try
  212. {
  213. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  214. }
  215. catch (Exception ex)
  216. {
  217. MessageBox.Show(ex.Message);
  218. }
  219. }
  220. else
  221. {
  222. TimeOut();
  223. IsSuspend = true;
  224. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  225. try
  226. {
  227. APP.FFmpeg.SuspendFFmpeg();
  228. }
  229. catch (Exception ex)
  230. {
  231. MessageBox.Show(ex.Message);
  232. }
  233. }
  234. }
  235. /// <summary>
  236. /// 停止录像
  237. /// </summary>
  238. /// <param name="sender"></param>
  239. /// <param name="e"></param>
  240. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  241. {
  242. IsSuspend = true;
  243. txbTime.Text = "00:00";
  244. End();
  245. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  246. if (gridToolbar.Visibility==Visibility.Visible)
  247. {
  248. gridToolbar.Visibility = Visibility.Hidden;
  249. gridColour.Visibility = Visibility.Hidden;
  250. gridThickness.Visibility = Visibility.Hidden;
  251. APP.W_PracticeWindow.Hide();
  252. }
  253. if (APP.W_XHMicroLessonSystemWindow == null)
  254. {
  255. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  256. }
  257. APP.W_XHMicroLessonSystemWindow.Show();
  258. if (!IsFirstRS)
  259. {
  260. try
  261. {
  262. try
  263. {
  264. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  265. }
  266. catch (Exception ex)
  267. {
  268. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  269. }
  270. IsFirstRS = true;
  271. //生成缩略图
  272. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  273. FileToolsCommon.CreateDirectory(ThumbnailPath);
  274. //缩略图存储位置
  275. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  276. new Thread(new ThreadStart(new Action(() =>
  277. {
  278. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  279. {
  280. Thread.Sleep(100);
  281. }
  282. FileToolsCommon.DeleteFile(ThumbnailPathName);
  283. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  284. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  285. VideoInfo.VideoPath = VideoSavePathName;
  286. VideoInfo.ThumbnailPath = ThumbnailPathName;
  287. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  288. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  289. VideoInfo.IsUpload = false;
  290. VideoInfo.Uploaded = 0;
  291. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  292. APP.VideoList.Add(VideoInfo);
  293. //保存数据
  294. APP.SaveWkData();
  295. }))).Start();
  296. }
  297. catch (Exception ex)
  298. {
  299. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  300. }
  301. }
  302. Hide();
  303. }
  304. #endregion
  305. #region 画笔相关
  306. /// <summary>
  307. /// 画笔工具栏关闭事件
  308. /// </summary>
  309. /// <param name="sender"></param>
  310. /// <param name="e"></param>
  311. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  312. {
  313. gridToolbar.Visibility = Visibility.Hidden;
  314. gridColour.Visibility = Visibility.Hidden;
  315. gridThickness.Visibility = Visibility.Hidden;
  316. APP.W_PracticeWindow.Hide();
  317. }
  318. /// <summary>
  319. /// 画笔点击事件
  320. /// </summary>
  321. /// <param name="sender"></param>
  322. /// <param name="e"></param>
  323. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  324. {
  325. string time = GetTimeStamp();
  326. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  327. if (!Directory.Exists(tempPath))
  328. {
  329. Directory.CreateDirectory(tempPath);
  330. }
  331. string imagePath = Path.Combine(tempPath, time + ".jpg");
  332. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath);
  333. if (gridToolbar.Visibility == Visibility.Visible)
  334. {
  335. gridToolbar.Visibility = Visibility.Hidden;
  336. }
  337. else
  338. {
  339. gridToolbar.Visibility = Visibility.Visible;
  340. try
  341. {
  342. if (APP.W_PracticeWindow == null)
  343. {
  344. APP.W_PracticeWindow = new PracticeWindow();
  345. //APP.W_PracticeWindow.Topmost = true;
  346. APP.W_PracticeWindow.Width = pwidth;
  347. APP.W_PracticeWindow.Height = pHeight;
  348. APP.W_PracticeWindow.Left = 0;
  349. APP.W_PracticeWindow.Top = 0;
  350. //practiceWin.Owner = this;
  351. }
  352. APP.W_PracticeWindow.Initialize(imagePath);
  353. APP.W_PracticeWindow.Show();
  354. }
  355. catch (Exception ex)
  356. {
  357. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  358. }
  359. }
  360. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  361. }
  362. /// <summary>
  363. /// 屏幕宽
  364. /// </summary>
  365. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  366. /// <summary>
  367. /// 屏幕高
  368. /// </summary>
  369. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  370. /// <summary>
  371. /// 获取时间戳
  372. /// </summary>
  373. /// <returns></returns>
  374. public string GetTimeStamp()
  375. {
  376. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  377. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  378. }
  379. /// <summary>
  380. /// 画笔粗细事件
  381. /// </summary>
  382. /// <param name="sender"></param>
  383. /// <param name="e"></param>
  384. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  385. {
  386. gridThickness.Visibility = Visibility.Visible;
  387. gridColour.Visibility = Visibility.Collapsed;
  388. }
  389. /// <summary>
  390. /// 画笔颜色事件
  391. /// </summary>
  392. /// <param name="sender"></param>
  393. /// <param name="e"></param>
  394. private void BtnColour_Click(object sender, RoutedEventArgs e)
  395. {
  396. gridColour.Visibility = Visibility.Visible;
  397. gridThickness.Visibility = Visibility.Collapsed;
  398. }
  399. /// <summary>
  400. /// 白色
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  405. {
  406. //drawingAttributes.Color = Colors.White;
  407. APP.W_PracticeWindow.White();
  408. gridColour.Visibility = Visibility.Collapsed;
  409. gridThickness.Visibility = Visibility.Collapsed;
  410. }
  411. /// <summary>
  412. /// 红色
  413. /// </summary>
  414. /// <param name="sender"></param>
  415. /// <param name="e"></param>
  416. private void BtnRed_Click(object sender, RoutedEventArgs e)
  417. {
  418. //drawingAttributes.Color = Colors.Red;
  419. APP.W_PracticeWindow.Red();
  420. gridColour.Visibility = Visibility.Collapsed;
  421. gridThickness.Visibility = Visibility.Collapsed;
  422. }
  423. /// <summary>
  424. /// 黄色
  425. /// </summary>
  426. /// <param name="sender"></param>
  427. /// <param name="e"></param>
  428. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  429. {
  430. //drawingAttributes.Color = Colors.Gold;
  431. APP.W_PracticeWindow.Yellow();
  432. gridColour.Visibility = Visibility.Collapsed;
  433. gridThickness.Visibility = Visibility.Collapsed;
  434. }
  435. /// <summary>
  436. /// 青色
  437. /// </summary>
  438. /// <param name="sender"></param>
  439. /// <param name="e"></param>
  440. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  441. {
  442. //drawingAttributes.Color = Colors.LimeGreen;
  443. APP.W_PracticeWindow.CyanBlue();
  444. gridColour.Visibility = Visibility.Collapsed;
  445. gridThickness.Visibility = Visibility.Collapsed;
  446. }
  447. /// <summary>
  448. /// 灰色
  449. /// </summary>
  450. /// <param name="sender"></param>
  451. /// <param name="e"></param>
  452. private void BtnGray_Click(object sender, RoutedEventArgs e)
  453. {
  454. //drawingAttributes.Color = Colors.Gray;
  455. APP.W_PracticeWindow.Gray();
  456. gridColour.Visibility = Visibility.Collapsed;
  457. gridThickness.Visibility = Visibility.Collapsed;
  458. }
  459. /// <summary>
  460. /// 蓝色
  461. /// </summary>
  462. /// <param name="sender"></param>
  463. /// <param name="e"></param>
  464. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  465. {
  466. //drawingAttributes.Color = Colors.DeepSkyBlue;
  467. APP.W_PracticeWindow.Blue();
  468. gridColour.Visibility = Visibility.Collapsed;
  469. gridThickness.Visibility = Visibility.Collapsed;
  470. }
  471. /// <summary>
  472. /// 画笔 细
  473. /// </summary>
  474. /// <param name="sender"></param>
  475. /// <param name="e"></param>
  476. private void BtnFine_Click(object sender, RoutedEventArgs e)
  477. {
  478. APP.W_PracticeWindow.Fine();
  479. gridColour.Visibility = Visibility.Collapsed;
  480. gridThickness.Visibility = Visibility.Collapsed;
  481. }
  482. /// <summary>
  483. /// 画笔 中
  484. /// </summary>
  485. /// <param name="sender"></param>
  486. /// <param name="e"></param>
  487. private void BtnIn_Click(object sender, RoutedEventArgs e)
  488. {
  489. APP.W_PracticeWindow.In();
  490. gridColour.Visibility = Visibility.Collapsed;
  491. gridThickness.Visibility = Visibility.Collapsed;
  492. }
  493. /// <summary>
  494. /// 画笔粗
  495. /// </summary>
  496. /// <param name="sender"></param>
  497. /// <param name="e"></param>
  498. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  499. {
  500. APP.W_PracticeWindow.Crude();
  501. gridColour.Visibility = Visibility.Collapsed;
  502. gridThickness.Visibility = Visibility.Collapsed;
  503. }
  504. /// <summary>
  505. /// 橡皮
  506. /// </summary>
  507. /// <param name="sender"></param>
  508. /// <param name="e"></param>
  509. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  510. {
  511. APP.W_PracticeWindow.Eraser();
  512. }
  513. /// <summary>
  514. /// 🖊
  515. /// </summary>
  516. /// <param name="sender"></param>
  517. /// <param name="e"></param>
  518. private void BtnPen_Click(object sender, RoutedEventArgs e)
  519. {
  520. APP.W_PracticeWindow.Pen();
  521. }
  522. /// <summary>
  523. /// ⚪
  524. /// </summary>
  525. /// <param name="sender"></param>
  526. /// <param name="e"></param>
  527. private void BtnRound_Click(object sender, RoutedEventArgs e)
  528. {
  529. APP.W_PracticeWindow.Round();
  530. }
  531. /// <summary>
  532. /// 矩形
  533. /// </summary>
  534. /// <param name="sender"></param>
  535. /// <param name="e"></param>
  536. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  537. {
  538. APP.W_PracticeWindow.Rectangle();
  539. }
  540. #endregion
  541. #endregion
  542. }
  543. }