星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

XHMicroLessonSystemWindow.xaml.cs 48KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. using Aspose.Words;
  2. using Aspose.Words.Saving;
  3. using Common.system;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing.Imaging;
  7. using System.IO;
  8. using System.Threading;
  9. using System.Windows;
  10. using System.Windows.Forms;
  11. using System.Windows.Ink;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using XHWK.Model;
  16. using System.Windows.Controls;
  17. using ComeCapture;
  18. using Aspose.Slides;
  19. using static Common.system.PdfTrunImage;
  20. namespace XHWK.WKTool
  21. {
  22. /// <summary>
  23. /// 主页面
  24. /// </summary>
  25. public partial class XHMicroLessonSystemWindow : Window
  26. {
  27. #region 字段
  28. /// <summary>
  29. /// 文件目录窗口
  30. /// </summary>
  31. //private CountdownWindow FileDirectoryWindows = null;
  32. private FolderBrowserDialog Ofd;
  33. private DialogResult Result;
  34. public readonly BlackboardNew myblackboard;
  35. private System.Windows.Forms.DialogResult result;
  36. private System.Windows.Forms.OpenFileDialog ofd;
  37. //声明一个 DrawingAttributes 类型的变量
  38. DrawingAttributes drawingAttributes;
  39. Model_Video VideoInfo = null;
  40. //定义事件
  41. public event ChangeTextHandler ChangeTextEvent;
  42. //定义委托
  43. public delegate void ChangeTextHandler(string text);
  44. /// <summary>
  45. /// 图片
  46. /// </summary>
  47. string [] ImgPDFPath = new string[300];
  48. #endregion
  49. #region 初始化
  50. /// <summary>
  51. /// 主页面
  52. /// </summary>
  53. public XHMicroLessonSystemWindow()
  54. {
  55. new Aspose.Pdf.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  56. InitializeComponent();
  57. myblackboard = new BlackboardNew(blackboard_canvas);
  58. APP.pageData.pagenum = 1;
  59. APP.pageData.currpage = 1;
  60. DataContext = APP.pageData;
  61. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoType");
  62. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  63. {
  64. rbnY.IsChecked = true;
  65. }
  66. else
  67. {
  68. rbnN.IsChecked = true;
  69. }
  70. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
  71. Initialize();
  72. }
  73. /// <summary>
  74. /// 初始化
  75. /// </summary>
  76. public void Initialize()
  77. {
  78. //创建 DrawingAttributes 类的一个实例
  79. drawingAttributes = new DrawingAttributes();
  80. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  81. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  82. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  83. blackboard_canvas.UseCustomCursor = true;
  84. drawingAttributes.FitToCurve = true;
  85. drawingAttributes.IgnorePressure = false;
  86. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  87. wfhCamera.Visibility = Visibility.Hidden;
  88. ImgPDFPath = null;
  89. ImgPDFPath = new string[300];
  90. }
  91. #endregion
  92. #region 事件
  93. /// <summary>
  94. /// 窗体移动
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  99. {
  100. DragMove();
  101. }
  102. /// <summary>
  103. /// 摄像头打开事件
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  108. {
  109. //UCCamera win = new UCCamera();
  110. ////win.Topmost = true;
  111. //win.ShowDialog();
  112. wfhCamera.Visibility = Visibility.Visible;
  113. CameraHelper.IsDisplay = true;
  114. CameraHelper.SourcePlayer = player;
  115. CameraHelper.UpdateCameraDevices();
  116. if (CameraHelper.CameraDevices.Count > 0)
  117. {
  118. CameraHelper.SetCameraDevice(0);
  119. }
  120. }
  121. /// <summary>
  122. /// 摄像头关闭事件
  123. /// </summary>
  124. /// <param name="sender"></param>
  125. /// <param name="e"></param>
  126. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  127. {
  128. wfhCamera.Visibility = Visibility.Hidden;
  129. CameraHelper.CloseDevice();
  130. }
  131. #endregion
  132. /// <summary>
  133. /// 录屏事件
  134. /// </summary>
  135. /// <param name="sender"></param>
  136. /// <param name="e"></param>
  137. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  138. {
  139. if (APP.IsLoginType == false)
  140. {
  141. Login();
  142. return;
  143. }
  144. if (APP.W_ScreenRecordingToolbarWindow == null)
  145. {
  146. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  147. {
  148. Topmost = true
  149. };
  150. APP.W_ScreenRecordingToolbarWindow.Initialize();
  151. }
  152. else
  153. {
  154. APP.W_ScreenRecordingToolbarWindow.Initialize();
  155. }
  156. //显示在右下角
  157. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 10;
  158. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 160;
  159. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  160. APP.W_ScreenRecordingToolbarWindow.Show();
  161. Hide();
  162. }
  163. /// <summary>
  164. /// 上传事件
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  169. {
  170. if (APP.IsLoginType == false)
  171. {
  172. Login();
  173. return;
  174. }
  175. FileDirectoryWindow fileDirectoryWindow = new FileDirectoryWindow();
  176. fileDirectoryWindow.Show();
  177. }
  178. /// <summary>
  179. /// 关闭事件
  180. /// </summary>
  181. /// <param name="sender"></param>
  182. /// <param name="e"></param>
  183. private void BtnDown_Click(object sender, RoutedEventArgs e)
  184. {
  185. System.Environment.Exit(0);
  186. }
  187. /// <summary>
  188. /// 设置 保存事件
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. private void BtnSave_Click(object sender, RoutedEventArgs e)
  193. {
  194. #region 合法性判断
  195. if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  196. {
  197. System.Windows.MessageBox.Show("路径不可为空!");
  198. return;
  199. }
  200. string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  201. if (!APP.WKData.WkPath.Equals(temp))
  202. {
  203. APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  204. if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  205. {
  206. //微课已存在
  207. MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  208. if (dr == MessageBoxResult.OK)
  209. {
  210. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  211. }
  212. else
  213. {
  214. return;
  215. }
  216. }
  217. //创建文件夹
  218. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  219. }
  220. #endregion
  221. if (rbnMP4.IsChecked == true)
  222. {
  223. //存储文件
  224. FileToolsCommon.SetConfigValue("VideoType", "1");
  225. }
  226. else if (rbnFLV.IsChecked == true)
  227. {
  228. FileToolsCommon.SetConfigValue("VideoType", "2");
  229. }
  230. else
  231. {
  232. FileToolsCommon.SetConfigValue("VideoType", "3");
  233. }
  234. if (rbnY.IsChecked == true)
  235. {
  236. FileToolsCommon.SetConfigValue("IsSound", "true");
  237. }
  238. else
  239. {
  240. FileToolsCommon.SetConfigValue("IsSound", "false");
  241. }
  242. GridMain.Visibility = Visibility.Visible;
  243. gridSetUp.Visibility = Visibility.Collapsed;
  244. }
  245. /// <summary>
  246. /// 设置事件
  247. /// </summary>
  248. /// <param name="sender"></param>
  249. /// <param name="e"></param>
  250. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  251. {
  252. GridMain.Visibility = Visibility.Collapsed;
  253. gridSetUp.Visibility = Visibility.Visible;
  254. }
  255. /// <summary>
  256. /// 设置 浏览事件
  257. /// </summary>
  258. /// <param name="sender"></param>
  259. /// <param name="e"></param>
  260. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  261. {
  262. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  263. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  264. Result = Ofd.ShowDialog();
  265. if (Result == System.Windows.Forms.DialogResult.OK)
  266. {
  267. if (Ofd.SelectedPath != "")
  268. {
  269. txbStoragePath.Text = Ofd.SelectedPath;
  270. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  271. //string temp = ofd.SelectedPath;
  272. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  273. }
  274. }
  275. }
  276. /// <summary>
  277. /// 画笔颜色事件 白色
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  282. {
  283. ////创建 DrawingAttributes 类的一个实例
  284. //drawingAttributes = new DrawingAttributes();
  285. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  286. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  287. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  288. ////设置 DrawingAttributes 的 Color 属性设置颜色
  289. drawingAttributes.Color = Colors.White;
  290. }
  291. /// <summary>
  292. /// 画笔颜色事件 红色
  293. /// </summary>
  294. /// <param name="sender"></param>
  295. /// <param name="e"></param>
  296. private void BtnRed_Click(object sender, RoutedEventArgs e)
  297. {
  298. //设置 DrawingAttributes 的 Color 属性设置颜色
  299. drawingAttributes.Color = Colors.Red;
  300. }
  301. /// <summary>
  302. /// 画笔颜色事件 灰色
  303. /// </summary>
  304. /// <param name="sender"></param>
  305. /// <param name="e"></param>
  306. private void BtnGray_Click(object sender, RoutedEventArgs e)
  307. {
  308. drawingAttributes.Color = Colors.Gray;
  309. }
  310. /// <summary>
  311. /// 画笔颜色事件 青色
  312. /// </summary>
  313. /// <param name="sender"></param>
  314. /// <param name="e"></param>
  315. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  316. {
  317. drawingAttributes.Color = Colors.LimeGreen;
  318. }
  319. /// <summary>
  320. /// 画笔颜色事件 黄色
  321. /// </summary>
  322. /// <param name="sender"></param>
  323. /// <param name="e"></param>
  324. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  325. {
  326. drawingAttributes.Color = Colors.Gold;
  327. }
  328. /// <summary>
  329. /// 画笔颜色事件 蓝色
  330. /// </summary>
  331. /// <param name="sender"></param>
  332. /// <param name="e"></param>
  333. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  334. {
  335. drawingAttributes.Color = Colors.DeepSkyBlue;
  336. }
  337. /// <summary>
  338. /// 画笔粗细事件 细
  339. /// </summary>
  340. /// <param name="sender"></param>
  341. /// <param name="e"></param>
  342. private void RbnFine_Click(object sender, RoutedEventArgs e)
  343. {
  344. drawingAttributes.Width = 1;
  345. drawingAttributes.Height = 1;
  346. }
  347. /// <summary>
  348. /// 画笔粗细事件 中
  349. /// </summary>
  350. /// <param name="sender"></param>
  351. /// <param name="e"></param>
  352. private void RbnIn_Click(object sender, RoutedEventArgs e)
  353. {
  354. drawingAttributes.Width = 3;
  355. drawingAttributes.Height = 3;
  356. }
  357. /// <summary>
  358. /// 画笔粗细事件 粗
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  363. {
  364. drawingAttributes.Width = 5;
  365. drawingAttributes.Height = 5;
  366. }
  367. /// <summary>
  368. /// 登陆事件
  369. /// </summary>
  370. /// <param name="sender"></param>
  371. /// <param name="e"></param>
  372. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  373. {
  374. Login();
  375. }
  376. /// <summary>
  377. /// 登陆
  378. /// </summary>
  379. private void Login()
  380. {
  381. if (APP.W_LoginWindow == null)
  382. {
  383. APP.W_LoginWindow = new LoginWindow();
  384. }
  385. else
  386. {
  387. APP.W_LoginWindow.Initialize();
  388. }
  389. APP.W_LoginWindow.ShowDialog();
  390. if (APP.IsLoginType)
  391. {
  392. txbLoginType.Text = APP.UserInfo.Username;
  393. }
  394. else
  395. {
  396. txbLoginType.Text = "未登录";
  397. }
  398. }
  399. /// <summary>
  400. /// 截图事件
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  405. {
  406. if (APP.IsLoginType == false)
  407. {
  408. Login();
  409. return;
  410. }
  411. string time = GetTimeStamp();
  412. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  413. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  414. if (APP.W_JieTuWindow != null)
  415. {
  416. APP.W_JieTuWindow.initialization();
  417. APP.W_JieTuWindow.Screenshot();
  418. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  419. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  420. }
  421. else
  422. {
  423. APP.W_JieTuWindow = new JieTuWindow();
  424. // 订阅事件
  425. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  426. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  427. APP.W_JieTuWindow.Show();
  428. }
  429. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  430. }
  431. /// <summary>
  432. /// 截图关闭窗口
  433. /// </summary>
  434. /// <param name="text"></param>
  435. private void frm_ChangeTextEvent(string text)
  436. {
  437. if ("关闭窗口".Equals(text))
  438. {
  439. if(!string.IsNullOrWhiteSpace(APP.ImgPath)&&File.Exists(APP.ImgPath))
  440. {
  441. APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
  442. if(!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  443. {
  444. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  445. }
  446. }
  447. }
  448. }
  449. /// <summary>
  450. /// 截图关闭 非正常关闭截图时,截图清空
  451. /// </summary>
  452. private void JietuWindow_click_closeJietuWindowClick()
  453. {
  454. APP.W_JieTuWindow = null;
  455. }
  456. /// <summary>
  457. /// 获取时间戳
  458. /// </summary>
  459. /// <returns></returns>
  460. public string GetTimeStamp()
  461. {
  462. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  463. return Convert.ToInt64(ts.TotalSeconds).ToString();
  464. }
  465. /// <summary>
  466. /// 导入事件
  467. /// </summary>
  468. /// <param name="sender"></param>
  469. /// <param name="e"></param>
  470. private void BtnImport_Click(object sender, RoutedEventArgs e)
  471. {
  472. if (APP.IsLoginType == false)
  473. {
  474. Login();
  475. return;
  476. }
  477. try
  478. {
  479. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  480. ofd = new System.Windows.Forms.OpenFileDialog
  481. {
  482. Filter = "文档|*.docx;*.doc;*ppt",
  483. InitialDirectory = desktopPath,
  484. Multiselect = false,
  485. AddExtension = true,
  486. DereferenceLinks = true
  487. };
  488. new Thread(
  489. o =>
  490. {
  491. Thread.Sleep(400);
  492. Dispatcher.Invoke(new Action(() =>
  493. {
  494. OpenDialogPPT();
  495. }
  496. ));
  497. })
  498. {
  499. IsBackground = true
  500. }.Start();
  501. }
  502. catch (Exception ex)
  503. {
  504. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  505. }
  506. }
  507. private void OpenDialog()
  508. {
  509. result = ofd.ShowDialog();
  510. if (result == System.Windows.Forms.DialogResult.OK)
  511. {
  512. if (ofd.FileName != "")
  513. {
  514. string filepath = ofd.FileName;
  515. string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  516. APP.Paths = ConvertWordToImage(filepath, path, "", 0, 0, null, 0).ToArray();
  517. for (int i = 0; i < APP.Paths.Length; i++)
  518. {
  519. APP.pageData.pagenum += 1;
  520. }
  521. if (APP.pageData.pagenum > 1)
  522. {
  523. APP.pageData.pagenum -= 1;
  524. }
  525. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  526. {
  527. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  528. }
  529. else
  530. {
  531. imgCanvas.Source = null;
  532. }
  533. }
  534. }
  535. }
  536. private void OpenDialogPPT()
  537. {
  538. result = ofd.ShowDialog();
  539. if (result == System.Windows.Forms.DialogResult.OK)
  540. {
  541. if (ofd.FileName != "")
  542. {
  543. #region PPT转PDF
  544. string filepath = ofd.FileName;
  545. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  546. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  547. path = pathTemp + path + ".pdf";
  548. //PPT转PDF
  549. Presentation ppt = new Presentation(filepath);
  550. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  551. #endregion
  552. #region PDF转图片
  553. // 图片绝对路径集合
  554. List<string> images = new List<string>();
  555. string directoryPath = pathTemp;
  556. //aspose许可证
  557. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  558. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  559. //l.SetLicense(licenseName);
  560. //定义Jpeg转换设备
  561. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  562. var device = new Aspose.Pdf.Devices.JpegDevice();
  563. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  564. //directoryPath += quality;
  565. Directory.CreateDirectory(directoryPath);
  566. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  567. device = new Aspose.Pdf.Devices.JpegDevice(100);
  568. //遍历每一页转为jpg
  569. for (var i = 1; i <= document.Pages.Count; i++)
  570. {
  571. long ii = Timestamp();
  572. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  573. images.Add(filePathOutPut);
  574. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  575. try
  576. {
  577. device.Process(document.Pages[i], fs);
  578. fs.Close();
  579. }
  580. catch (Exception ex)
  581. {
  582. fs.Close();
  583. File.Delete(filePathOutPut);
  584. }
  585. }
  586. #endregion
  587. APP.Paths = images.ToArray();
  588. ImgPDFPath= images.ToArray();
  589. for (int i = 0; i < APP.Paths.Length; i++)
  590. {
  591. APP.pageData.pagenum += 1;
  592. }
  593. if (APP.pageData.pagenum > 1)
  594. {
  595. APP.pageData.pagenum -= 1;
  596. }
  597. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  598. {
  599. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  600. }
  601. else
  602. {
  603. imgCanvas.Source = null;
  604. }
  605. }
  606. }
  607. }
  608. /// <summary>
  609. /// 返回一个时间戳到毫秒
  610. /// </summary>
  611. /// <returns></returns>
  612. public static long Timestamp()
  613. {
  614. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  615. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  616. return timestr;
  617. }
  618. #region 录制窗口
  619. #region 变量
  620. /// <summary>
  621. /// 视频保存路径
  622. /// </summary>
  623. string RecordingPath;
  624. /// <summary>
  625. /// 图片保存路径
  626. /// </summary>
  627. string ImgPath;
  628. /// <summary>
  629. /// 音频保存路径名
  630. /// </summary>
  631. string AudioPathName;
  632. /// <summary>
  633. /// 视频保存路径名
  634. /// </summary>
  635. string VideoSavePathName;
  636. /// <summary>
  637. /// 暂停录制
  638. /// </summary>
  639. bool IsSuspendR = true;
  640. /// <summary>
  641. /// 是否首次录制
  642. /// </summary>
  643. bool IsFirstR = true;
  644. /// <summary>
  645. /// 图片
  646. /// </summary>
  647. List<string> RsImgName = null;
  648. /// <summary>
  649. /// 是否开始截图计数
  650. /// </summary>
  651. bool IsStartCount = false;
  652. #endregion
  653. /// <summary>
  654. /// 录制窗口内容
  655. /// </summary>
  656. /// <param name="sender"></param>
  657. /// <param name="e"></param>
  658. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  659. {
  660. if (APP.IsLoginType == false)
  661. {
  662. Login();
  663. return;
  664. }
  665. blackboard_canvas.Visibility = Visibility.Visible;
  666. StartRecord();
  667. }
  668. /// <summary>
  669. /// 停止录制窗口内容
  670. /// </summary>
  671. /// <param name="sender"></param>
  672. /// <param name="e"></param>
  673. private void BtnStop_Click(object sender, RoutedEventArgs e)
  674. {
  675. if (APP.IsLoginType == false)
  676. {
  677. Login();
  678. return;
  679. }
  680. blackboard_canvas.Visibility = Visibility.Collapsed;
  681. EndRecord();
  682. }
  683. System.Timers.Timer timer;
  684. /// <summary>
  685. /// 开始录制和暂停录制
  686. /// </summary>
  687. void StartRecord()
  688. {
  689. if (IsSuspendR)
  690. {
  691. if (IsFirstR)//是否第一次录制 初始化录制
  692. {
  693. VideoInfo = new Model_Video();
  694. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  695. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  696. RecordingPath = APP.WKData.WkPath;
  697. ImgPath = APP.WKData.WkPath + "temp/Image/";
  698. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  699. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  700. FileToolsCommon.CreateDirectory(RecordingPath);
  701. FileToolsCommon.CreateDirectory(ImgPath);
  702. FileToolsCommon.CreateDirectory(AudioPathName);
  703. AudioPathName += APP.WKData.WkName + ".MP3";
  704. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  705. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  706. {
  707. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  708. if (dr == MessageBoxResult.OK)
  709. {
  710. try
  711. {
  712. FileToolsCommon.DeleteFile(VideoSavePathName);
  713. APP.VideoList.RemoveAll(x => x.VidePath == VideoSavePathName);
  714. }
  715. catch (Exception ex)
  716. {
  717. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  718. }
  719. }
  720. else
  721. {
  722. return;
  723. }
  724. }
  725. IsFirstR = false;
  726. RsImgName = new List<string>();
  727. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  728. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  729. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  730. timer.Enabled = true; //启动计时器
  731. }
  732. #region 录像倒计时
  733. if (APP.W_CountdownWindow == null)
  734. {
  735. APP.W_CountdownWindow = new CountdownWindow();
  736. //APP.W_CountdownWindow.Topmost = true;
  737. }
  738. else
  739. {
  740. APP.W_CountdownWindow.Initialize();
  741. APP.W_CountdownWindow.Topmost = true;
  742. }
  743. APP.W_CountdownWindow.Show();
  744. #endregion
  745. //继续录制
  746. IsSuspendR = false;
  747. //BtnRecording.Content = "暂停录制";
  748. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  749. TxbRecordingWord.Text = "暂停";
  750. try
  751. {
  752. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  753. new Thread(new ThreadStart(new Action(() =>
  754. {
  755. Thread.Sleep(1000);
  756. Dispatcher.Invoke(() =>
  757. {
  758. IsStartCount = true;
  759. //timer.Start();
  760. });
  761. }))).Start();
  762. }
  763. catch (Exception ex)
  764. {
  765. System.Windows.MessageBox.Show(ex.Message);
  766. }
  767. }
  768. else
  769. {
  770. //暂停
  771. IsSuspendR = true;
  772. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  773. TxbRecordingWord.Text = "继续";
  774. try
  775. {
  776. APP.FFmpeg.SuspendFFmpeg();
  777. new Thread(new ThreadStart(new Action(() =>
  778. {
  779. while (APP.FFmpeg.myProcess != null)
  780. {
  781. Thread.Sleep(100);
  782. }
  783. IsStartCount = false;
  784. }))).Start();
  785. }
  786. catch (Exception ex)
  787. {
  788. System.Windows.MessageBox.Show(ex.Message);
  789. }
  790. }
  791. }
  792. /// <summary>
  793. /// 录制保存图片
  794. /// </summary>
  795. /// <param name="sender"></param>
  796. /// <param name="e"></param>
  797. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  798. {
  799. if (IsStartCount)
  800. {
  801. try
  802. {
  803. Dispatcher.Invoke(() =>
  804. {
  805. string FilePathName = ImgPath + RsImgName.Count + ".png";
  806. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  807. RsImgName.Add(FilePathName);
  808. });
  809. }
  810. catch (Exception ex)
  811. {
  812. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  813. }
  814. }
  815. }
  816. /// <summary>
  817. /// 停止录制并生成录制文件
  818. /// </summary>
  819. void EndRecord()
  820. {
  821. if (!IsFirstR)
  822. {
  823. IsFirstR = true;
  824. IsSuspendR = true;
  825. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  826. TxbRecordingWord.Text = "录制";
  827. try
  828. {
  829. APP.FFmpeg.StopFFmpeg(AudioPathName);
  830. new Thread(new ThreadStart(new Action(() =>
  831. {
  832. while (APP.FFmpeg.myProcess != null)
  833. {
  834. Thread.Sleep(100);
  835. }
  836. Dispatcher.Invoke(() =>
  837. {
  838. IsStartCount = false;
  839. timer.Stop();
  840. });
  841. }))).Start();
  842. new Thread(new ThreadStart(new Action(() =>
  843. {
  844. while (APP.FFmpeg.myProcess != null)
  845. {
  846. Thread.Sleep(100);
  847. }
  848. }))).Start();
  849. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  850. //生成缩略图
  851. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  852. FileToolsCommon.CreateDirectory(ThumbnailPath);
  853. //缩略图存储位置
  854. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  855. new Thread(new ThreadStart(new Action(() =>
  856. {
  857. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  858. {
  859. Thread.Sleep(100);
  860. }
  861. FileToolsCommon.DeleteFile(ThumbnailPathName);
  862. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  863. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  864. VideoInfo.VidePath = VideoSavePathName;
  865. VideoInfo.ThumbnailPath = ThumbnailPathName;
  866. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  867. APP.VideoList.Add(VideoInfo);
  868. }))).Start();
  869. //List<Model_Video> VideoList
  870. }
  871. catch (Exception ex)
  872. {
  873. System.Windows.MessageBox.Show(ex.Message);
  874. }
  875. }
  876. }
  877. #endregion
  878. /// <summary>
  879. /// 增加事件
  880. /// </summary>
  881. /// <param name="sender"></param>
  882. /// <param name="e"></param>
  883. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  884. {
  885. if (APP.IsLoginType == false)
  886. {
  887. Login();
  888. return;
  889. }
  890. APP.pageData.pagenum += 1;
  891. APP.pageData.currpage = APP.pageData.pagenum;
  892. myblackboard.changepage(APP.pageData.currpage - 1);
  893. imgCanvas.Source = null;
  894. }
  895. /// <summary>
  896. /// 打印事件
  897. /// </summary>
  898. /// <param name="sender"></param>
  899. /// <param name="e"></param>
  900. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  901. {
  902. if (APP.IsLoginType == false)
  903. {
  904. Login();
  905. return;
  906. }
  907. //for(int i=0;i< APP.pageData.pagenum; i++)
  908. //{
  909. //}
  910. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  911. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  912. try
  913. {
  914. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
  915. document.Open();
  916. iTextSharp.text.Image image;
  917. for (int i = 0; i < ImgPDFPath.Length; i++)
  918. {
  919. if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
  920. image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
  921. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  922. {
  923. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  924. }
  925. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  926. {
  927. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  928. }
  929. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  930. document.NewPage();
  931. document.Add(image);
  932. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  933. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  934. //p1.Leading = 150; //行间距
  935. //document.Add(p1);
  936. }
  937. Console.WriteLine("转换成功!");
  938. }
  939. catch (Exception ex)
  940. {
  941. Console.WriteLine("转换失败,原因:" + ex.Message);
  942. }
  943. document.Close();
  944. ////Console.ReadKey();
  945. }
  946. /// <summary>
  947. /// 我的
  948. /// </summary>
  949. /// <param name="sender"></param>
  950. /// <param name="e"></param>
  951. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  952. {
  953. if (APP.IsLoginType == false)
  954. {
  955. Login();
  956. return;
  957. }
  958. }
  959. /// <summary>
  960. /// 上一页
  961. /// </summary>
  962. /// <param name="sender"></param>
  963. /// <param name="e"></param>
  964. private void last_button_Click(object sender, RoutedEventArgs e)
  965. {
  966. if (APP.pageData.currpage > 1)
  967. {
  968. APP.pageData.currpage -= 1;
  969. myblackboard.changepage(APP.pageData.currpage - 1);
  970. if (APP.Paths.Length > 0)
  971. {
  972. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length&& APP.pageData.currpage > 0)
  973. {
  974. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  975. }
  976. else
  977. {
  978. imgCanvas.Source = null;
  979. }
  980. }
  981. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  982. {
  983. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  984. }
  985. }
  986. }
  987. /// <summary>
  988. /// 下一页
  989. /// </summary>
  990. /// <param name="sender"></param>
  991. /// <param name="e"></param>
  992. private void next_btn_Click(object sender, RoutedEventArgs e)
  993. {
  994. if (APP.pageData.currpage < APP.pageData.pagenum)
  995. {
  996. APP.pageData.currpage += 1;
  997. myblackboard.changepage(APP.pageData.currpage - 1);
  998. if (APP.Paths.Length > 0)
  999. {
  1000. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
  1001. {
  1002. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1003. }
  1004. else
  1005. {
  1006. imgCanvas.Source = null;
  1007. }
  1008. }
  1009. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1010. {
  1011. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1012. }
  1013. try
  1014. {
  1015. Dispatcher.Invoke(() =>
  1016. {
  1017. string FilePathName = AppDomain.CurrentDomain.BaseDirectory + "Temp\\" +"pdf"+ APP.pageData.currpage.ToString() + ".jpg";
  1018. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1019. ImgPDFPath[APP.pageData.currpage - 1] =FilePathName;
  1020. });
  1021. }
  1022. catch (Exception ex)
  1023. {
  1024. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1025. }
  1026. }
  1027. }
  1028. /// <summary>
  1029. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1030. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1031. /// </summary>
  1032. /// <param name="pdfInputPath">Word文件路径</param>
  1033. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1034. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1035. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1036. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1037. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1038. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1039. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1040. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1041. {
  1042. // 返回的图片绝对路径集合
  1043. List<string> images = new List<string>();
  1044. try
  1045. {
  1046. // open word file
  1047. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1048. // validate parameter
  1049. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1050. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1051. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1052. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1053. if (startPageNum <= 0) { startPageNum = 1; }
  1054. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1055. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1056. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1057. if (resolution <= 0) { resolution = 128; }
  1058. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1059. {
  1060. Resolution = resolution
  1061. };
  1062. // start to convert each page
  1063. for (int i = startPageNum; i <= endPageNum; i++)
  1064. {
  1065. imageSaveOptions.PageIndex = i - 1;
  1066. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1067. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1068. APP.num++;
  1069. }
  1070. imageSaveOptions = null;
  1071. doc = null;
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1076. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1077. }
  1078. return images;
  1079. }
  1080. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1081. {
  1082. SaveFormat sf;// = SaveFormat.Unknown;
  1083. if (imageFormat.Equals(ImageFormat.Png))
  1084. {
  1085. sf = SaveFormat.Png;
  1086. }
  1087. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1088. {
  1089. sf = SaveFormat.Jpeg;
  1090. }
  1091. else if (imageFormat.Equals(ImageFormat.Tiff))
  1092. {
  1093. sf = SaveFormat.Tiff;
  1094. }
  1095. else if (imageFormat.Equals(ImageFormat.Bmp))
  1096. {
  1097. sf = SaveFormat.Bmp;
  1098. }
  1099. else
  1100. {
  1101. sf = SaveFormat.Unknown;
  1102. }
  1103. return sf;
  1104. }
  1105. #region 图像缩放,移动
  1106. private bool mouseDown;
  1107. private System.Windows.Point mouseXY;
  1108. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1109. {
  1110. var img = sender as ContentControl;
  1111. if (img == null)
  1112. {
  1113. return;
  1114. }
  1115. img.CaptureMouse();
  1116. mouseDown = true;
  1117. mouseXY = e.GetPosition(img);
  1118. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1119. }
  1120. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1121. {
  1122. System.Windows.Point point = e.GetPosition(imgCanvas);
  1123. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1124. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1125. //{
  1126. // Console.WriteLine("在范围内");
  1127. //}
  1128. }
  1129. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1130. {
  1131. var img = sender as ContentControl;
  1132. if (img == null)
  1133. {
  1134. return;
  1135. }
  1136. img.ReleaseMouseCapture();
  1137. mouseDown = false;
  1138. }
  1139. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1140. {
  1141. var img = sender as ContentControl;
  1142. if (img == null)
  1143. {
  1144. return;
  1145. }
  1146. if (mouseDown)
  1147. {
  1148. Domousemove(img, e);
  1149. }
  1150. }
  1151. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1152. {
  1153. if (e.LeftButton != MouseButtonState.Pressed)
  1154. {
  1155. return;
  1156. }
  1157. var group = IMG.FindResource("Imageview") as TransformGroup;
  1158. var transform = group.Children[1] as TranslateTransform;
  1159. var position = e.GetPosition(img);
  1160. transform.X -= mouseXY.X - position.X;
  1161. transform.Y -= mouseXY.Y - position.Y;
  1162. mouseXY = position;
  1163. }
  1164. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1165. {
  1166. var img = sender as ContentControl;
  1167. if (img == null)
  1168. {
  1169. return;
  1170. }
  1171. var point = e.GetPosition(img);
  1172. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1173. var PicLocate = e.GetPosition(imgCanvas);
  1174. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1175. var group = IMG.FindResource("Imageview") as TransformGroup;
  1176. var delta = e.Delta * 0.001;
  1177. DowheelZoom(group, point, delta);
  1178. }
  1179. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1180. {
  1181. var pointToContent = group.Inverse.Transform(point);
  1182. var transform = group.Children[0] as ScaleTransform;
  1183. if (transform.ScaleX + delta < 0.1) return;
  1184. transform.ScaleX += delta;
  1185. transform.ScaleY += delta;
  1186. var transform1 = group.Children[1] as TranslateTransform;
  1187. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1188. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1189. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1190. }
  1191. #endregion
  1192. }
  1193. }