星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

XHMicroLessonSystemWindow.xaml.cs 62KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  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. using TStudyDigitalPen.HID;
  21. using System.Drawing;
  22. namespace XHWK.WKTool
  23. {
  24. /// <summary>
  25. /// 主页面
  26. /// </summary>
  27. public partial class XHMicroLessonSystemWindow : Window
  28. {
  29. #region 字段
  30. /// <summary>
  31. /// 文件目录窗口
  32. /// </summary>
  33. //private CountdownWindow FileDirectoryWindows = null;
  34. private FolderBrowserDialog Ofd;
  35. private DialogResult Result;
  36. public readonly BlackboardNew myblackboard;
  37. private System.Windows.Forms.DialogResult result;
  38. private System.Windows.Forms.OpenFileDialog ofd;
  39. //声明一个 DrawingAttributes 类型的变量
  40. DrawingAttributes drawingAttributes;
  41. Model_Video VideoInfo = null;
  42. //定义事件
  43. public event ChangeTextHandler ChangeTextEvent;
  44. //定义委托
  45. public delegate void ChangeTextHandler(string text);
  46. /// <summary>
  47. /// 图片
  48. /// </summary>
  49. string [] ImgPDFPath = new string[300];
  50. #endregion
  51. #region 初始化
  52. /// <summary>
  53. /// 主页面
  54. /// </summary>
  55. public XHMicroLessonSystemWindow()
  56. {
  57. 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=")));
  58. InitializeComponent();
  59. myblackboard = new BlackboardNew(blackboard_canvas);
  60. APP.pageData.pagenum = 1;
  61. APP.pageData.currpage = 1;
  62. DataContext = APP.pageData;
  63. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoType");
  64. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  65. {
  66. rbnY.IsChecked = true;
  67. }
  68. else
  69. {
  70. rbnN.IsChecked = true;
  71. }
  72. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
  73. Initialize();
  74. InitPen();
  75. }
  76. /// <summary>
  77. /// 初始化
  78. /// </summary>
  79. public void Initialize()
  80. {
  81. //创建 DrawingAttributes 类的一个实例
  82. drawingAttributes = new DrawingAttributes();
  83. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  84. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  85. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  86. blackboard_canvas.UseCustomCursor = true;
  87. drawingAttributes.FitToCurve = true;
  88. drawingAttributes.IgnorePressure = false;
  89. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  90. wfhCamera.Visibility = Visibility.Hidden;
  91. ImgPDFPath = null;
  92. ImgPDFPath = new string[300];
  93. }
  94. #endregion
  95. #region 事件
  96. /// <summary>
  97. /// 窗体移动
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  102. {
  103. DragMove();
  104. }
  105. /// <summary>
  106. /// 摄像头打开事件
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  111. {
  112. //UCCamera win = new UCCamera();
  113. ////win.Topmost = true;
  114. //win.ShowDialog();
  115. wfhCamera.Visibility = Visibility.Visible;
  116. CameraHelper.IsDisplay = true;
  117. CameraHelper.SourcePlayer = player;
  118. CameraHelper.UpdateCameraDevices();
  119. if (CameraHelper.CameraDevices.Count > 0)
  120. {
  121. CameraHelper.SetCameraDevice(0);
  122. }
  123. }
  124. /// <summary>
  125. /// 摄像头关闭事件
  126. /// </summary>
  127. /// <param name="sender"></param>
  128. /// <param name="e"></param>
  129. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  130. {
  131. wfhCamera.Visibility = Visibility.Hidden;
  132. CameraHelper.CloseDevice();
  133. }
  134. #endregion
  135. /// <summary>
  136. /// 录屏事件
  137. /// </summary>
  138. /// <param name="sender"></param>
  139. /// <param name="e"></param>
  140. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  141. {
  142. if (APP.IsLoginType == false)
  143. {
  144. Login();
  145. return;
  146. }
  147. if (APP.W_ScreenRecordingToolbarWindow == null)
  148. {
  149. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  150. {
  151. Topmost = true
  152. };
  153. APP.W_ScreenRecordingToolbarWindow.Initialize();
  154. }
  155. else
  156. {
  157. APP.W_ScreenRecordingToolbarWindow.Initialize();
  158. }
  159. //显示在右下角
  160. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 10;
  161. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 160;
  162. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  163. APP.W_ScreenRecordingToolbarWindow.Show();
  164. Hide();
  165. }
  166. /// <summary>
  167. /// 上传事件
  168. /// </summary>
  169. /// <param name="sender"></param>
  170. /// <param name="e"></param>
  171. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  172. {
  173. if (APP.IsLoginType == false)
  174. {
  175. Login();
  176. return;
  177. }
  178. FileDirectoryWindow fileDirectoryWindow = new FileDirectoryWindow();
  179. fileDirectoryWindow.Show();
  180. }
  181. /// <summary>
  182. /// 关闭事件
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. private void BtnDown_Click(object sender, RoutedEventArgs e)
  187. {
  188. APP.SaveWkData();
  189. System.Environment.Exit(0);
  190. }
  191. /// <summary>
  192. /// 设置 保存事件
  193. /// </summary>
  194. /// <param name="sender"></param>
  195. /// <param name="e"></param>
  196. private void BtnSave_Click(object sender, RoutedEventArgs e)
  197. {
  198. #region 合法性判断
  199. if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  200. {
  201. System.Windows.MessageBox.Show("路径不可为空!");
  202. return;
  203. }
  204. string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  205. if (!APP.WKData.WkPath.Equals(temp))
  206. {
  207. APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  208. if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  209. {
  210. //微课已存在
  211. MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  212. if (dr == MessageBoxResult.OK)
  213. {
  214. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  215. }
  216. else
  217. {
  218. return;
  219. }
  220. }
  221. //创建文件夹
  222. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  223. }
  224. #endregion
  225. if (rbnMP4.IsChecked == true)
  226. {
  227. //存储文件
  228. FileToolsCommon.SetConfigValue("VideoType", "1");
  229. }
  230. else if (rbnFLV.IsChecked == true)
  231. {
  232. FileToolsCommon.SetConfigValue("VideoType", "2");
  233. }
  234. else
  235. {
  236. FileToolsCommon.SetConfigValue("VideoType", "3");
  237. }
  238. if (rbnY.IsChecked == true)
  239. {
  240. FileToolsCommon.SetConfigValue("IsSound", "true");
  241. }
  242. else
  243. {
  244. FileToolsCommon.SetConfigValue("IsSound", "false");
  245. }
  246. GridMain.Visibility = Visibility.Visible;
  247. gridSetUp.Visibility = Visibility.Collapsed;
  248. }
  249. /// <summary>
  250. /// 设置事件
  251. /// </summary>
  252. /// <param name="sender"></param>
  253. /// <param name="e"></param>
  254. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  255. {
  256. GridMain.Visibility = Visibility.Collapsed;
  257. gridSetUp.Visibility = Visibility.Visible;
  258. }
  259. /// <summary>
  260. /// 设置 浏览事件
  261. /// </summary>
  262. /// <param name="sender"></param>
  263. /// <param name="e"></param>
  264. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  265. {
  266. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  267. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  268. Result = Ofd.ShowDialog();
  269. if (Result == System.Windows.Forms.DialogResult.OK)
  270. {
  271. if (Ofd.SelectedPath != "")
  272. {
  273. txbStoragePath.Text = Ofd.SelectedPath;
  274. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  275. //string temp = ofd.SelectedPath;
  276. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  277. }
  278. }
  279. }
  280. /// <summary>
  281. /// 画笔颜色事件 白色
  282. /// </summary>
  283. /// <param name="sender"></param>
  284. /// <param name="e"></param>
  285. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  286. {
  287. ////创建 DrawingAttributes 类的一个实例
  288. //drawingAttributes = new DrawingAttributes();
  289. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  290. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  291. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  292. ////设置 DrawingAttributes 的 Color 属性设置颜色
  293. drawingAttributes.Color = Colors.White;
  294. }
  295. /// <summary>
  296. /// 画笔颜色事件 红色
  297. /// </summary>
  298. /// <param name="sender"></param>
  299. /// <param name="e"></param>
  300. private void BtnRed_Click(object sender, RoutedEventArgs e)
  301. {
  302. //设置 DrawingAttributes 的 Color 属性设置颜色
  303. drawingAttributes.Color = Colors.Red;
  304. }
  305. /// <summary>
  306. /// 画笔颜色事件 灰色
  307. /// </summary>
  308. /// <param name="sender"></param>
  309. /// <param name="e"></param>
  310. private void BtnGray_Click(object sender, RoutedEventArgs e)
  311. {
  312. drawingAttributes.Color = Colors.Gray;
  313. }
  314. /// <summary>
  315. /// 画笔颜色事件 青色
  316. /// </summary>
  317. /// <param name="sender"></param>
  318. /// <param name="e"></param>
  319. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  320. {
  321. drawingAttributes.Color = Colors.LimeGreen;
  322. }
  323. /// <summary>
  324. /// 画笔颜色事件 黄色
  325. /// </summary>
  326. /// <param name="sender"></param>
  327. /// <param name="e"></param>
  328. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  329. {
  330. drawingAttributes.Color = Colors.Gold;
  331. }
  332. /// <summary>
  333. /// 画笔颜色事件 蓝色
  334. /// </summary>
  335. /// <param name="sender"></param>
  336. /// <param name="e"></param>
  337. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  338. {
  339. drawingAttributes.Color = Colors.DeepSkyBlue;
  340. }
  341. /// <summary>
  342. /// 画笔粗细事件 细
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. private void RbnFine_Click(object sender, RoutedEventArgs e)
  347. {
  348. drawingAttributes.Width = 1;
  349. drawingAttributes.Height = 1;
  350. }
  351. /// <summary>
  352. /// 画笔粗细事件 中
  353. /// </summary>
  354. /// <param name="sender"></param>
  355. /// <param name="e"></param>
  356. private void RbnIn_Click(object sender, RoutedEventArgs e)
  357. {
  358. drawingAttributes.Width = 3;
  359. drawingAttributes.Height = 3;
  360. }
  361. /// <summary>
  362. /// 画笔粗细事件 粗
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  367. {
  368. drawingAttributes.Width = 5;
  369. drawingAttributes.Height = 5;
  370. }
  371. /// <summary>
  372. /// 登陆事件
  373. /// </summary>
  374. /// <param name="sender"></param>
  375. /// <param name="e"></param>
  376. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  377. {
  378. Login();
  379. }
  380. /// <summary>
  381. /// 登陆
  382. /// </summary>
  383. private void Login()
  384. {
  385. if (APP.W_LoginWindow == null)
  386. {
  387. APP.W_LoginWindow = new LoginWindow();
  388. }
  389. else
  390. {
  391. APP.W_LoginWindow.Initialize();
  392. }
  393. APP.W_LoginWindow.ShowDialog();
  394. if (APP.IsLoginType)
  395. {
  396. txbLoginType.Text = APP.UserInfo.Username;
  397. }
  398. else
  399. {
  400. txbLoginType.Text = "未登录";
  401. }
  402. }
  403. /// <summary>
  404. /// 截图事件
  405. /// </summary>
  406. /// <param name="sender"></param>
  407. /// <param name="e"></param>
  408. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  409. {
  410. if (APP.IsLoginType == false)
  411. {
  412. Login();
  413. return;
  414. }
  415. string time = GetTimeStamp();
  416. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  417. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  418. if (APP.W_JieTuWindow != null)
  419. {
  420. APP.W_JieTuWindow.initialization();
  421. APP.W_JieTuWindow.Screenshot();
  422. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  423. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  424. }
  425. else
  426. {
  427. APP.W_JieTuWindow = new JieTuWindow();
  428. // 订阅事件
  429. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  430. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  431. APP.W_JieTuWindow.Show();
  432. }
  433. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  434. }
  435. /// <summary>
  436. /// 截图关闭窗口
  437. /// </summary>
  438. /// <param name="text"></param>
  439. private void frm_ChangeTextEvent(string text)
  440. {
  441. if ("关闭窗口".Equals(text))
  442. {
  443. if(!string.IsNullOrWhiteSpace(APP.ImgPath)&&File.Exists(APP.ImgPath))
  444. {
  445. APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
  446. if(!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  447. {
  448. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  449. }
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// 截图关闭 非正常关闭截图时,截图清空
  455. /// </summary>
  456. private void JietuWindow_click_closeJietuWindowClick()
  457. {
  458. APP.W_JieTuWindow = null;
  459. }
  460. /// <summary>
  461. /// 获取时间戳
  462. /// </summary>
  463. /// <returns></returns>
  464. public string GetTimeStamp()
  465. {
  466. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  467. return Convert.ToInt64(ts.TotalSeconds).ToString();
  468. }
  469. /// <summary>
  470. /// 导入事件
  471. /// </summary>
  472. /// <param name="sender"></param>
  473. /// <param name="e"></param>
  474. private void BtnImport_Click(object sender, RoutedEventArgs e)
  475. {
  476. if (APP.IsLoginType == false)
  477. {
  478. Login();
  479. return;
  480. }
  481. try
  482. {
  483. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  484. ofd = new System.Windows.Forms.OpenFileDialog
  485. {
  486. Filter = "文档|*.docx;*.doc;*ppt",
  487. InitialDirectory = desktopPath,
  488. Multiselect = false,
  489. AddExtension = true,
  490. DereferenceLinks = true
  491. };
  492. new Thread(
  493. o =>
  494. {
  495. Thread.Sleep(400);
  496. Dispatcher.Invoke(new Action(() =>
  497. {
  498. OpenDialog();
  499. }
  500. ));
  501. })
  502. {
  503. IsBackground = true
  504. }.Start();
  505. }
  506. catch (Exception ex)
  507. {
  508. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  509. }
  510. }
  511. private void OpenDialog()
  512. {
  513. result = ofd.ShowDialog();
  514. if (result == System.Windows.Forms.DialogResult.OK)
  515. {
  516. if (ofd.FileName != "")
  517. {
  518. #region PPT转PDF
  519. string filepath = ofd.FileName;
  520. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  521. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  522. if (type.Contains("typezsygppt"))
  523. {
  524. try
  525. {
  526. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  527. path = pathTemp + path + ".pdf";
  528. //PPT转PDF
  529. Presentation ppt = new Presentation(filepath);
  530. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  531. #endregion
  532. #region PDF转图片
  533. // 图片绝对路径集合
  534. List<string> images = new List<string>();
  535. string directoryPath = pathTemp;
  536. //aspose许可证
  537. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  538. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  539. //l.SetLicense(licenseName);
  540. //定义Jpeg转换设备
  541. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  542. var device = new Aspose.Pdf.Devices.JpegDevice();
  543. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  544. //directoryPath += quality;
  545. Directory.CreateDirectory(directoryPath);
  546. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  547. device = new Aspose.Pdf.Devices.JpegDevice(100);
  548. //遍历每一页转为jpg
  549. for (var i = 1; i <= document.Pages.Count; i++)
  550. {
  551. long ii = Timestamp();
  552. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  553. images.Add(filePathOutPut);
  554. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  555. try
  556. {
  557. device.Process(document.Pages[i], fs);
  558. fs.Close();
  559. }
  560. catch (Exception ex)
  561. {
  562. fs.Close();
  563. File.Delete(filePathOutPut);
  564. }
  565. }
  566. #endregion
  567. APP.Paths = images.ToArray();
  568. ImgPDFPath = images.ToArray();
  569. for (int i = 0; i < APP.Paths.Length; i++)
  570. {
  571. APP.pageData.pagenum += 1;
  572. }
  573. if (APP.pageData.pagenum > 1)
  574. {
  575. APP.pageData.pagenum -= 1;
  576. }
  577. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  578. {
  579. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  580. }
  581. else
  582. {
  583. imgCanvas.Source = null;
  584. }
  585. }
  586. catch (Exception ex)
  587. {
  588. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  589. }
  590. }
  591. else
  592. {
  593. try
  594. {
  595. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  596. APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  597. for (int i = 0; i < APP.Paths.Length; i++)
  598. {
  599. APP.pageData.pagenum += 1;
  600. }
  601. if (APP.pageData.pagenum > 1)
  602. {
  603. APP.pageData.pagenum -= 1;
  604. }
  605. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  606. {
  607. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  608. }
  609. else
  610. {
  611. imgCanvas.Source = null;
  612. }
  613. }
  614. catch (Exception ex)
  615. {
  616. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
  617. }
  618. }
  619. }
  620. }
  621. }
  622. /// <summary>
  623. /// 返回一个时间戳到毫秒
  624. /// </summary>
  625. /// <returns></returns>
  626. public static long Timestamp()
  627. {
  628. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  629. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  630. return timestr;
  631. }
  632. #region 录制窗口
  633. #region 变量
  634. /// <summary>
  635. /// 视频保存路径
  636. /// </summary>
  637. string RecordingPath;
  638. /// <summary>
  639. /// 图片保存路径
  640. /// </summary>
  641. string ImgPath;
  642. /// <summary>
  643. /// 音频保存路径名
  644. /// </summary>
  645. string AudioPathName;
  646. /// <summary>
  647. /// 视频保存路径名
  648. /// </summary>
  649. string VideoSavePathName;
  650. /// <summary>
  651. /// 暂停录制
  652. /// </summary>
  653. bool IsSuspendR = true;
  654. /// <summary>
  655. /// 是否首次录制
  656. /// </summary>
  657. bool IsFirstR = true;
  658. /// <summary>
  659. /// 图片
  660. /// </summary>
  661. List<string> RsImgName = null;
  662. /// <summary>
  663. /// 是否开始截图计数
  664. /// </summary>
  665. bool IsStartCount = false;
  666. #endregion
  667. /// <summary>
  668. /// 录制窗口内容
  669. /// </summary>
  670. /// <param name="sender"></param>
  671. /// <param name="e"></param>
  672. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  673. {
  674. if (APP.IsLoginType == false)
  675. {
  676. Login();
  677. return;
  678. }
  679. blackboard_canvas.Visibility = Visibility.Visible;
  680. StartRecord();
  681. }
  682. /// <summary>
  683. /// 停止录制窗口内容
  684. /// </summary>
  685. /// <param name="sender"></param>
  686. /// <param name="e"></param>
  687. private void BtnStop_Click(object sender, RoutedEventArgs e)
  688. {
  689. if (APP.IsLoginType == false)
  690. {
  691. Login();
  692. return;
  693. }
  694. blackboard_canvas.Visibility = Visibility.Collapsed;
  695. EndRecord();
  696. }
  697. System.Timers.Timer timer;
  698. /// <summary>
  699. /// 开始录制和暂停录制
  700. /// </summary>
  701. void StartRecord()
  702. {
  703. if (IsSuspendR)
  704. {
  705. if (IsFirstR)//是否第一次录制 初始化录制
  706. {
  707. VideoInfo = new Model_Video();
  708. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  709. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  710. RecordingPath = APP.WKData.WkPath;
  711. ImgPath = APP.WKData.WkPath + "temp/Image/";
  712. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  713. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  714. FileToolsCommon.CreateDirectory(RecordingPath);
  715. FileToolsCommon.CreateDirectory(ImgPath);
  716. FileToolsCommon.CreateDirectory(AudioPathName);
  717. AudioPathName += APP.WKData.WkName + ".MP3";
  718. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  719. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  720. {
  721. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  722. if (dr == MessageBoxResult.OK)
  723. {
  724. try
  725. {
  726. FileToolsCommon.DeleteFile(VideoSavePathName);
  727. APP.VideoList.RemoveAll(x => x.VidePath == VideoSavePathName);
  728. }
  729. catch (Exception ex)
  730. {
  731. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  732. }
  733. }
  734. else
  735. {
  736. return;
  737. }
  738. }
  739. IsFirstR = false;
  740. RsImgName = new List<string>();
  741. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  742. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  743. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  744. timer.Enabled = true; //启动计时器
  745. }
  746. #region 录像倒计时
  747. if (APP.W_CountdownWindow == null)
  748. {
  749. APP.W_CountdownWindow = new CountdownWindow();
  750. //APP.W_CountdownWindow.Topmost = true;
  751. }
  752. else
  753. {
  754. APP.W_CountdownWindow.Initialize();
  755. APP.W_CountdownWindow.Topmost = true;
  756. }
  757. APP.W_CountdownWindow.Show();
  758. #endregion
  759. //继续录制
  760. IsSuspendR = false;
  761. //BtnRecording.Content = "暂停录制";
  762. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  763. TxbRecordingWord.Text = "暂停";
  764. try
  765. {
  766. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  767. new Thread(new ThreadStart(new Action(() =>
  768. {
  769. Thread.Sleep(1000);
  770. Dispatcher.Invoke(() =>
  771. {
  772. IsStartCount = true;
  773. //timer.Start();
  774. });
  775. }))).Start();
  776. }
  777. catch (Exception ex)
  778. {
  779. System.Windows.MessageBox.Show(ex.Message);
  780. }
  781. }
  782. else
  783. {
  784. //暂停
  785. IsSuspendR = true;
  786. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  787. TxbRecordingWord.Text = "继续";
  788. try
  789. {
  790. APP.FFmpeg.SuspendFFmpeg();
  791. new Thread(new ThreadStart(new Action(() =>
  792. {
  793. while (APP.FFmpeg.myProcess != null)
  794. {
  795. Thread.Sleep(100);
  796. }
  797. IsStartCount = false;
  798. }))).Start();
  799. }
  800. catch (Exception ex)
  801. {
  802. System.Windows.MessageBox.Show(ex.Message);
  803. }
  804. }
  805. }
  806. /// <summary>
  807. /// 录制保存图片
  808. /// </summary>
  809. /// <param name="sender"></param>
  810. /// <param name="e"></param>
  811. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  812. {
  813. if (IsStartCount)
  814. {
  815. try
  816. {
  817. Dispatcher.Invoke(() =>
  818. {
  819. string FilePathName = ImgPath + RsImgName.Count + ".png";
  820. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  821. RsImgName.Add(FilePathName);
  822. });
  823. }
  824. catch (Exception ex)
  825. {
  826. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  827. }
  828. }
  829. }
  830. /// <summary>
  831. /// 停止录制并生成录制文件
  832. /// </summary>
  833. void EndRecord()
  834. {
  835. if (!IsFirstR)
  836. {
  837. IsFirstR = true;
  838. IsSuspendR = true;
  839. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  840. TxbRecordingWord.Text = "录制";
  841. try
  842. {
  843. APP.FFmpeg.StopFFmpeg(AudioPathName);
  844. new Thread(new ThreadStart(new Action(() =>
  845. {
  846. while (APP.FFmpeg.myProcess != null)
  847. {
  848. Thread.Sleep(100);
  849. }
  850. Dispatcher.Invoke(() =>
  851. {
  852. IsStartCount = false;
  853. timer.Stop();
  854. });
  855. }))).Start();
  856. new Thread(new ThreadStart(new Action(() =>
  857. {
  858. while (APP.FFmpeg.myProcess != null)
  859. {
  860. Thread.Sleep(100);
  861. }
  862. }))).Start();
  863. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  864. //生成缩略图
  865. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  866. FileToolsCommon.CreateDirectory(ThumbnailPath);
  867. //缩略图存储位置
  868. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  869. new Thread(new ThreadStart(new Action(() =>
  870. {
  871. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  872. {
  873. Thread.Sleep(100);
  874. }
  875. FileToolsCommon.DeleteFile(ThumbnailPathName);
  876. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  877. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  878. VideoInfo.VidePath = VideoSavePathName;
  879. VideoInfo.ThumbnailPath = ThumbnailPathName;
  880. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  881. APP.VideoList.Add(VideoInfo);
  882. //保存数据
  883. APP.SaveWkData();
  884. }))).Start();
  885. //List<Model_Video> VideoList
  886. }
  887. catch (Exception ex)
  888. {
  889. System.Windows.MessageBox.Show(ex.Message);
  890. }
  891. }
  892. }
  893. #endregion
  894. /// <summary>
  895. /// 增加事件
  896. /// </summary>
  897. /// <param name="sender"></param>
  898. /// <param name="e"></param>
  899. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  900. {
  901. if (APP.IsLoginType == false)
  902. {
  903. Login();
  904. return;
  905. }
  906. APP.pageData.pagenum += 1;
  907. APP.pageData.currpage = APP.pageData.pagenum;
  908. myblackboard.changepage(APP.pageData.currpage - 1);
  909. imgCanvas.Source = null;
  910. }
  911. /// <summary>
  912. /// 打印事件
  913. /// </summary>
  914. /// <param name="sender"></param>
  915. /// <param name="e"></param>
  916. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  917. {
  918. if (APP.IsLoginType == false)
  919. {
  920. Login();
  921. return;
  922. }
  923. //for(int i=0;i< APP.pageData.pagenum; i++)
  924. //{
  925. //}
  926. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  927. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  928. try
  929. {
  930. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  931. //设置纸张横向
  932. document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  933. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
  934. document.Open();
  935. iTextSharp.text.Image image;
  936. for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
  937. {
  938. if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
  939. image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
  940. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  941. {
  942. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  943. }
  944. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  945. {
  946. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  947. }
  948. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  949. document.NewPage();
  950. document.Add(image);
  951. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  952. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  953. //p1.Leading = 150; //行间距
  954. //document.Add(p1);
  955. }
  956. Console.WriteLine("转换成功!");
  957. }
  958. catch (Exception ex)
  959. {
  960. Console.WriteLine("转换失败,原因:" + ex.Message);
  961. }
  962. document.Close();
  963. ////Console.ReadKey();
  964. }
  965. /// <summary>
  966. /// 我的
  967. /// </summary>
  968. /// <param name="sender"></param>
  969. /// <param name="e"></param>
  970. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  971. {
  972. if (APP.IsLoginType == false)
  973. {
  974. Login();
  975. return;
  976. }
  977. }
  978. /// <summary>
  979. /// 上一页
  980. /// </summary>
  981. /// <param name="sender"></param>
  982. /// <param name="e"></param>
  983. private void last_button_Click(object sender, RoutedEventArgs e)
  984. {
  985. if (APP.pageData.currpage > 1)
  986. {
  987. try
  988. {
  989. Dispatcher.Invoke(() =>
  990. {
  991. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  992. FileToolsCommon.CreateDirectory(filePath);
  993. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  994. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  995. ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  996. });
  997. }
  998. catch (Exception ex)
  999. {
  1000. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
  1001. }
  1002. APP.pageData.currpage -= 1;
  1003. myblackboard.changepage(APP.pageData.currpage - 1);
  1004. if (APP.Paths.Length > 0)
  1005. {
  1006. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length&& APP.pageData.currpage > 0)
  1007. {
  1008. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  1009. }
  1010. else
  1011. {
  1012. imgCanvas.Source = null;
  1013. }
  1014. }
  1015. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1016. {
  1017. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1018. }
  1019. }
  1020. }
  1021. /// <summary>
  1022. /// 下一页
  1023. /// </summary>
  1024. /// <param name="sender"></param>
  1025. /// <param name="e"></param>
  1026. private void next_btn_Click(object sender, RoutedEventArgs e)
  1027. {
  1028. if (APP.pageData.currpage < APP.pageData.pagenum)
  1029. {
  1030. try
  1031. {
  1032. Dispatcher.Invoke(() =>
  1033. {
  1034. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1035. FileToolsCommon.CreateDirectory(filePath);
  1036. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1037. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1038. ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1039. });
  1040. }
  1041. catch (Exception ex)
  1042. {
  1043. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
  1044. }
  1045. APP.pageData.currpage += 1;
  1046. myblackboard.changepage(APP.pageData.currpage - 1);
  1047. if (APP.Paths.Length > 0)
  1048. {
  1049. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
  1050. {
  1051. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1052. }
  1053. else
  1054. {
  1055. imgCanvas.Source = null;
  1056. }
  1057. }
  1058. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1059. {
  1060. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1061. }
  1062. }
  1063. }
  1064. /// <summary>
  1065. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1066. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1067. /// </summary>
  1068. /// <param name="pdfInputPath">Word文件路径</param>
  1069. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1070. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1071. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1072. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1073. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1074. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1075. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1076. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1077. {
  1078. // 返回的图片绝对路径集合
  1079. List<string> images = new List<string>();
  1080. try
  1081. {
  1082. // open word file
  1083. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1084. // validate parameter
  1085. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1086. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1087. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1088. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1089. if (startPageNum <= 0) { startPageNum = 1; }
  1090. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1091. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1092. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1093. if (resolution <= 0) { resolution = 128; }
  1094. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1095. {
  1096. Resolution = resolution
  1097. };
  1098. // start to convert each page
  1099. for (int i = startPageNum; i <= endPageNum; i++)
  1100. {
  1101. imageSaveOptions.PageIndex = i - 1;
  1102. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1103. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1104. APP.num++;
  1105. }
  1106. imageSaveOptions = null;
  1107. doc = null;
  1108. }
  1109. catch (Exception ex)
  1110. {
  1111. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1112. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1113. }
  1114. return images;
  1115. }
  1116. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1117. {
  1118. SaveFormat sf;// = SaveFormat.Unknown;
  1119. if (imageFormat.Equals(ImageFormat.Png))
  1120. {
  1121. sf = SaveFormat.Png;
  1122. }
  1123. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1124. {
  1125. sf = SaveFormat.Jpeg;
  1126. }
  1127. else if (imageFormat.Equals(ImageFormat.Tiff))
  1128. {
  1129. sf = SaveFormat.Tiff;
  1130. }
  1131. else if (imageFormat.Equals(ImageFormat.Bmp))
  1132. {
  1133. sf = SaveFormat.Bmp;
  1134. }
  1135. else
  1136. {
  1137. sf = SaveFormat.Unknown;
  1138. }
  1139. return sf;
  1140. }
  1141. #region 图像缩放,移动
  1142. private bool mouseDown;
  1143. private System.Windows.Point mouseXY;
  1144. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1145. {
  1146. var img = sender as ContentControl;
  1147. if (img == null)
  1148. {
  1149. return;
  1150. }
  1151. img.CaptureMouse();
  1152. mouseDown = true;
  1153. mouseXY = e.GetPosition(img);
  1154. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1155. }
  1156. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1157. {
  1158. System.Windows.Point point = e.GetPosition(imgCanvas);
  1159. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1160. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1161. //{
  1162. // Console.WriteLine("在范围内");
  1163. //}
  1164. }
  1165. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1166. {
  1167. var img = sender as ContentControl;
  1168. if (img == null)
  1169. {
  1170. return;
  1171. }
  1172. img.ReleaseMouseCapture();
  1173. mouseDown = false;
  1174. }
  1175. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1176. {
  1177. var img = sender as ContentControl;
  1178. if (img == null)
  1179. {
  1180. return;
  1181. }
  1182. if (mouseDown)
  1183. {
  1184. Domousemove(img, e);
  1185. }
  1186. }
  1187. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1188. {
  1189. if (e.LeftButton != MouseButtonState.Pressed)
  1190. {
  1191. return;
  1192. }
  1193. var group = IMG.FindResource("Imageview") as TransformGroup;
  1194. var transform = group.Children[1] as TranslateTransform;
  1195. var position = e.GetPosition(img);
  1196. transform.X -= mouseXY.X - position.X;
  1197. transform.Y -= mouseXY.Y - position.Y;
  1198. mouseXY = position;
  1199. }
  1200. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1201. {
  1202. var img = sender as ContentControl;
  1203. if (img == null)
  1204. {
  1205. return;
  1206. }
  1207. var point = e.GetPosition(img);
  1208. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1209. var PicLocate = e.GetPosition(imgCanvas);
  1210. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1211. var group = IMG.FindResource("Imageview") as TransformGroup;
  1212. var delta = e.Delta * 0.001;
  1213. DowheelZoom(group, point, delta);
  1214. }
  1215. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1216. {
  1217. var pointToContent = group.Inverse.Transform(point);
  1218. var transform = group.Children[0] as ScaleTransform;
  1219. if (transform.ScaleX + delta < 0.1) return;
  1220. transform.ScaleX += delta;
  1221. transform.ScaleY += delta;
  1222. var transform1 = group.Children[1] as TranslateTransform;
  1223. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1224. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1225. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1226. }
  1227. #endregion
  1228. #region 点阵笔相关
  1229. #region 值初始化
  1230. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  1231. /// <summary>
  1232. /// A4点阵纸点阵宽度
  1233. /// </summary>
  1234. private const int A4_WIDTH = 5600;
  1235. /// <summary>
  1236. /// A4点阵纸点阵高度
  1237. /// </summary>
  1238. private const int A4_HEIGHT = 7920;
  1239. /// <summary>
  1240. /// 画板
  1241. /// </summary>
  1242. private Graphics graphics;
  1243. /// <summary>
  1244. /// 笔画坐标数组
  1245. /// </summary>
  1246. private List<System.Drawing.Point> stroke;
  1247. /// <summary>
  1248. /// 笔序列号
  1249. /// </summary>
  1250. private string penSerial;
  1251. /// <summary>
  1252. /// 笔是否在点
  1253. /// </summary>
  1254. private bool isPenDown;
  1255. //当前点阵地址
  1256. private string currentPageSerial = string.Empty;
  1257. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  1258. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  1259. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  1260. #endregion
  1261. public void InitPen()
  1262. {
  1263. stroke = new List<System.Drawing.Point>();
  1264. //获取点阵笔实例,并绑定点阵笔事件
  1265. //将授权文件内容传入,获取点阵笔对象实例
  1266. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  1267. //绑定笔连接事件
  1268. APP.digitalPen.PenConnected += OnPenConnect;
  1269. //绑定笔断开事件
  1270. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  1271. //绑定笔书写输出坐标事件
  1272. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  1273. //绑定抬笔事件
  1274. APP.digitalPen.PenUp += OnPenUp;
  1275. //绑定落笔事件
  1276. APP.digitalPen.PenDown += OnPenDown;
  1277. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  1278. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  1279. //完成初始化点阵笔,开始与点阵笔通信
  1280. ERROR_CODE ER = APP.digitalPen.Start();
  1281. ////绑定笔在新的点阵地址页面书写事件
  1282. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  1283. ////绑定笔信息事件
  1284. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  1285. //启动接收笔数据,完成初始化工作
  1286. ERROR_CODE rc = APP.digitalPen.Start();
  1287. //判断是否成功
  1288. if (ER != ERROR_CODE.ERROR_OK)
  1289. {
  1290. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  1291. }
  1292. }
  1293. /// <summary>
  1294. /// 落笔
  1295. /// </summary>
  1296. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1297. /// <param name="penSerial">点阵笔序列号</param>
  1298. /// <param name="penType">点阵笔型号编号</param>
  1299. private void OnPenDown(ulong time, string penSerial, int penType)
  1300. {
  1301. if (this.CheckAccess())
  1302. {
  1303. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  1304. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1305. }
  1306. else
  1307. {
  1308. //labPenSerial.Text = penSerial;
  1309. //labPenStatus.Text = "PenDown";
  1310. isPenDown = true;
  1311. }
  1312. }
  1313. /// <summary>
  1314. /// 抬笔
  1315. /// </summary>
  1316. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1317. /// <param name="penSerial">点阵笔序列号</param>
  1318. /// <param name="penType">点阵笔型号编号</param>
  1319. private void OnPenUp(ulong time, string penSerial, int penType)
  1320. {
  1321. if (this.CheckAccess())
  1322. {
  1323. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  1324. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1325. }
  1326. else
  1327. {
  1328. isPenDown = false;
  1329. APP.PenSerial = penSerial;
  1330. //int leftPoints = stroke.Count % 3;
  1331. //if (0 != leftPoints)
  1332. //{
  1333. // int from = stroke.Count - leftPoints - 1;
  1334. // if (from < 0)
  1335. // from = 0;
  1336. // int to = stroke.Count - 1;
  1337. // DrawCoordinates(from, to);
  1338. //}
  1339. stroke.Clear();
  1340. }
  1341. }
  1342. /// <summary>
  1343. /// 笔断开
  1344. /// </summary>
  1345. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1346. /// <param name="penSerial">点阵笔序列号</param>
  1347. /// <param name="penType">点阵笔型号编号</param>
  1348. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  1349. {
  1350. if (this.CheckAccess())
  1351. {
  1352. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  1353. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1354. }
  1355. else
  1356. {
  1357. APP.PenSerial = penSerial;
  1358. APP.PenStatus = false;
  1359. }
  1360. }
  1361. /// <summary>
  1362. /// 笔连接
  1363. /// </summary>
  1364. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1365. /// <param name="penSerial">点阵笔序列号</param>
  1366. /// <param name="penType">点阵笔型号编号</param>
  1367. private void OnPenConnect(ulong time, string penSerial, int penType)
  1368. {
  1369. if (this.CheckAccess())
  1370. {
  1371. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  1372. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1373. }
  1374. else
  1375. {
  1376. APP.PenSerial = penSerial;
  1377. APP.PenStatus = true;
  1378. this.penSerial = penSerial;
  1379. //连接后,在获取笔数据前,可以清除笔内的历史数据
  1380. //APP.digitalPen.ClearMemory(penSerial);
  1381. //开始接收笔数据
  1382. APP.digitalPen.GetPenData(penSerial);
  1383. }
  1384. }
  1385. /// <summary>
  1386. /// 电池电量
  1387. /// </summary>
  1388. /// <param name="time"></param>
  1389. /// <param name="penSerial"></param>
  1390. /// <param name="penType"></param>
  1391. /// <param name="capacity"></param>
  1392. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  1393. {
  1394. if (this.CheckAccess())
  1395. {
  1396. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  1397. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  1398. }
  1399. else
  1400. {
  1401. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  1402. }
  1403. }
  1404. /// <summary>
  1405. /// 已用存储
  1406. /// </summary>
  1407. /// <param name="time"></param>
  1408. /// <param name="penSerial"></param>
  1409. /// <param name="penType"></param>
  1410. /// <param name="fillLevel"></param>
  1411. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  1412. {
  1413. if (this.CheckAccess())
  1414. {
  1415. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  1416. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  1417. }
  1418. else
  1419. {
  1420. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  1421. }
  1422. }
  1423. /// <summary>
  1424. /// 笔书写,收到坐标
  1425. /// </summary>
  1426. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1427. /// <param name="penSerial">点阵笔序列号</param>
  1428. /// <param name="penType">点阵笔型号编号</param>
  1429. /// <param name="pageSerial">点阵地址</param>
  1430. /// <param name="cx">x坐标</param>
  1431. /// <param name="cy">y坐标</param>
  1432. /// <param name="force">压力值</param>
  1433. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  1434. {
  1435. if (this.CheckAccess())
  1436. {
  1437. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  1438. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  1439. }
  1440. else
  1441. {
  1442. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  1443. if (!isPenDown)
  1444. {
  1445. return;
  1446. }
  1447. stroke.Add(new System.Drawing.Point(cx, cy));
  1448. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  1449. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  1450. //点
  1451. double testX=(double)cx * PropW;
  1452. double testY=(double)cy * PropH;
  1453. //pageSerial //点阵IP地址 与打印的页面关联
  1454. ////每3个点画一条曲线
  1455. //if (stroke.Count % 3 == 0)
  1456. //{
  1457. // int from = stroke.Count - 3 - 1;
  1458. // if (from < 0)
  1459. // from = 0;
  1460. // int to = stroke.Count - 1;
  1461. // DrawCoordinates(from, to);
  1462. //}
  1463. }
  1464. }
  1465. /// <summary>
  1466. /// 停止笔
  1467. /// </summary>
  1468. public void StopDigitalPen()
  1469. {
  1470. //停止,释放资源
  1471. APP.digitalPen.Stop();
  1472. }
  1473. /// <summary>
  1474. /// 清空笔内存储
  1475. /// </summary>
  1476. public void ClearPenStorage()
  1477. {
  1478. if (!string.IsNullOrEmpty(penSerial))
  1479. APP.digitalPen.ClearMemory(penSerial);
  1480. }
  1481. /// <summary>
  1482. /// 获取剩余电量
  1483. /// </summary>
  1484. public void GetPenElectricityQuantity()
  1485. {
  1486. if (!string.IsNullOrEmpty(penSerial))
  1487. APP.digitalPen.GetBatteryCapacity(penSerial);
  1488. }
  1489. /// <summary>
  1490. /// 获取存储空间
  1491. /// </summary>
  1492. public void GetUsedStorage()
  1493. {
  1494. if (!string.IsNullOrEmpty(penSerial))
  1495. APP.digitalPen.GetMemoryFillLevel(penSerial);
  1496. }
  1497. /// <summary>
  1498. /// 开启悬浮
  1499. /// </summary>
  1500. public void 开启悬浮()
  1501. {
  1502. if (!string.IsNullOrEmpty(penSerial))
  1503. APP.digitalPen.SetPenHoverMode(true, penSerial);
  1504. }
  1505. /// <summary>
  1506. /// 关闭悬浮
  1507. /// </summary>
  1508. public void 关闭悬浮()
  1509. {
  1510. if (!string.IsNullOrEmpty(penSerial))
  1511. APP.digitalPen.SetPenHoverMode(false, penSerial);
  1512. }
  1513. #endregion
  1514. }
  1515. }