星火微课系统客户端
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 39KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. using Common.system;
  2. using System;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Forms;
  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. private string VideoSavePathName;
  24. /// <summary>
  25. /// 是否首次录屏
  26. /// </summary>
  27. private bool IsFirstRS = true;
  28. /// <summary>
  29. /// 是否暂停
  30. /// </summary>
  31. private bool IsSuspend = true;
  32. /// <summary>
  33. /// 视频信息
  34. /// </summary>
  35. private Model_Video VideoInfo = null;
  36. //声明一个 DrawingAttributes 类型的变量
  37. private DrawingAttributes drawingAttributes;
  38. private DispatcherTimer t = null;
  39. /// <summary>
  40. /// 计时器状态
  41. /// </summary>
  42. private enum State
  43. {
  44. Start,
  45. Pause,
  46. End
  47. }
  48. /// <summary>
  49. /// 状态
  50. /// </summary>
  51. private State _state = State.End;
  52. /// <summary>
  53. /// 计时用
  54. /// </summary>
  55. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  56. private KeyboardHookCommon k_hook;
  57. /// <summary>
  58. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  59. /// </summary>
  60. public int flg = 0;
  61. private System.Timers.Timer timer = new System.Timers.Timer();
  62. #endregion
  63. #region 初始化
  64. /// <summary>
  65. /// 录屏工具栏
  66. /// </summary>
  67. public ScreenRecordingToolbarWindow()
  68. {
  69. InitializeComponent();
  70. }
  71. /// <summary>
  72. /// 初始化
  73. /// </summary>
  74. public void Initialize()
  75. {
  76. //timer = new System.Timers.Timer(200);
  77. //timer.Interval = 300;
  78. //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
  79. //timer.Enabled = true; //启动计时器
  80. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  81. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  82. k_hook = new KeyboardHookCommon();
  83. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  84. //创建 DrawingAttributes 类的一个实例
  85. drawingAttributes = new DrawingAttributes();
  86. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  87. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  88. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  89. drawingAttributes.FitToCurve = true;
  90. //隐藏画笔工具栏
  91. //BtnToolbarDown_Click(null, null);
  92. gridToolbar.Visibility = Visibility.Hidden;
  93. gridColour.Visibility = Visibility.Hidden;
  94. gridThickness.Visibility = Visibility.Hidden;
  95. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  96. btnReturn.IsEnabled = true;//返回主界面可点击
  97. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  98. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  99. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  100. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  101. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  102. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  103. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  104. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  105. //btnReturn.IsEnabled = true;//返回主界面可点击
  106. txbTime.Visibility = Visibility.Hidden;//时间不显示
  107. if (t == null)
  108. {
  109. t = new DispatcherTimer();
  110. t.Tick += OnTimer;
  111. t.Interval = new TimeSpan(0, 0, 0, 1);
  112. t.IsEnabled = true;
  113. t.Start();
  114. }
  115. t.Interval = new TimeSpan(0, 0, 0, 1);
  116. //Stack();
  117. //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  118. //BtnRecordingScreen_Click(null, null);
  119. }
  120. private void TimerDealy(object o, EventArgs e)
  121. {
  122. Dispatcher.Invoke(() =>
  123. {
  124. if (Left > 1630)
  125. {
  126. return;
  127. }
  128. //获取鼠标在屏幕上的位置
  129. double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
  130. double mouse_y = Form.MousePosition.Y;
  131. bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
  132. bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
  133. if (Left < 1630 && Left >= 0 && is_in_collasped_range)
  134. {
  135. System.Threading.Thread.Sleep(300);
  136. Left += 20 /*-this.ActualWidth - 3*/;
  137. }
  138. else if (Left < 0 && is_in_visiable_range)
  139. {
  140. Left = 1;
  141. }
  142. });
  143. }
  144. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  145. {
  146. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  147. {
  148. //开始,暂停
  149. BtnRecordingScreen_Click(null, null);
  150. }
  151. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  152. {
  153. //结束
  154. BtnStopRecordingScreen_Click(null, null);
  155. }
  156. }
  157. #endregion
  158. #region 事件
  159. /// <summary>
  160. /// 时钟回调
  161. /// </summary>
  162. /// <param name="sender"></param>
  163. /// <param name="e"></param>
  164. private void OnTimer(object sender, EventArgs e)
  165. {
  166. switch (_state)
  167. {
  168. case State.Start:
  169. {
  170. _timeSpan += new TimeSpan(0, 0, 0, 1);
  171. }
  172. break;
  173. case State.Pause:
  174. {
  175. }
  176. break;
  177. case State.End:
  178. {
  179. _timeSpan = new TimeSpan();
  180. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  181. }
  182. break;
  183. }
  184. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  185. //char[] times = time.ToCharArray();
  186. txbTime.Text = time;
  187. }
  188. /// <summary>
  189. /// 开始
  190. /// </summary>
  191. /// <param name="sender"></param>
  192. /// <param name="e"></param>
  193. private void Stack()
  194. {
  195. _state = State.Start;
  196. }
  197. /// <summary>
  198. /// 暂停
  199. /// </summary>
  200. private void TimeOut()
  201. {
  202. _state = State.Pause;
  203. }
  204. /// <summary>
  205. /// 结束
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void End()
  210. {
  211. _state = State.End;
  212. }
  213. #region 录屏
  214. /// <summary>
  215. /// 设置录屏文件地址
  216. /// </summary>
  217. private void SetUpVideoPathName()
  218. {
  219. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  220. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  221. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  222. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  223. int num = 1;
  224. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  225. {
  226. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  227. num++;
  228. }
  229. }
  230. /// <summary>
  231. /// 开始或暂停录制
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  236. {
  237. if (IsSuspend)
  238. {
  239. if (IsFirstRS)
  240. {
  241. #region 检测麦克风扬声器是否可用
  242. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  243. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  244. try
  245. {
  246. FileToolsCommon.DeleteFile(audioSpeakerPath);
  247. FileToolsCommon.DeleteFile(audioMicrophonePath);
  248. }
  249. catch (Exception)
  250. {
  251. }
  252. //扬声器
  253. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  254. {
  255. APP.FFmpeg.StopRecordAudio(2);
  256. //Thread.Sleep(500);
  257. //麦克风
  258. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  259. {
  260. }
  261. else
  262. {
  263. //无法录制麦克风
  264. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  265. if (Res == MessageBoxResult.Cancel)
  266. {
  267. return;
  268. }
  269. }
  270. APP.FFmpeg.StopRecordAudio(1);
  271. }
  272. else
  273. {
  274. //无法录制扬声器音频
  275. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  276. if (Res == MessageBoxResult.Cancel)
  277. {
  278. return;
  279. }
  280. }
  281. #endregion
  282. VideoInfo = new Model_Video
  283. {
  284. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  285. WkType = Enum_WKVidetype.RecordingScreen
  286. };
  287. SetUpVideoPathName();
  288. IsFirstRS = false;
  289. k_hook.Start();//安装键盘钩子
  290. if (APP.W_CountdownWindow == null)
  291. {
  292. APP.W_CountdownWindow = new CountdownWindow();
  293. APP.W_CountdownWindow.Initialize(true, 1800);
  294. //APP.W_CountdownWindow.Topmost = true;
  295. }
  296. else
  297. {
  298. APP.W_CountdownWindow.Initialize(true, 1800);
  299. //APP.W_CountdownWindow.Topmost = true;
  300. }
  301. APP.W_CountdownWindow.Show();
  302. }
  303. IsSuspend = false;
  304. //#region 录像倒计时
  305. //if (APP.W_CountdownWindow == null)
  306. //{
  307. // APP.W_CountdownWindow = new CountdownWindow();
  308. // //APP.W_CountdownWindow.Topmost = true;
  309. //}
  310. //else
  311. //{
  312. // APP.W_CountdownWindow.Initialize();
  313. // //APP.W_CountdownWindow.Topmost = true;
  314. //}
  315. //APP.W_CountdownWindow.Show();
  316. //#endregion
  317. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
  318. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  319. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  320. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
  321. btnBlackPenOne.IsEnabled = true;//蓝笔可点击
  322. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
  323. btnBlackPenTwo.IsEnabled = true;//红笔可点击
  324. txbTime.Visibility = Visibility.Visible;//时间显示
  325. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
  326. btnReturn.IsEnabled = false;//返回主界面可点击
  327. //borOne.Background = new SolidColorBrush(Colors.LightBlue);
  328. //btnReturn.IsEnabled = false;//返回主界面可点击
  329. try
  330. {
  331. #region 4秒内不可点击
  332. new Thread(new ThreadStart(new Action(() =>
  333. {
  334. Dispatcher.Invoke(() =>
  335. {
  336. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  337. BtnRecordingScreen.IsEnabled = false;
  338. BtnStopRecordingScreen.IsEnabled = false;
  339. });
  340. Thread.Sleep(4000);
  341. Dispatcher.Invoke(() =>
  342. {
  343. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  344. BtnRecordingScreen.IsEnabled = true;
  345. BtnStopRecordingScreen.IsEnabled = true;
  346. });
  347. }))).Start();
  348. #endregion
  349. new Thread(new ThreadStart(new Action(() =>
  350. {
  351. if (IsFirstRS)
  352. {
  353. Thread.Sleep(1500);
  354. }
  355. if(APP.FFmpeg.myProcess!=null)
  356. {
  357. Thread.Sleep(100);
  358. }
  359. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  360. Thread.Sleep(1000);
  361. Dispatcher.Invoke(() =>
  362. {
  363. Stack();
  364. });
  365. }))).Start();
  366. }
  367. catch (Exception ex)
  368. {
  369. MessageWindow.Show(ex.Message);
  370. }
  371. }
  372. else
  373. {
  374. TimeOut();
  375. IsSuspend = true;
  376. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  377. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  378. //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  379. //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  380. //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  381. //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  382. txbTime.Visibility = Visibility.Hidden;//时间不显示
  383. imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  384. btnReturn.IsEnabled = true;//返回主界面可点击
  385. #region 2秒内不可点击
  386. new Thread(new ThreadStart(new Action(() =>
  387. {
  388. Dispatcher.Invoke(() =>
  389. {
  390. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  391. BtnRecordingScreen.IsEnabled = false;
  392. BtnStopRecordingScreen.IsEnabled = false;
  393. });
  394. Thread.Sleep(2000);
  395. Dispatcher.Invoke(() =>
  396. {
  397. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  398. BtnRecordingScreen.IsEnabled = true;
  399. BtnStopRecordingScreen.IsEnabled = true;
  400. });
  401. }))).Start();
  402. #endregion
  403. try
  404. {
  405. APP.FFmpeg.SuspendFFmpeg();
  406. }
  407. catch (Exception ex)
  408. {
  409. MessageWindow.Show(ex.Message);
  410. }
  411. }
  412. }
  413. /// <summary>
  414. /// 停止录像
  415. /// </summary>
  416. /// <param name="sender"></param>
  417. /// <param name="e"></param>
  418. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  419. {
  420. k_hook.Stop();
  421. IsSuspend = true;
  422. txbTime.Text = "00:00";
  423. txbTime.Visibility = Visibility.Hidden;
  424. End();
  425. if (APP.W_PracticeWindow != null)
  426. {
  427. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  428. {
  429. APP.W_PracticeWindow.Hide();
  430. }
  431. }
  432. if (gridToolbar.Visibility == Visibility.Visible)
  433. {
  434. gridToolbar.Visibility = Visibility.Hidden;
  435. gridColour.Visibility = Visibility.Hidden;
  436. gridThickness.Visibility = Visibility.Hidden;
  437. }
  438. if (APP.W_XHMicroLessonSystemWindow == null)
  439. {
  440. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  441. }
  442. APP.W_XHMicroLessonSystemWindow.Show();
  443. if (!IsFirstRS)
  444. {
  445. try
  446. {
  447. try
  448. {
  449. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  450. }
  451. catch (Exception ex)
  452. {
  453. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  454. }
  455. IsFirstRS = true;
  456. //生成缩略图
  457. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  458. FileToolsCommon.CreateDirectory(ThumbnailPath);
  459. //缩略图存储位置
  460. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  461. new Thread(new ThreadStart(new Action(() =>
  462. {
  463. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  464. {
  465. Thread.Sleep(100);
  466. }
  467. FileToolsCommon.DeleteFile(ThumbnailPathName);
  468. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  469. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  470. VideoInfo.VideoPath = VideoSavePathName;
  471. VideoInfo.ThumbnailPath = ThumbnailPathName;
  472. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName,200,130);
  473. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  474. VideoInfo.IsUpload = false;
  475. VideoInfo.Uploaded = 0;
  476. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  477. APP.VideoList.Add(VideoInfo);
  478. //保存数据
  479. APP.SaveWkData();
  480. }))).Start();
  481. Click_stopRecordingScreen();
  482. }
  483. catch (Exception ex)
  484. {
  485. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  486. }
  487. }
  488. Hide();
  489. }
  490. #endregion
  491. #region 画笔相关
  492. /// <summary>
  493. /// 画笔工具栏关闭事件
  494. /// </summary>
  495. /// <param name="sender"></param>
  496. /// <param name="e"></param>
  497. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  498. {
  499. gridToolbar.Visibility = Visibility.Hidden;
  500. gridColour.Visibility = Visibility.Hidden;
  501. gridThickness.Visibility = Visibility.Hidden;
  502. APP.W_PracticeWindow.Hide();
  503. }
  504. /// <summary>
  505. /// 画笔点击事件
  506. /// </summary>
  507. /// <param name="sender"></param>
  508. /// <param name="e"></param>
  509. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  510. {
  511. string time = GetTimeStamp();
  512. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  513. if (!Directory.Exists(tempPath))
  514. {
  515. Directory.CreateDirectory(tempPath);
  516. }
  517. string imagePath = Path.Combine(tempPath, time + ".jpg");
  518. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  519. try
  520. {
  521. if (flg == 11)
  522. {
  523. Dispatcher.Invoke(() =>
  524. {
  525. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  526. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  527. });
  528. flg = 1;
  529. APP.W_PracticeWindow.Hide();
  530. }
  531. else if (flg == 10)
  532. {
  533. Dispatcher.Invoke(() =>
  534. {
  535. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  536. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  537. });
  538. APP.W_PracticeWindow.Blue();
  539. flg = 11;
  540. }
  541. else
  542. {
  543. //new Thread(new ThreadStart(new Action(() =>
  544. //{
  545. Dispatcher.Invoke(() =>
  546. {
  547. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  548. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  549. });
  550. //}))).Start();
  551. if (APP.W_PracticeWindow == null)
  552. {
  553. APP.W_PracticeWindow = new PracticeWindow
  554. {
  555. //APP.W_PracticeWindow.Topmost = true;
  556. Width = pwidth,
  557. Height = pHeight,
  558. Left = 0,
  559. Top = 0
  560. };
  561. //practiceWin.Owner = this;
  562. }
  563. APP.W_PracticeWindow.Initialize(imagePath);
  564. flg = 11;
  565. APP.W_PracticeWindow.Blue();
  566. APP.W_PracticeWindow.Show();
  567. }
  568. }
  569. catch (Exception ex)
  570. {
  571. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  572. }
  573. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  574. }
  575. /// <summary>
  576. /// 屏幕宽
  577. /// </summary>
  578. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  579. /// <summary>
  580. /// 屏幕高
  581. /// </summary>
  582. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  583. /// <summary>
  584. /// 获取时间戳
  585. /// </summary>
  586. /// <returns></returns>
  587. public string GetTimeStamp()
  588. {
  589. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  590. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  591. }
  592. /// <summary>
  593. /// 画笔粗细事件
  594. /// </summary>
  595. /// <param name="sender"></param>
  596. /// <param name="e"></param>
  597. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  598. {
  599. gridThickness.Visibility = Visibility.Visible;
  600. gridColour.Visibility = Visibility.Collapsed;
  601. }
  602. /// <summary>
  603. /// 画笔颜色事件
  604. /// </summary>
  605. /// <param name="sender"></param>
  606. /// <param name="e"></param>
  607. private void BtnColour_Click(object sender, RoutedEventArgs e)
  608. {
  609. gridColour.Visibility = Visibility.Visible;
  610. gridThickness.Visibility = Visibility.Collapsed;
  611. }
  612. /// <summary>
  613. /// 白色
  614. /// </summary>
  615. /// <param name="sender"></param>
  616. /// <param name="e"></param>
  617. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  618. {
  619. //drawingAttributes.Color = Colors.White;
  620. APP.W_PracticeWindow.White();
  621. gridColour.Visibility = Visibility.Collapsed;
  622. gridThickness.Visibility = Visibility.Collapsed;
  623. }
  624. /// <summary>
  625. /// 红色
  626. /// </summary>
  627. /// <param name="sender"></param>
  628. /// <param name="e"></param>
  629. private void BtnRed_Click(object sender, RoutedEventArgs e)
  630. {
  631. //drawingAttributes.Color = Colors.Red;
  632. APP.W_PracticeWindow.Red();
  633. gridColour.Visibility = Visibility.Collapsed;
  634. gridThickness.Visibility = Visibility.Collapsed;
  635. }
  636. /// <summary>
  637. /// 黄色
  638. /// </summary>
  639. /// <param name="sender"></param>
  640. /// <param name="e"></param>
  641. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  642. {
  643. //drawingAttributes.Color = Colors.Gold;
  644. APP.W_PracticeWindow.Yellow();
  645. gridColour.Visibility = Visibility.Collapsed;
  646. gridThickness.Visibility = Visibility.Collapsed;
  647. }
  648. /// <summary>
  649. /// 青色
  650. /// </summary>
  651. /// <param name="sender"></param>
  652. /// <param name="e"></param>
  653. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  654. {
  655. //drawingAttributes.Color = Colors.LimeGreen;
  656. APP.W_PracticeWindow.CyanBlue();
  657. gridColour.Visibility = Visibility.Collapsed;
  658. gridThickness.Visibility = Visibility.Collapsed;
  659. }
  660. /// <summary>
  661. /// 灰色
  662. /// </summary>
  663. /// <param name="sender"></param>
  664. /// <param name="e"></param>
  665. private void BtnGray_Click(object sender, RoutedEventArgs e)
  666. {
  667. //drawingAttributes.Color = Colors.Gray;
  668. APP.W_PracticeWindow.Gray();
  669. gridColour.Visibility = Visibility.Collapsed;
  670. gridThickness.Visibility = Visibility.Collapsed;
  671. }
  672. /// <summary>
  673. /// 蓝色
  674. /// </summary>
  675. /// <param name="sender"></param>
  676. /// <param name="e"></param>
  677. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  678. {
  679. //drawingAttributes.Color = Colors.DeepSkyBlue;
  680. APP.W_PracticeWindow.Blue();
  681. gridColour.Visibility = Visibility.Collapsed;
  682. gridThickness.Visibility = Visibility.Collapsed;
  683. }
  684. /// <summary>
  685. /// 画笔 细
  686. /// </summary>
  687. /// <param name="sender"></param>
  688. /// <param name="e"></param>
  689. private void BtnFine_Click(object sender, RoutedEventArgs e)
  690. {
  691. APP.W_PracticeWindow.Fine();
  692. gridColour.Visibility = Visibility.Collapsed;
  693. gridThickness.Visibility = Visibility.Collapsed;
  694. }
  695. /// <summary>
  696. /// 画笔 中
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void BtnIn_Click(object sender, RoutedEventArgs e)
  701. {
  702. APP.W_PracticeWindow.In();
  703. gridColour.Visibility = Visibility.Collapsed;
  704. gridThickness.Visibility = Visibility.Collapsed;
  705. }
  706. /// <summary>
  707. /// 画笔粗
  708. /// </summary>
  709. /// <param name="sender"></param>
  710. /// <param name="e"></param>
  711. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  712. {
  713. APP.W_PracticeWindow.Crude();
  714. gridColour.Visibility = Visibility.Collapsed;
  715. gridThickness.Visibility = Visibility.Collapsed;
  716. }
  717. /// <summary>
  718. /// 橡皮
  719. /// </summary>
  720. /// <param name="sender"></param>
  721. /// <param name="e"></param>
  722. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  723. {
  724. APP.W_PracticeWindow.Eraser();
  725. }
  726. /// <summary>
  727. /// 🖊
  728. /// </summary>
  729. /// <param name="sender"></param>
  730. /// <param name="e"></param>
  731. private void BtnPen_Click(object sender, RoutedEventArgs e)
  732. {
  733. APP.W_PracticeWindow.Pen();
  734. }
  735. /// <summary>
  736. /// ⚪
  737. /// </summary>
  738. /// <param name="sender"></param>
  739. /// <param name="e"></param>
  740. private void BtnRound_Click(object sender, RoutedEventArgs e)
  741. {
  742. APP.W_PracticeWindow.Round();
  743. }
  744. /// <summary>
  745. /// 矩形
  746. /// </summary>
  747. /// <param name="sender"></param>
  748. /// <param name="e"></param>
  749. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  750. {
  751. APP.W_PracticeWindow.Rectangle();
  752. }
  753. #endregion
  754. #endregion
  755. /// <summary>
  756. /// 停止录屏
  757. /// </summary>
  758. public delegate void StopRecordingScreen();
  759. /// <summary>
  760. /// 停止录屏
  761. /// </summary>
  762. public event StopRecordingScreen Click_stopRecordingScreen;
  763. /// <summary>
  764. /// 黑笔
  765. /// </summary>
  766. /// <param name="sender"></param>
  767. /// <param name="e"></param>
  768. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  769. {
  770. }
  771. /// <summary>
  772. /// 移动工具栏
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  777. {
  778. DragMove();
  779. }
  780. /// <summary>
  781. /// 红笔
  782. /// </summary>
  783. /// <param name="sender"></param>
  784. /// <param name="e"></param>
  785. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  786. {
  787. string time = GetTimeStamp();
  788. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  789. if (!Directory.Exists(tempPath))
  790. {
  791. Directory.CreateDirectory(tempPath);
  792. }
  793. string imagePath = Path.Combine(tempPath, time + ".jpg");
  794. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  795. try
  796. {
  797. if (flg == 10)
  798. {
  799. Dispatcher.Invoke(() =>
  800. {
  801. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  802. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  803. });
  804. flg = 0;
  805. APP.W_PracticeWindow.Hide();
  806. }
  807. else if (flg == 11)
  808. {
  809. Dispatcher.Invoke(() =>
  810. {
  811. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  812. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  813. });
  814. flg = 10;
  815. APP.W_PracticeWindow.Red();
  816. }
  817. else
  818. {
  819. Dispatcher.Invoke(() =>
  820. {
  821. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  822. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  823. });
  824. if (APP.W_PracticeWindow == null)
  825. {
  826. APP.W_PracticeWindow = new PracticeWindow
  827. {
  828. //APP.W_PracticeWindow.Topmost = true;
  829. Width = pwidth,
  830. Height = pHeight,
  831. Left = 0,
  832. Top = 0
  833. };
  834. //practiceWin.Owner = this;
  835. }
  836. APP.W_PracticeWindow.Initialize(imagePath);
  837. flg = 10;
  838. APP.W_PracticeWindow.Red();
  839. APP.W_PracticeWindow.Show();
  840. }
  841. }
  842. catch (Exception ex)
  843. {
  844. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  845. }
  846. }
  847. /// <summary>
  848. /// 鼠标右键按下事件
  849. /// </summary>
  850. /// <param name="sender"></param>
  851. /// <param name="e"></param>
  852. private void RightButtonDown()
  853. {
  854. if (flg > 9)
  855. {
  856. APP.W_PracticeWindow.Hide();
  857. }
  858. else
  859. {
  860. string time = GetTimeStamp();
  861. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  862. if (!Directory.Exists(tempPath))
  863. {
  864. Directory.CreateDirectory(tempPath);
  865. }
  866. string imagePath = Path.Combine(tempPath, time + ".jpg");
  867. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  868. try
  869. {
  870. if (APP.W_PracticeWindow == null)
  871. {
  872. APP.W_PracticeWindow = new PracticeWindow
  873. {
  874. //APP.W_PracticeWindow.Topmost = true;
  875. Width = pwidth,
  876. Height = pHeight,
  877. Left = 0,
  878. Top = 0
  879. };
  880. //practiceWin.Owner = this;
  881. }
  882. APP.W_PracticeWindow.Initialize(imagePath);
  883. if (flg == 0)
  884. {
  885. flg = 10;
  886. APP.W_PracticeWindow.Red();
  887. }
  888. else
  889. {
  890. flg = 11;
  891. APP.W_PracticeWindow.Blue();
  892. }
  893. APP.W_PracticeWindow.Show();
  894. }
  895. catch (Exception ex)
  896. {
  897. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  898. }
  899. }
  900. }
  901. /// <summary>
  902. /// 返回主界面
  903. /// </summary>
  904. /// <param name="sender"></param>
  905. /// <param name="e"></param>
  906. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  907. {
  908. if (!IsFirstRS)
  909. {
  910. MessageBoxResult br = MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
  911. if (br == MessageBoxResult.Cancel)
  912. {
  913. return;
  914. }
  915. k_hook.Stop();
  916. IsSuspend = true;
  917. txbTime.Text = "00:00";
  918. txbTime.Visibility = Visibility.Hidden;
  919. End();
  920. if (APP.W_PracticeWindow != null)
  921. {
  922. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  923. {
  924. APP.W_PracticeWindow.Hide();
  925. }
  926. }
  927. if (gridToolbar.Visibility == Visibility.Visible)
  928. {
  929. gridToolbar.Visibility = Visibility.Hidden;
  930. gridColour.Visibility = Visibility.Hidden;
  931. gridThickness.Visibility = Visibility.Hidden;
  932. }
  933. if (APP.W_XHMicroLessonSystemWindow == null)
  934. {
  935. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  936. }
  937. try
  938. {
  939. try
  940. {
  941. APP.FFmpeg.SuspendFFmpeg();
  942. }
  943. catch (Exception ex)
  944. {
  945. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  946. }
  947. IsFirstRS = true;
  948. new Thread(new ThreadStart(new Action(() =>
  949. {
  950. VideoInfo = null;
  951. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  952. }))).Start();
  953. }
  954. catch (Exception ex)
  955. {
  956. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  957. }
  958. }
  959. APP.W_XHMicroLessonSystemWindow.Show();
  960. Hide();
  961. }
  962. /// <summary>
  963. /// 批注退出
  964. /// </summary>
  965. public void ReturnPractice()
  966. {
  967. Dispatcher.Invoke(() =>
  968. {
  969. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  970. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  971. });
  972. flg = 0;
  973. APP.W_PracticeWindow.Hide();
  974. }
  975. }
  976. }