星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ScreenRecordingToolbarWindow.xaml.cs 19KB

4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. IsFirstRS = false;
  175. }
  176. IsSuspend = false;
  177. //#region 录像倒计时
  178. //if (APP.W_CountdownWindow == null)
  179. //{
  180. // APP.W_CountdownWindow = new CountdownWindow();
  181. // //APP.W_CountdownWindow.Topmost = true;
  182. //}
  183. //else
  184. //{
  185. // APP.W_CountdownWindow.Initialize();
  186. // //APP.W_CountdownWindow.Topmost = true;
  187. //}
  188. //APP.W_CountdownWindow.Show();
  189. //#endregion
  190. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  191. try
  192. {
  193. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  194. }
  195. catch (Exception ex)
  196. {
  197. MessageBox.Show(ex.Message);
  198. }
  199. }
  200. else
  201. {
  202. TimeOut();
  203. IsSuspend = true;
  204. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  205. try
  206. {
  207. APP.FFmpeg.SuspendFFmpeg();
  208. }
  209. catch (Exception ex)
  210. {
  211. MessageBox.Show(ex.Message);
  212. }
  213. }
  214. }
  215. /// <summary>
  216. /// 停止录像
  217. /// </summary>
  218. /// <param name="sender"></param>
  219. /// <param name="e"></param>
  220. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  221. {
  222. IsSuspend = true;
  223. txbTime.Text = "00:00";
  224. End();
  225. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  226. if (gridToolbar.Visibility==Visibility.Visible)
  227. {
  228. gridToolbar.Visibility = Visibility.Hidden;
  229. gridColour.Visibility = Visibility.Hidden;
  230. gridThickness.Visibility = Visibility.Hidden;
  231. APP.W_PracticeWindow.Hide();
  232. }
  233. if (APP.W_XHMicroLessonSystemWindow == null)
  234. {
  235. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  236. }
  237. APP.W_XHMicroLessonSystemWindow.Show();
  238. if (!IsFirstRS)
  239. {
  240. try
  241. {
  242. try
  243. {
  244. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  245. }
  246. catch (Exception ex)
  247. {
  248. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  249. }
  250. IsFirstRS = true;
  251. //生成缩略图
  252. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  253. FileToolsCommon.CreateDirectory(ThumbnailPath);
  254. //缩略图存储位置
  255. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  256. new Thread(new ThreadStart(new Action(() =>
  257. {
  258. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  259. {
  260. Thread.Sleep(100);
  261. }
  262. FileToolsCommon.DeleteFile(ThumbnailPathName);
  263. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  264. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  265. VideoInfo.VideoPath = VideoSavePathName;
  266. VideoInfo.ThumbnailPath = ThumbnailPathName;
  267. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  268. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  269. VideoInfo.IsUpload = false;
  270. VideoInfo.Uploaded = 0;
  271. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  272. APP.VideoList.Add(VideoInfo);
  273. //保存数据
  274. APP.SaveWkData();
  275. }))).Start();
  276. }
  277. catch (Exception ex)
  278. {
  279. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  280. }
  281. }
  282. Hide();
  283. }
  284. #endregion
  285. #region 画笔相关
  286. /// <summary>
  287. /// 画笔工具栏关闭事件
  288. /// </summary>
  289. /// <param name="sender"></param>
  290. /// <param name="e"></param>
  291. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  292. {
  293. gridToolbar.Visibility = Visibility.Hidden;
  294. gridColour.Visibility = Visibility.Hidden;
  295. gridThickness.Visibility = Visibility.Hidden;
  296. APP.W_PracticeWindow.Hide();
  297. }
  298. /// <summary>
  299. /// 画笔点击事件
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  304. {
  305. string time = GetTimeStamp();
  306. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  307. if (!Directory.Exists(tempPath))
  308. {
  309. Directory.CreateDirectory(tempPath);
  310. }
  311. string imagePath = Path.Combine(tempPath, time + ".jpg");
  312. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath);
  313. if (gridToolbar.Visibility == Visibility.Visible)
  314. {
  315. gridToolbar.Visibility = Visibility.Hidden;
  316. }
  317. else
  318. {
  319. gridToolbar.Visibility = Visibility.Visible;
  320. try
  321. {
  322. if (APP.W_PracticeWindow == null)
  323. {
  324. APP.W_PracticeWindow = new PracticeWindow();
  325. //APP.W_PracticeWindow.Topmost = true;
  326. APP.W_PracticeWindow.Width = pwidth;
  327. APP.W_PracticeWindow.Height = pHeight;
  328. APP.W_PracticeWindow.Left = 0;
  329. APP.W_PracticeWindow.Top = 0;
  330. //practiceWin.Owner = this;
  331. }
  332. APP.W_PracticeWindow.Initialize(imagePath);
  333. APP.W_PracticeWindow.Show();
  334. }
  335. catch (Exception ex)
  336. {
  337. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  338. }
  339. }
  340. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  341. }
  342. /// <summary>
  343. /// 屏幕宽
  344. /// </summary>
  345. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  346. /// <summary>
  347. /// 屏幕高
  348. /// </summary>
  349. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  350. /// <summary>
  351. /// 获取时间戳
  352. /// </summary>
  353. /// <returns></returns>
  354. public string GetTimeStamp()
  355. {
  356. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  357. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  358. }
  359. /// <summary>
  360. /// 画笔粗细事件
  361. /// </summary>
  362. /// <param name="sender"></param>
  363. /// <param name="e"></param>
  364. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  365. {
  366. gridThickness.Visibility = Visibility.Visible;
  367. gridColour.Visibility = Visibility.Collapsed;
  368. }
  369. /// <summary>
  370. /// 画笔颜色事件
  371. /// </summary>
  372. /// <param name="sender"></param>
  373. /// <param name="e"></param>
  374. private void BtnColour_Click(object sender, RoutedEventArgs e)
  375. {
  376. gridColour.Visibility = Visibility.Visible;
  377. gridThickness.Visibility = Visibility.Collapsed;
  378. }
  379. /// <summary>
  380. /// 白色
  381. /// </summary>
  382. /// <param name="sender"></param>
  383. /// <param name="e"></param>
  384. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  385. {
  386. //drawingAttributes.Color = Colors.White;
  387. APP.W_PracticeWindow.White();
  388. gridColour.Visibility = Visibility.Collapsed;
  389. gridThickness.Visibility = Visibility.Collapsed;
  390. }
  391. /// <summary>
  392. /// 红色
  393. /// </summary>
  394. /// <param name="sender"></param>
  395. /// <param name="e"></param>
  396. private void BtnRed_Click(object sender, RoutedEventArgs e)
  397. {
  398. //drawingAttributes.Color = Colors.Red;
  399. APP.W_PracticeWindow.Red();
  400. gridColour.Visibility = Visibility.Collapsed;
  401. gridThickness.Visibility = Visibility.Collapsed;
  402. }
  403. /// <summary>
  404. /// 黄色
  405. /// </summary>
  406. /// <param name="sender"></param>
  407. /// <param name="e"></param>
  408. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  409. {
  410. //drawingAttributes.Color = Colors.Gold;
  411. APP.W_PracticeWindow.Yellow();
  412. gridColour.Visibility = Visibility.Collapsed;
  413. gridThickness.Visibility = Visibility.Collapsed;
  414. }
  415. /// <summary>
  416. /// 青色
  417. /// </summary>
  418. /// <param name="sender"></param>
  419. /// <param name="e"></param>
  420. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  421. {
  422. //drawingAttributes.Color = Colors.LimeGreen;
  423. APP.W_PracticeWindow.CyanBlue();
  424. gridColour.Visibility = Visibility.Collapsed;
  425. gridThickness.Visibility = Visibility.Collapsed;
  426. }
  427. /// <summary>
  428. /// 灰色
  429. /// </summary>
  430. /// <param name="sender"></param>
  431. /// <param name="e"></param>
  432. private void BtnGray_Click(object sender, RoutedEventArgs e)
  433. {
  434. //drawingAttributes.Color = Colors.Gray;
  435. APP.W_PracticeWindow.Gray();
  436. gridColour.Visibility = Visibility.Collapsed;
  437. gridThickness.Visibility = Visibility.Collapsed;
  438. }
  439. /// <summary>
  440. /// 蓝色
  441. /// </summary>
  442. /// <param name="sender"></param>
  443. /// <param name="e"></param>
  444. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  445. {
  446. //drawingAttributes.Color = Colors.DeepSkyBlue;
  447. APP.W_PracticeWindow.Blue();
  448. gridColour.Visibility = Visibility.Collapsed;
  449. gridThickness.Visibility = Visibility.Collapsed;
  450. }
  451. /// <summary>
  452. /// 画笔 细
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. private void BtnFine_Click(object sender, RoutedEventArgs e)
  457. {
  458. APP.W_PracticeWindow.Fine();
  459. gridColour.Visibility = Visibility.Collapsed;
  460. gridThickness.Visibility = Visibility.Collapsed;
  461. }
  462. /// <summary>
  463. /// 画笔 中
  464. /// </summary>
  465. /// <param name="sender"></param>
  466. /// <param name="e"></param>
  467. private void BtnIn_Click(object sender, RoutedEventArgs e)
  468. {
  469. APP.W_PracticeWindow.In();
  470. gridColour.Visibility = Visibility.Collapsed;
  471. gridThickness.Visibility = Visibility.Collapsed;
  472. }
  473. /// <summary>
  474. /// 画笔粗
  475. /// </summary>
  476. /// <param name="sender"></param>
  477. /// <param name="e"></param>
  478. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  479. {
  480. APP.W_PracticeWindow.Crude();
  481. gridColour.Visibility = Visibility.Collapsed;
  482. gridThickness.Visibility = Visibility.Collapsed;
  483. }
  484. /// <summary>
  485. /// 橡皮
  486. /// </summary>
  487. /// <param name="sender"></param>
  488. /// <param name="e"></param>
  489. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  490. {
  491. APP.W_PracticeWindow.Eraser();
  492. }
  493. /// <summary>
  494. /// 🖊
  495. /// </summary>
  496. /// <param name="sender"></param>
  497. /// <param name="e"></param>
  498. private void BtnPen_Click(object sender, RoutedEventArgs e)
  499. {
  500. APP.W_PracticeWindow.Pen();
  501. }
  502. /// <summary>
  503. /// ⚪
  504. /// </summary>
  505. /// <param name="sender"></param>
  506. /// <param name="e"></param>
  507. private void BtnRound_Click(object sender, RoutedEventArgs e)
  508. {
  509. APP.W_PracticeWindow.Round();
  510. }
  511. /// <summary>
  512. /// 矩形
  513. /// </summary>
  514. /// <param name="sender"></param>
  515. /// <param name="e"></param>
  516. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  517. {
  518. APP.W_PracticeWindow.Rectangle();
  519. }
  520. #endregion
  521. #endregion
  522. }
  523. }