星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ScreenRecordingToolbarWindow.xaml.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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 XHWK.Model;
  11. namespace XHWK.WKTool
  12. {
  13. /// <summary>
  14. /// 录屏工具栏
  15. /// </summary>
  16. public partial class ScreenRecordingToolbarWindow : Window
  17. {
  18. #region 初始变量
  19. /// <summary>
  20. /// 视频存储路径
  21. /// </summary>
  22. string RecordingPath;
  23. /// <summary>
  24. /// 视频保存名称
  25. /// </summary>
  26. string VideoSavePathName;
  27. /// <summary>
  28. /// 是否首次录屏
  29. /// </summary>
  30. bool IsFirstRS = true;
  31. /// <summary>
  32. /// 是否暂停
  33. /// </summary>
  34. bool IsSuspend = true;
  35. /// <summary>
  36. /// 视频信息
  37. /// </summary>
  38. Model_Video VideoInfo = null;
  39. //声明一个 DrawingAttributes 类型的变量
  40. DrawingAttributes drawingAttributes;
  41. #endregion
  42. #region 初始化
  43. /// <summary>
  44. /// 录屏工具栏
  45. /// </summary>
  46. public ScreenRecordingToolbarWindow()
  47. {
  48. InitializeComponent();
  49. }
  50. /// <summary>
  51. /// 初始化
  52. /// </summary>
  53. public void Initialize()
  54. {
  55. //创建 DrawingAttributes 类的一个实例
  56. drawingAttributes = new DrawingAttributes();
  57. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  58. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  59. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  60. drawingAttributes.FitToCurve = true;
  61. //隐藏画笔工具栏
  62. //BtnToolbarDown_Click(null, null);
  63. gridToolbar.Visibility = Visibility.Hidden;
  64. gridColour.Visibility = Visibility.Hidden;
  65. gridThickness.Visibility = Visibility.Hidden;
  66. }
  67. #endregion
  68. #region 事件
  69. #region 录制
  70. /// <summary>
  71. /// 开始或暂停录制
  72. /// </summary>
  73. /// <param name="sender"></param>
  74. /// <param name="e"></param>
  75. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  76. {
  77. if (IsSuspend)
  78. {
  79. if (IsFirstRS)
  80. {
  81. VideoInfo = new Model_Video();
  82. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  83. VideoInfo.WkType = Enum_WKVidetype.RecordingScreen;
  84. RecordingPath = APP.WKData.WkPath;
  85. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  86. FileToolsCommon.CreateDirectory(RecordingPath);
  87. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  88. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  89. {
  90. MessageBoxResult dr = System.Windows.MessageBox.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  91. if (dr == MessageBoxResult.OK)
  92. {
  93. try
  94. {
  95. FileToolsCommon.DeleteFile(VideoSavePathName);
  96. APP.VideoList.RemoveAll(x => x.VidePath == VideoSavePathName);
  97. }
  98. catch (Exception ex)
  99. {
  100. LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  101. }
  102. }
  103. else
  104. {
  105. return;
  106. }
  107. }
  108. IsFirstRS = false;
  109. }
  110. IsSuspend = false;
  111. #region 录像倒计时
  112. if (APP.W_CountdownWindow == null)
  113. {
  114. APP.W_CountdownWindow = new CountdownWindow();
  115. //APP.W_CountdownWindow.Topmost = true;
  116. }
  117. else
  118. {
  119. APP.W_CountdownWindow.Initialize();
  120. //APP.W_CountdownWindow.Topmost = true;
  121. }
  122. APP.W_CountdownWindow.Show();
  123. #endregion
  124. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  125. try
  126. {
  127. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  128. }
  129. catch (Exception ex)
  130. {
  131. MessageBox.Show(ex.Message);
  132. }
  133. }
  134. else
  135. {
  136. IsSuspend = true;
  137. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  138. try
  139. {
  140. APP.FFmpeg.SuspendFFmpeg();
  141. }
  142. catch (Exception ex)
  143. {
  144. MessageBox.Show(ex.Message);
  145. }
  146. }
  147. }
  148. /// <summary>
  149. /// 停止录像
  150. /// </summary>
  151. /// <param name="sender"></param>
  152. /// <param name="e"></param>
  153. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  154. {
  155. if (APP.W_XHMicroLessonSystemWindow == null)
  156. {
  157. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  158. }
  159. APP.W_XHMicroLessonSystemWindow.Show();
  160. if (!IsFirstRS)
  161. {
  162. try
  163. {
  164. try
  165. {
  166. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  167. }
  168. catch (Exception ex)
  169. {
  170. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  171. }
  172. IsFirstRS = true;
  173. //生成缩略图
  174. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  175. FileToolsCommon.CreateDirectory(ThumbnailPath);
  176. //缩略图存储位置
  177. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  178. new Thread(new ThreadStart(new Action(() =>
  179. {
  180. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  181. {
  182. Thread.Sleep(100);
  183. }
  184. FileToolsCommon.DeleteFile(ThumbnailPathName);
  185. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  186. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  187. VideoInfo.VidePath = VideoSavePathName;
  188. VideoInfo.ThumbnailPath = ThumbnailPathName;
  189. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  190. APP.VideoList.Add(VideoInfo);
  191. //保存数据
  192. APP.SaveWkData();
  193. }))).Start();
  194. }
  195. catch (Exception ex)
  196. {
  197. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  198. }
  199. }
  200. Hide();
  201. }
  202. #endregion
  203. #region 画笔相关
  204. /// <summary>
  205. /// 画笔工具栏关闭事件
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  210. {
  211. gridToolbar.Visibility = Visibility.Hidden;
  212. gridColour.Visibility = Visibility.Hidden;
  213. gridThickness.Visibility = Visibility.Hidden;
  214. APP.W_PracticeWindow.Hide();
  215. }
  216. /// <summary>
  217. /// 画笔点击事件
  218. /// </summary>
  219. /// <param name="sender"></param>
  220. /// <param name="e"></param>
  221. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  222. {
  223. string time = GetTimeStamp();
  224. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  225. if (!Directory.Exists(tempPath))
  226. {
  227. Directory.CreateDirectory(tempPath);
  228. }
  229. string imagePath = Path.Combine(tempPath, time + ".jpg");
  230. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath);
  231. if (gridToolbar.Visibility == Visibility.Visible)
  232. {
  233. gridToolbar.Visibility = Visibility.Hidden;
  234. }
  235. else
  236. {
  237. gridToolbar.Visibility = Visibility.Visible;
  238. }
  239. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  240. try
  241. {
  242. if (APP.W_PracticeWindow == null)
  243. {
  244. APP.W_PracticeWindow = new PracticeWindow();
  245. //APP.W_PracticeWindow.Topmost = true;
  246. APP.W_PracticeWindow.Width = pwidth;
  247. APP.W_PracticeWindow.Height = pHeight;
  248. APP.W_PracticeWindow.Left = 0;
  249. APP.W_PracticeWindow.Top = 0;
  250. //practiceWin.Owner = this;
  251. }
  252. APP.W_PracticeWindow.Initialize(imagePath);
  253. APP.W_PracticeWindow.Show();
  254. }
  255. catch (Exception ex)
  256. {
  257. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  258. }
  259. }
  260. /// <summary>
  261. /// 屏幕宽
  262. /// </summary>
  263. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  264. /// <summary>
  265. /// 屏幕高
  266. /// </summary>
  267. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  268. /// <summary>
  269. /// 获取时间戳
  270. /// </summary>
  271. /// <returns></returns>
  272. public string GetTimeStamp()
  273. {
  274. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  275. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  276. }
  277. /// <summary>
  278. /// 画笔粗细事件
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  283. {
  284. gridThickness.Visibility = Visibility.Visible;
  285. gridColour.Visibility = Visibility.Collapsed;
  286. }
  287. /// <summary>
  288. /// 画笔颜色事件
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void BtnColour_Click(object sender, RoutedEventArgs e)
  293. {
  294. gridColour.Visibility = Visibility.Visible;
  295. gridThickness.Visibility = Visibility.Collapsed;
  296. }
  297. /// <summary>
  298. /// 白色
  299. /// </summary>
  300. /// <param name="sender"></param>
  301. /// <param name="e"></param>
  302. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  303. {
  304. //drawingAttributes.Color = Colors.White;
  305. APP.W_PracticeWindow.White();
  306. }
  307. /// <summary>
  308. /// 红色
  309. /// </summary>
  310. /// <param name="sender"></param>
  311. /// <param name="e"></param>
  312. private void BtnRed_Click(object sender, RoutedEventArgs e)
  313. {
  314. //drawingAttributes.Color = Colors.Red;
  315. APP.W_PracticeWindow.Red();
  316. }
  317. /// <summary>
  318. /// 黄色
  319. /// </summary>
  320. /// <param name="sender"></param>
  321. /// <param name="e"></param>
  322. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  323. {
  324. //drawingAttributes.Color = Colors.Gold;
  325. APP.W_PracticeWindow.Yellow();
  326. }
  327. /// <summary>
  328. /// 青色
  329. /// </summary>
  330. /// <param name="sender"></param>
  331. /// <param name="e"></param>
  332. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  333. {
  334. //drawingAttributes.Color = Colors.LimeGreen;
  335. APP.W_PracticeWindow.CyanBlue();
  336. }
  337. /// <summary>
  338. /// 灰色
  339. /// </summary>
  340. /// <param name="sender"></param>
  341. /// <param name="e"></param>
  342. private void BtnGray_Click(object sender, RoutedEventArgs e)
  343. {
  344. //drawingAttributes.Color = Colors.Gray;
  345. APP.W_PracticeWindow.Gray();
  346. }
  347. /// <summary>
  348. /// 蓝色
  349. /// </summary>
  350. /// <param name="sender"></param>
  351. /// <param name="e"></param>
  352. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  353. {
  354. //drawingAttributes.Color = Colors.DeepSkyBlue;
  355. APP.W_PracticeWindow.Blue();
  356. }
  357. /// <summary>
  358. /// 画笔 细
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void BtnFine_Click(object sender, RoutedEventArgs e)
  363. {
  364. APP.W_PracticeWindow.Fine();
  365. }
  366. /// <summary>
  367. /// 画笔 中
  368. /// </summary>
  369. /// <param name="sender"></param>
  370. /// <param name="e"></param>
  371. private void BtnIn_Click(object sender, RoutedEventArgs e)
  372. {
  373. APP.W_PracticeWindow.In();
  374. }
  375. /// <summary>
  376. /// 画笔粗
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  381. {
  382. APP.W_PracticeWindow.Crude();
  383. }
  384. /// <summary>
  385. /// 橡皮
  386. /// </summary>
  387. /// <param name="sender"></param>
  388. /// <param name="e"></param>
  389. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  390. {
  391. APP.W_PracticeWindow.Eraser();
  392. }
  393. #endregion
  394. #endregion
  395. /// <summary>
  396. /// 🖊
  397. /// </summary>
  398. /// <param name="sender"></param>
  399. /// <param name="e"></param>
  400. private void BtnPen_Click(object sender, RoutedEventArgs e)
  401. {
  402. APP.W_PracticeWindow.Pen();
  403. }
  404. /// <summary>
  405. /// ⚪
  406. /// </summary>
  407. /// <param name="sender"></param>
  408. /// <param name="e"></param>
  409. private void BtnRound_Click(object sender, RoutedEventArgs e)
  410. {
  411. APP.W_PracticeWindow.Round();
  412. }
  413. /// <summary>
  414. /// 矩形
  415. /// </summary>
  416. /// <param name="sender"></param>
  417. /// <param name="e"></param>
  418. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  419. {
  420. APP.W_PracticeWindow.Rectangle();
  421. }
  422. }
  423. }