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

XHMicroLessonSystemWindow.xaml.cs 51KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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. OpenDialog();
  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. #region PPT转PDF
  515. string filepath = ofd.FileName;
  516. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  517. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  518. if (type.Contains("typezsygppt"))
  519. {
  520. try
  521. {
  522. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  523. path = pathTemp + path + ".pdf";
  524. //PPT转PDF
  525. Presentation ppt = new Presentation(filepath);
  526. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  527. #endregion
  528. #region PDF转图片
  529. // 图片绝对路径集合
  530. List<string> images = new List<string>();
  531. string directoryPath = pathTemp;
  532. //aspose许可证
  533. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  534. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  535. //l.SetLicense(licenseName);
  536. //定义Jpeg转换设备
  537. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  538. var device = new Aspose.Pdf.Devices.JpegDevice();
  539. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  540. //directoryPath += quality;
  541. Directory.CreateDirectory(directoryPath);
  542. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  543. device = new Aspose.Pdf.Devices.JpegDevice(100);
  544. //遍历每一页转为jpg
  545. for (var i = 1; i <= document.Pages.Count; i++)
  546. {
  547. long ii = Timestamp();
  548. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  549. images.Add(filePathOutPut);
  550. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  551. try
  552. {
  553. device.Process(document.Pages[i], fs);
  554. fs.Close();
  555. }
  556. catch (Exception ex)
  557. {
  558. fs.Close();
  559. File.Delete(filePathOutPut);
  560. }
  561. }
  562. #endregion
  563. APP.Paths = images.ToArray();
  564. ImgPDFPath = images.ToArray();
  565. for (int i = 0; i < APP.Paths.Length; i++)
  566. {
  567. APP.pageData.pagenum += 1;
  568. }
  569. if (APP.pageData.pagenum > 1)
  570. {
  571. APP.pageData.pagenum -= 1;
  572. }
  573. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  574. {
  575. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  576. }
  577. else
  578. {
  579. imgCanvas.Source = null;
  580. }
  581. }
  582. catch (Exception ex)
  583. {
  584. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  585. }
  586. }
  587. else
  588. {
  589. try
  590. {
  591. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  592. APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  593. for (int i = 0; i < APP.Paths.Length; i++)
  594. {
  595. APP.pageData.pagenum += 1;
  596. }
  597. if (APP.pageData.pagenum > 1)
  598. {
  599. APP.pageData.pagenum -= 1;
  600. }
  601. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  602. {
  603. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  604. }
  605. else
  606. {
  607. imgCanvas.Source = null;
  608. }
  609. }
  610. catch (Exception ex)
  611. {
  612. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
  613. }
  614. }
  615. }
  616. }
  617. }
  618. /// <summary>
  619. /// 返回一个时间戳到毫秒
  620. /// </summary>
  621. /// <returns></returns>
  622. public static long Timestamp()
  623. {
  624. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  625. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  626. return timestr;
  627. }
  628. #region 录制窗口
  629. #region 变量
  630. /// <summary>
  631. /// 视频保存路径
  632. /// </summary>
  633. string RecordingPath;
  634. /// <summary>
  635. /// 图片保存路径
  636. /// </summary>
  637. string ImgPath;
  638. /// <summary>
  639. /// 音频保存路径名
  640. /// </summary>
  641. string AudioPathName;
  642. /// <summary>
  643. /// 视频保存路径名
  644. /// </summary>
  645. string VideoSavePathName;
  646. /// <summary>
  647. /// 暂停录制
  648. /// </summary>
  649. bool IsSuspendR = true;
  650. /// <summary>
  651. /// 是否首次录制
  652. /// </summary>
  653. bool IsFirstR = true;
  654. /// <summary>
  655. /// 图片
  656. /// </summary>
  657. List<string> RsImgName = null;
  658. /// <summary>
  659. /// 是否开始截图计数
  660. /// </summary>
  661. bool IsStartCount = false;
  662. #endregion
  663. /// <summary>
  664. /// 录制窗口内容
  665. /// </summary>
  666. /// <param name="sender"></param>
  667. /// <param name="e"></param>
  668. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  669. {
  670. if (APP.IsLoginType == false)
  671. {
  672. Login();
  673. return;
  674. }
  675. blackboard_canvas.Visibility = Visibility.Visible;
  676. StartRecord();
  677. }
  678. /// <summary>
  679. /// 停止录制窗口内容
  680. /// </summary>
  681. /// <param name="sender"></param>
  682. /// <param name="e"></param>
  683. private void BtnStop_Click(object sender, RoutedEventArgs e)
  684. {
  685. if (APP.IsLoginType == false)
  686. {
  687. Login();
  688. return;
  689. }
  690. blackboard_canvas.Visibility = Visibility.Collapsed;
  691. EndRecord();
  692. }
  693. System.Timers.Timer timer;
  694. /// <summary>
  695. /// 开始录制和暂停录制
  696. /// </summary>
  697. void StartRecord()
  698. {
  699. if (IsSuspendR)
  700. {
  701. if (IsFirstR)//是否第一次录制 初始化录制
  702. {
  703. VideoInfo = new Model_Video();
  704. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  705. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  706. RecordingPath = APP.WKData.WkPath;
  707. ImgPath = APP.WKData.WkPath + "temp/Image/";
  708. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  709. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  710. FileToolsCommon.CreateDirectory(RecordingPath);
  711. FileToolsCommon.CreateDirectory(ImgPath);
  712. FileToolsCommon.CreateDirectory(AudioPathName);
  713. AudioPathName += APP.WKData.WkName + ".MP3";
  714. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  715. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  716. {
  717. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  718. if (dr == MessageBoxResult.OK)
  719. {
  720. try
  721. {
  722. FileToolsCommon.DeleteFile(VideoSavePathName);
  723. APP.VideoList.RemoveAll(x => x.VidePath == VideoSavePathName);
  724. }
  725. catch (Exception ex)
  726. {
  727. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  728. }
  729. }
  730. else
  731. {
  732. return;
  733. }
  734. }
  735. IsFirstR = false;
  736. RsImgName = new List<string>();
  737. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  738. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  739. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  740. timer.Enabled = true; //启动计时器
  741. }
  742. #region 录像倒计时
  743. if (APP.W_CountdownWindow == null)
  744. {
  745. APP.W_CountdownWindow = new CountdownWindow();
  746. //APP.W_CountdownWindow.Topmost = true;
  747. }
  748. else
  749. {
  750. APP.W_CountdownWindow.Initialize();
  751. APP.W_CountdownWindow.Topmost = true;
  752. }
  753. APP.W_CountdownWindow.Show();
  754. #endregion
  755. //继续录制
  756. IsSuspendR = false;
  757. //BtnRecording.Content = "暂停录制";
  758. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  759. TxbRecordingWord.Text = "暂停";
  760. try
  761. {
  762. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  763. new Thread(new ThreadStart(new Action(() =>
  764. {
  765. Thread.Sleep(1000);
  766. Dispatcher.Invoke(() =>
  767. {
  768. IsStartCount = true;
  769. //timer.Start();
  770. });
  771. }))).Start();
  772. }
  773. catch (Exception ex)
  774. {
  775. System.Windows.MessageBox.Show(ex.Message);
  776. }
  777. }
  778. else
  779. {
  780. //暂停
  781. IsSuspendR = true;
  782. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  783. TxbRecordingWord.Text = "继续";
  784. try
  785. {
  786. APP.FFmpeg.SuspendFFmpeg();
  787. new Thread(new ThreadStart(new Action(() =>
  788. {
  789. while (APP.FFmpeg.myProcess != null)
  790. {
  791. Thread.Sleep(100);
  792. }
  793. IsStartCount = false;
  794. }))).Start();
  795. }
  796. catch (Exception ex)
  797. {
  798. System.Windows.MessageBox.Show(ex.Message);
  799. }
  800. }
  801. }
  802. /// <summary>
  803. /// 录制保存图片
  804. /// </summary>
  805. /// <param name="sender"></param>
  806. /// <param name="e"></param>
  807. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  808. {
  809. if (IsStartCount)
  810. {
  811. try
  812. {
  813. Dispatcher.Invoke(() =>
  814. {
  815. string FilePathName = ImgPath + RsImgName.Count + ".png";
  816. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  817. RsImgName.Add(FilePathName);
  818. });
  819. }
  820. catch (Exception ex)
  821. {
  822. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  823. }
  824. }
  825. }
  826. /// <summary>
  827. /// 停止录制并生成录制文件
  828. /// </summary>
  829. void EndRecord()
  830. {
  831. if (!IsFirstR)
  832. {
  833. IsFirstR = true;
  834. IsSuspendR = true;
  835. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  836. TxbRecordingWord.Text = "录制";
  837. try
  838. {
  839. APP.FFmpeg.StopFFmpeg(AudioPathName);
  840. new Thread(new ThreadStart(new Action(() =>
  841. {
  842. while (APP.FFmpeg.myProcess != null)
  843. {
  844. Thread.Sleep(100);
  845. }
  846. Dispatcher.Invoke(() =>
  847. {
  848. IsStartCount = false;
  849. timer.Stop();
  850. });
  851. }))).Start();
  852. new Thread(new ThreadStart(new Action(() =>
  853. {
  854. while (APP.FFmpeg.myProcess != null)
  855. {
  856. Thread.Sleep(100);
  857. }
  858. }))).Start();
  859. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  860. //生成缩略图
  861. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  862. FileToolsCommon.CreateDirectory(ThumbnailPath);
  863. //缩略图存储位置
  864. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  865. new Thread(new ThreadStart(new Action(() =>
  866. {
  867. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  868. {
  869. Thread.Sleep(100);
  870. }
  871. FileToolsCommon.DeleteFile(ThumbnailPathName);
  872. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  873. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  874. VideoInfo.VidePath = VideoSavePathName;
  875. VideoInfo.ThumbnailPath = ThumbnailPathName;
  876. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  877. APP.VideoList.Add(VideoInfo);
  878. }))).Start();
  879. //List<Model_Video> VideoList
  880. }
  881. catch (Exception ex)
  882. {
  883. System.Windows.MessageBox.Show(ex.Message);
  884. }
  885. }
  886. }
  887. #endregion
  888. /// <summary>
  889. /// 增加事件
  890. /// </summary>
  891. /// <param name="sender"></param>
  892. /// <param name="e"></param>
  893. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  894. {
  895. if (APP.IsLoginType == false)
  896. {
  897. Login();
  898. return;
  899. }
  900. APP.pageData.pagenum += 1;
  901. APP.pageData.currpage = APP.pageData.pagenum;
  902. myblackboard.changepage(APP.pageData.currpage - 1);
  903. imgCanvas.Source = null;
  904. }
  905. /// <summary>
  906. /// 打印事件
  907. /// </summary>
  908. /// <param name="sender"></param>
  909. /// <param name="e"></param>
  910. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  911. {
  912. if (APP.IsLoginType == false)
  913. {
  914. Login();
  915. return;
  916. }
  917. //for(int i=0;i< APP.pageData.pagenum; i++)
  918. //{
  919. //}
  920. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  921. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  922. try
  923. {
  924. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  925. //设置纸张横向
  926. document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  927. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
  928. document.Open();
  929. iTextSharp.text.Image image;
  930. for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
  931. {
  932. if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
  933. image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
  934. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  935. {
  936. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  937. }
  938. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  939. {
  940. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  941. }
  942. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  943. document.NewPage();
  944. document.Add(image);
  945. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  946. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  947. //p1.Leading = 150; //行间距
  948. //document.Add(p1);
  949. }
  950. Console.WriteLine("转换成功!");
  951. }
  952. catch (Exception ex)
  953. {
  954. Console.WriteLine("转换失败,原因:" + ex.Message);
  955. }
  956. document.Close();
  957. ////Console.ReadKey();
  958. }
  959. /// <summary>
  960. /// 我的
  961. /// </summary>
  962. /// <param name="sender"></param>
  963. /// <param name="e"></param>
  964. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  965. {
  966. if (APP.IsLoginType == false)
  967. {
  968. Login();
  969. return;
  970. }
  971. }
  972. /// <summary>
  973. /// 上一页
  974. /// </summary>
  975. /// <param name="sender"></param>
  976. /// <param name="e"></param>
  977. private void last_button_Click(object sender, RoutedEventArgs e)
  978. {
  979. if (APP.pageData.currpage > 1)
  980. {
  981. try
  982. {
  983. Dispatcher.Invoke(() =>
  984. {
  985. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  986. FileToolsCommon.CreateDirectory(filePath);
  987. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  988. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  989. ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  990. });
  991. }
  992. catch (Exception ex)
  993. {
  994. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
  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&& APP.pageData.currpage > 0)
  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. }
  1014. }
  1015. /// <summary>
  1016. /// 下一页
  1017. /// </summary>
  1018. /// <param name="sender"></param>
  1019. /// <param name="e"></param>
  1020. private void next_btn_Click(object sender, RoutedEventArgs e)
  1021. {
  1022. if (APP.pageData.currpage < APP.pageData.pagenum)
  1023. {
  1024. try
  1025. {
  1026. Dispatcher.Invoke(() =>
  1027. {
  1028. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1029. FileToolsCommon.CreateDirectory(filePath);
  1030. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1031. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1032. ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1033. });
  1034. }
  1035. catch (Exception ex)
  1036. {
  1037. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
  1038. }
  1039. APP.pageData.currpage += 1;
  1040. myblackboard.changepage(APP.pageData.currpage - 1);
  1041. if (APP.Paths.Length > 0)
  1042. {
  1043. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
  1044. {
  1045. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1046. }
  1047. else
  1048. {
  1049. imgCanvas.Source = null;
  1050. }
  1051. }
  1052. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1053. {
  1054. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1055. }
  1056. }
  1057. }
  1058. /// <summary>
  1059. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1060. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1061. /// </summary>
  1062. /// <param name="pdfInputPath">Word文件路径</param>
  1063. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1064. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1065. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1066. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1067. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1068. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1069. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1070. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1071. {
  1072. // 返回的图片绝对路径集合
  1073. List<string> images = new List<string>();
  1074. try
  1075. {
  1076. // open word file
  1077. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1078. // validate parameter
  1079. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1080. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1081. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1082. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1083. if (startPageNum <= 0) { startPageNum = 1; }
  1084. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1085. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1086. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1087. if (resolution <= 0) { resolution = 128; }
  1088. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1089. {
  1090. Resolution = resolution
  1091. };
  1092. // start to convert each page
  1093. for (int i = startPageNum; i <= endPageNum; i++)
  1094. {
  1095. imageSaveOptions.PageIndex = i - 1;
  1096. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1097. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1098. APP.num++;
  1099. }
  1100. imageSaveOptions = null;
  1101. doc = null;
  1102. }
  1103. catch (Exception ex)
  1104. {
  1105. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1106. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1107. }
  1108. return images;
  1109. }
  1110. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1111. {
  1112. SaveFormat sf;// = SaveFormat.Unknown;
  1113. if (imageFormat.Equals(ImageFormat.Png))
  1114. {
  1115. sf = SaveFormat.Png;
  1116. }
  1117. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1118. {
  1119. sf = SaveFormat.Jpeg;
  1120. }
  1121. else if (imageFormat.Equals(ImageFormat.Tiff))
  1122. {
  1123. sf = SaveFormat.Tiff;
  1124. }
  1125. else if (imageFormat.Equals(ImageFormat.Bmp))
  1126. {
  1127. sf = SaveFormat.Bmp;
  1128. }
  1129. else
  1130. {
  1131. sf = SaveFormat.Unknown;
  1132. }
  1133. return sf;
  1134. }
  1135. #region 图像缩放,移动
  1136. private bool mouseDown;
  1137. private System.Windows.Point mouseXY;
  1138. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1139. {
  1140. var img = sender as ContentControl;
  1141. if (img == null)
  1142. {
  1143. return;
  1144. }
  1145. img.CaptureMouse();
  1146. mouseDown = true;
  1147. mouseXY = e.GetPosition(img);
  1148. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1149. }
  1150. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1151. {
  1152. System.Windows.Point point = e.GetPosition(imgCanvas);
  1153. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1154. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1155. //{
  1156. // Console.WriteLine("在范围内");
  1157. //}
  1158. }
  1159. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1160. {
  1161. var img = sender as ContentControl;
  1162. if (img == null)
  1163. {
  1164. return;
  1165. }
  1166. img.ReleaseMouseCapture();
  1167. mouseDown = false;
  1168. }
  1169. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1170. {
  1171. var img = sender as ContentControl;
  1172. if (img == null)
  1173. {
  1174. return;
  1175. }
  1176. if (mouseDown)
  1177. {
  1178. Domousemove(img, e);
  1179. }
  1180. }
  1181. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1182. {
  1183. if (e.LeftButton != MouseButtonState.Pressed)
  1184. {
  1185. return;
  1186. }
  1187. var group = IMG.FindResource("Imageview") as TransformGroup;
  1188. var transform = group.Children[1] as TranslateTransform;
  1189. var position = e.GetPosition(img);
  1190. transform.X -= mouseXY.X - position.X;
  1191. transform.Y -= mouseXY.Y - position.Y;
  1192. mouseXY = position;
  1193. }
  1194. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1195. {
  1196. var img = sender as ContentControl;
  1197. if (img == null)
  1198. {
  1199. return;
  1200. }
  1201. var point = e.GetPosition(img);
  1202. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1203. var PicLocate = e.GetPosition(imgCanvas);
  1204. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1205. var group = IMG.FindResource("Imageview") as TransformGroup;
  1206. var delta = e.Delta * 0.001;
  1207. DowheelZoom(group, point, delta);
  1208. }
  1209. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1210. {
  1211. var pointToContent = group.Inverse.Transform(point);
  1212. var transform = group.Children[0] as ScaleTransform;
  1213. if (transform.ScaleX + delta < 0.1) return;
  1214. transform.ScaleX += delta;
  1215. transform.ScaleY += delta;
  1216. var transform1 = group.Children[1] as TranslateTransform;
  1217. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1218. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1219. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1220. }
  1221. #endregion
  1222. }
  1223. }