星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

XHMicroLessonSystemWindow.xaml.cs 51KB

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