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

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