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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  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. /// <summary>
  54. /// 当前颜色
  55. /// </summary>
  56. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Black;
  57. /// <summary>
  58. /// 笔迹粗细
  59. /// </summary>
  60. private int Size = 2;
  61. #endregion
  62. #region 初始化
  63. /// <summary>
  64. /// 主页面
  65. /// </summary>
  66. public XHMicroLessonSystemWindow()
  67. {
  68. 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=")));
  69. InitializeComponent();
  70. btnPrint.IsEnabled = false;
  71. myblackboard = new BlackboardNew(blackboard_canvas);
  72. APP.pageData.pagenum = 0;
  73. APP.pageData.currpage = 0;
  74. DataContext = APP.pageData;
  75. //APP.SaveDraw();//画板模型第一页初始化
  76. APP.PageDrawList = new List<Model_DrawData>();
  77. Model_DrawData model_DrawData = new Model_DrawData();
  78. model_DrawData.PageNum = APP.pageData.currpage;
  79. APP.PageDrawList.Add(model_DrawData);
  80. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  81. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  82. {
  83. rbnY.IsChecked = true;
  84. }
  85. else
  86. {
  87. rbnN.IsChecked = true;
  88. }
  89. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  90. Initialize();
  91. InitPen();
  92. }
  93. /// <summary>
  94. /// 初始化
  95. /// </summary>
  96. public void Initialize()
  97. {
  98. #region 数据初始化
  99. APP.pageData.pagenum = 0;
  100. APP.pageData.currpage = APP.pageData.pagenum;
  101. #endregion
  102. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  103. //创建 DrawingAttributes 类的一个实例
  104. drawingAttributes = new DrawingAttributes();
  105. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  106. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  107. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  108. blackboard_canvas.UseCustomCursor = true;
  109. drawingAttributes.FitToCurve = true;
  110. drawingAttributes.IgnorePressure = false;
  111. drawingAttributes.Width = Size;
  112. drawingAttributes.Height = Size;
  113. drawingAttributes.Color = Color;
  114. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  115. //wfhCamera.Visibility = Visibility.Hidden;
  116. ImgPDFPath = null;
  117. ImgPDFPath = new string[300];
  118. }
  119. #endregion
  120. #region 事件
  121. /// <summary>
  122. /// 窗体移动
  123. /// </summary>
  124. /// <param name="sender"></param>
  125. /// <param name="e"></param>
  126. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  127. {
  128. DragMove();
  129. }
  130. #region 摄像头
  131. System.Timers.Timer times;
  132. List<string> RbnOpen;
  133. bool IsRbnOpen = false;
  134. /// <summary>
  135. /// 摄像头打开事件
  136. /// </summary>
  137. /// <param name="sender"></param>
  138. /// <param name="e"></param>
  139. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  140. {
  141. //UCCamera win = new UCCamera();
  142. ////win.Topmost = true;
  143. //win.ShowDialog();
  144. //wfhCamera.Visibility = Visibility.Visible;
  145. //CameraHelper.IsDisplay = true;
  146. //CameraHelper.SourcePlayer = player;
  147. CameraHelper.UpdateCameraDevices();
  148. if (CameraHelper.CameraDevices.Count > 0)
  149. {
  150. CameraHelper.SetCameraDevice(0);
  151. RbnOpen = new List<string>();
  152. times = new System.Timers.Timer(300);//设置执行一次(false)还是一直执行(true)
  153. times.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  154. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  155. times.Enabled = true; //启动计时器
  156. IsRbnOpen = true;
  157. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  158. FileToolsCommon.CreateDirectory(imgPath);
  159. }
  160. }
  161. int I = 9999;
  162. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  163. {
  164. if (IsRbnOpen)
  165. {
  166. try
  167. {
  168. Dispatcher.Invoke(() =>
  169. {
  170. if (I > 10010)
  171. {
  172. long time = Timestamp();
  173. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  174. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  175. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  176. if (!string.IsNullOrWhiteSpace(path))
  177. {
  178. RbnOpen.Add(path);
  179. imgPlayerRight.Visibility = Visibility.Visible;
  180. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  181. if ("1".Equals(APP.CameraPosition))
  182. {
  183. imgPlayerRight.Visibility = Visibility.Visible;
  184. imgPlayerLeft.Visibility = Visibility.Collapsed;
  185. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  186. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  187. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  188. }
  189. else if ("2".Equals(APP.CameraPosition))
  190. {
  191. imgPlayerRight.Visibility = Visibility.Collapsed;
  192. imgPlayerLeft.Visibility = Visibility.Visible;
  193. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  194. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  195. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  196. }
  197. else if ("3".Equals(APP.CameraPosition))
  198. {
  199. imgPlayerRight.Visibility = Visibility.Collapsed;
  200. imgPlayerLeft.Visibility = Visibility.Collapsed;
  201. imgPlayerRightUnder.Visibility = Visibility.Visible;
  202. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  203. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  204. }
  205. else if ("4".Equals(APP.CameraPosition))
  206. {
  207. imgPlayerRight.Visibility = Visibility.Collapsed;
  208. imgPlayerLeft.Visibility = Visibility.Collapsed;
  209. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  210. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  211. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  212. }
  213. else
  214. {
  215. imgPlayerLeft.Visibility = Visibility.Collapsed;
  216. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  217. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  218. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  219. }
  220. }
  221. }
  222. I++;
  223. });
  224. }
  225. catch (Exception ex)
  226. {
  227. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// 摄像头关闭事件
  233. /// </summary>
  234. /// <param name="sender"></param>
  235. /// <param name="e"></param>
  236. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  237. {
  238. IsRbnOpen = false;
  239. imgPlayerRight.Visibility = Visibility.Collapsed;
  240. imgPlayerLeft.Visibility = Visibility.Collapsed;
  241. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  242. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  243. CameraHelper.CloseDevice();
  244. I = 9999;
  245. }
  246. #endregion
  247. #endregion
  248. /// <summary>
  249. /// 录屏事件
  250. /// </summary>
  251. /// <param name="sender"></param>
  252. /// <param name="e"></param>
  253. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  254. {
  255. #region 限制只允许录制一个录屏 废弃
  256. //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  257. //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  258. //{
  259. // MessageBoxResult dr = System.Windows.MessageBox.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  260. // if (dr == MessageBoxResult.OK)
  261. // {
  262. // try
  263. // {
  264. // FileToolsCommon.DeleteFile(RecordScreenPathName);
  265. // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  266. // }
  267. // catch (Exception ex)
  268. // {
  269. // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  270. // }
  271. // }
  272. // else
  273. // {
  274. // return;
  275. // }
  276. //}
  277. #endregion
  278. if (APP.W_ScreenRecordingToolbarWindow == null)
  279. {
  280. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  281. {
  282. Topmost = true
  283. };
  284. APP.W_ScreenRecordingToolbarWindow.Initialize();
  285. }
  286. else
  287. {
  288. APP.W_ScreenRecordingToolbarWindow.Initialize();
  289. }
  290. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  291. //显示在右下角
  292. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  293. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  294. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  295. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  296. APP.W_ScreenRecordingToolbarWindow.Show();
  297. Hide();
  298. }
  299. /// <summary>
  300. /// 保存录屏中
  301. /// </summary>
  302. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  303. {
  304. TxbRecordScreenWord.Text = "保存中";//
  305. btnScreenRecording.IsEnabled = false;
  306. new Thread(new ThreadStart(new Action(() =>
  307. {
  308. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  309. {
  310. Thread.Sleep(100);
  311. }
  312. Dispatcher.Invoke(() =>
  313. {
  314. btnScreenRecording.IsEnabled = true;
  315. TxbRecordScreenWord.Text = "录屏";
  316. });
  317. }))).Start();
  318. }
  319. /// <summary>
  320. /// 上传事件
  321. /// </summary>
  322. /// <param name="sender"></param>
  323. /// <param name="e"></param>
  324. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  325. {
  326. if (APP.IsLoginType == false)
  327. {
  328. Login();
  329. return;
  330. }
  331. if (APP.fileDirectoryWindow == null)
  332. {
  333. APP.fileDirectoryWindow = new FileDirectoryWindow();
  334. //APP.fileDirectoryWindow.Topmost = true;
  335. APP.fileDirectoryWindow.Owner = this;
  336. }
  337. else
  338. {
  339. APP.fileDirectoryWindow.Initialize();
  340. }
  341. APP.fileDirectoryWindow.ShowDialog();
  342. }
  343. /// <summary>
  344. /// 关闭事件
  345. /// </summary>
  346. /// <param name="sender"></param>
  347. /// <param name="e"></param>
  348. private void BtnDown_Click(object sender, RoutedEventArgs e)
  349. {
  350. if (IsFirstR)
  351. {
  352. APP.Killffmpeg();
  353. APP.SaveWkData();
  354. APP.SaveDraw();
  355. Thread.Sleep(100);
  356. System.Environment.Exit(0);
  357. }
  358. else
  359. {
  360. MessageBoxResult dr = System.Windows.MessageBox.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  361. if (dr == MessageBoxResult.OK)
  362. {
  363. APP.SaveWkData();
  364. APP.SaveDraw();
  365. BtnStop_Click(null, null);
  366. while (!IsFirstR)
  367. {
  368. Thread.Sleep(100);
  369. }
  370. System.Environment.Exit(0);
  371. }
  372. else
  373. {
  374. return;
  375. }
  376. }
  377. }
  378. /// <summary>
  379. /// 设置 保存事件
  380. /// </summary>
  381. /// <param name="sender"></param>
  382. /// <param name="e"></param>
  383. private void BtnSave_Click(object sender, RoutedEventArgs e)
  384. {
  385. #region 合法性判断
  386. //if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  387. //{
  388. // System.Windows.MessageBox.Show("路径不可为空!");
  389. // return;
  390. //}
  391. //string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  392. //if (!APP.WKData.WkPath.Equals(temp))
  393. //{
  394. // APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  395. // if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  396. // {
  397. // //微课已存在
  398. // MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  399. // if (dr == MessageBoxResult.OK)
  400. // {
  401. // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  402. // }
  403. // else
  404. // {
  405. // return;
  406. // }
  407. // }
  408. // //创建文件夹
  409. // FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  410. //}
  411. #endregion
  412. if (rbnMP4.IsChecked == true)
  413. {
  414. //存储文件
  415. FileToolsCommon.SetConfigValue("VideoType", "1");
  416. }
  417. else if (rbnFLV.IsChecked == true)
  418. {
  419. FileToolsCommon.SetConfigValue("VideoType", "2");
  420. }
  421. else
  422. {
  423. FileToolsCommon.SetConfigValue("VideoType", "3");
  424. }
  425. if (rbnY.IsChecked == true)
  426. {
  427. FileToolsCommon.SetConfigValue("IsSound", "true");
  428. }
  429. else
  430. {
  431. FileToolsCommon.SetConfigValue("IsSound", "false");
  432. }
  433. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  434. if (rbnRight.IsChecked == true)
  435. {
  436. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  437. }
  438. else if (rbnLeft.IsChecked == true)
  439. {
  440. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  441. }
  442. else if (rbnRightUnder.IsChecked == true)
  443. {
  444. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  445. }
  446. else if (rbnLeftUnder.IsChecked == true)
  447. {
  448. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  449. }
  450. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  451. GridMain.Visibility = Visibility.Visible;
  452. gridSetUp.Visibility = Visibility.Collapsed;
  453. imgPlayerRight.Visibility = Visibility.Collapsed;
  454. imgPlayerLeft.Visibility = Visibility.Collapsed;
  455. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  456. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  457. }
  458. /// <summary>
  459. /// 设置事件
  460. /// </summary>
  461. /// <param name="sender"></param>
  462. /// <param name="e"></param>
  463. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  464. {
  465. if (!TxbRecordingWord.Text.Equals("暂停"))
  466. {
  467. GridMain.Visibility = Visibility.Collapsed;
  468. gridSetUp.Visibility = Visibility.Visible;
  469. txbStoragePath.Content = APP.WKData.WkPath;
  470. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  471. if ("1".Equals(APP.CameraPosition))
  472. {
  473. rbnRight.IsChecked = true;
  474. }
  475. else if ("2".Equals(APP.CameraPosition))
  476. {
  477. rbnLeft.IsChecked = true;
  478. }
  479. else if ("3".Equals(APP.CameraPosition))
  480. {
  481. rbnRightUnder.IsChecked = true;
  482. }
  483. else if ("4".Equals(APP.CameraPosition))
  484. {
  485. rbnLeftUnder.IsChecked = true;
  486. }
  487. }
  488. }
  489. /// <summary>
  490. /// 设置 浏览事件
  491. /// </summary>
  492. /// <param name="sender"></param>
  493. /// <param name="e"></param>
  494. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  495. {
  496. System.Diagnostics.Process.Start(APP.WKData.WkPath);
  497. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  498. //Ofd = new System.Windows.Forms.FolderBrowserDialog();
  499. //Result = Ofd.ShowDialog();
  500. //if (Result == System.Windows.Forms.DialogResult.OK)
  501. //{
  502. // if (Ofd.SelectedPath != "")
  503. // {
  504. // //txbStoragePath.Text = Ofd.SelectedPath;
  505. // //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  506. // //string temp = ofd.SelectedPath;
  507. // //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  508. // }
  509. //}
  510. }
  511. /// <summary>
  512. /// 画笔颜色事件 白色
  513. /// </summary>
  514. /// <param name="sender"></param>
  515. /// <param name="e"></param>
  516. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  517. {
  518. ////创建 DrawingAttributes 类的一个实例
  519. //drawingAttributes = new DrawingAttributes();
  520. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  521. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  522. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  523. ////设置 DrawingAttributes 的 Color 属性设置颜色
  524. drawingAttributes.Color = Colors.White;
  525. Color = Colors.White;
  526. }
  527. /// <summary>
  528. /// 画笔颜色事件 红色
  529. /// </summary>
  530. /// <param name="sender"></param>
  531. /// <param name="e"></param>
  532. private void BtnRed_Click(object sender, RoutedEventArgs e)
  533. {
  534. //设置 DrawingAttributes 的 Color 属性设置颜色
  535. drawingAttributes.Color = Colors.Red;
  536. Color = Colors.Red;
  537. }
  538. /// <summary>
  539. /// 画笔颜色事件 灰色
  540. /// </summary>
  541. /// <param name="sender"></param>
  542. /// <param name="e"></param>
  543. private void BtnGray_Click(object sender, RoutedEventArgs e)
  544. {
  545. drawingAttributes.Color = Colors.Gray;
  546. Color = Colors.Gray;
  547. }
  548. /// <summary>
  549. /// 画笔颜色事件 青色
  550. /// </summary>
  551. /// <param name="sender"></param>
  552. /// <param name="e"></param>
  553. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  554. {
  555. drawingAttributes.Color = Colors.LimeGreen;
  556. Color = Colors.LimeGreen;
  557. }
  558. /// <summary>
  559. /// 画笔颜色事件 黄色
  560. /// </summary>
  561. /// <param name="sender"></param>
  562. /// <param name="e"></param>
  563. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  564. {
  565. drawingAttributes.Color = Colors.Gold;
  566. Color = Colors.Gold;
  567. }
  568. /// <summary>
  569. /// 画笔颜色事件 蓝色
  570. /// </summary>
  571. /// <param name="sender"></param>
  572. /// <param name="e"></param>
  573. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  574. {
  575. drawingAttributes.Color = Colors.DeepSkyBlue;
  576. Color = Colors.DeepSkyBlue;
  577. }
  578. /// <summary>
  579. /// 画笔粗细事件 细
  580. /// </summary>
  581. /// <param name="sender"></param>
  582. /// <param name="e"></param>
  583. private void RbnFine_Click(object sender, RoutedEventArgs e)
  584. {
  585. drawingAttributes.Width = 1;
  586. drawingAttributes.Height = 1;
  587. Size = 1;
  588. }
  589. /// <summary>
  590. /// 画笔粗细事件 中
  591. /// </summary>
  592. /// <param name="sender"></param>
  593. /// <param name="e"></param>
  594. private void RbnIn_Click(object sender, RoutedEventArgs e)
  595. {
  596. drawingAttributes.Width = 3;
  597. drawingAttributes.Height = 3;
  598. Size = 3;
  599. }
  600. /// <summary>
  601. /// 画笔粗细事件 粗
  602. /// </summary>
  603. /// <param name="sender"></param>
  604. /// <param name="e"></param>
  605. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  606. {
  607. drawingAttributes.Width = 5;
  608. drawingAttributes.Height = 5;
  609. Size = 5;
  610. }
  611. /// <summary>
  612. /// 登陆事件
  613. /// </summary>
  614. /// <param name="sender"></param>
  615. /// <param name="e"></param>
  616. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  617. {
  618. Login();
  619. }
  620. /// <summary>
  621. /// 登陆
  622. /// </summary>
  623. private void Login()
  624. {
  625. if (APP.W_LoginWindow == null)
  626. {
  627. APP.W_LoginWindow = new LoginWindow();
  628. APP.W_LoginWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  629. APP.W_LoginWindow.Owner = this;
  630. }
  631. else
  632. {
  633. APP.W_LoginWindow.Initialize();
  634. }
  635. APP.W_LoginWindow.ShowDialog();
  636. if (APP.IsLoginType)
  637. {
  638. txbLoginType.Text = APP.UserInfo.Username;
  639. ImgUpload.Visibility = Visibility.Visible;
  640. ImgUploadTwo.Visibility = Visibility.Collapsed;
  641. }
  642. else
  643. {
  644. txbLoginType.Text = "未登录";
  645. ImgUpload.Visibility = Visibility.Collapsed;
  646. ImgUploadTwo.Visibility = Visibility.Visible;
  647. }
  648. }
  649. /// <summary>
  650. /// 截图事件
  651. /// </summary>
  652. /// <param name="sender"></param>
  653. /// <param name="e"></param>
  654. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  655. {
  656. string time = GetTimeStamp();
  657. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  658. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  659. if (APP.W_JieTuWindow != null)
  660. {
  661. APP.W_JieTuWindow.initialization();
  662. APP.W_JieTuWindow.Screenshot();
  663. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  664. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  665. }
  666. else
  667. {
  668. APP.W_JieTuWindow = new JieTuWindow();
  669. // 订阅事件
  670. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  671. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  672. APP.W_JieTuWindow.Show();
  673. }
  674. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  675. }
  676. /// <summary>
  677. /// 截图关闭窗口
  678. /// </summary>
  679. /// <param name="text"></param>
  680. private void frm_ChangeTextEvent(string text)
  681. {
  682. if ("关闭窗口".Equals(text))
  683. {
  684. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  685. {
  686. if (APP.pageData.currpage == 0)
  687. {
  688. APP.pageData.pagenum += 1;
  689. APP.pageData.currpage = APP.pageData.pagenum;
  690. }
  691. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  692. {
  693. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  694. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  695. }
  696. else
  697. {
  698. Model_DrawData model_DrawData = new Model_DrawData();
  699. model_DrawData.PageImagePath = APP.ImgPath;
  700. model_DrawData.PdfImagePath = APP.ImgPath;
  701. APP.PageDrawList.Add(model_DrawData);
  702. }
  703. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  704. //{
  705. // //imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  706. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage-1].PageImagePath));
  707. //}
  708. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  709. {
  710. //imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  711. imgDocumentation.Source = null;
  712. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  713. //btnOk.Visibility = Visibility.Visible;
  714. //blackboard_canvas.Visibility = Visibility.Collapsed;
  715. APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
  716. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  717. ImgPrintTwo.Visibility = Visibility.Collapsed;
  718. btnPrint.IsEnabled = true;
  719. }
  720. }
  721. }
  722. }
  723. /// <summary>
  724. /// 截图关闭 非正常关闭截图时,截图清空
  725. /// </summary>
  726. private void JietuWindow_click_closeJietuWindowClick()
  727. {
  728. APP.W_JieTuWindow = null;
  729. }
  730. /// <summary>
  731. /// 获取时间戳
  732. /// </summary>
  733. /// <returns></returns>
  734. public string GetTimeStamp()
  735. {
  736. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  737. return Convert.ToInt64(ts.TotalSeconds).ToString();
  738. }
  739. /// <summary>
  740. /// 导入事件
  741. /// </summary>
  742. /// <param name="sender"></param>
  743. /// <param name="e"></param>
  744. private void BtnImport_Click(object sender, RoutedEventArgs e)
  745. {
  746. try
  747. {
  748. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  749. ofd = new System.Windows.Forms.OpenFileDialog
  750. {
  751. Filter = "文档|*.docx;*.doc;*ppt",
  752. InitialDirectory = desktopPath,
  753. Multiselect = false,
  754. AddExtension = true,
  755. DereferenceLinks = true
  756. };
  757. new Thread(
  758. o =>
  759. {
  760. Thread.Sleep(400);
  761. Dispatcher.Invoke(new Action(() =>
  762. {
  763. OpenDialog();
  764. }
  765. ));
  766. })
  767. {
  768. IsBackground = true
  769. }.Start();
  770. }
  771. catch (Exception ex)
  772. {
  773. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  774. }
  775. }
  776. /// <summary>
  777. /// 导入文档
  778. /// </summary>
  779. private void OpenDialog()
  780. {
  781. result = ofd.ShowDialog();
  782. if (result == System.Windows.Forms.DialogResult.OK)
  783. {
  784. if (ofd.FileName != "")
  785. {
  786. #region PPT转PDF
  787. string filepath = ofd.FileName;
  788. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  789. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  790. if (type.Contains("typezsygppt"))//ppt
  791. {
  792. try
  793. {
  794. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  795. path = pathTemp + path + ".pdf";
  796. //PPT转PDF
  797. Presentation ppt = new Presentation(filepath);
  798. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  799. #endregion
  800. #region PDF转图片
  801. // 图片绝对路径集合
  802. List<string> images = new List<string>();
  803. string directoryPath = pathTemp;
  804. //aspose许可证
  805. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  806. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  807. //l.SetLicense(licenseName);
  808. //定义Jpeg转换设备
  809. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  810. var device = new Aspose.Pdf.Devices.JpegDevice();
  811. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  812. //directoryPath += quality;
  813. Directory.CreateDirectory(directoryPath);
  814. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  815. device = new Aspose.Pdf.Devices.JpegDevice(100);
  816. //遍历每一页转为jpg
  817. for (var i = 1; i <= document.Pages.Count; i++)
  818. {
  819. long ii = Timestamp();
  820. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  821. images.Add(filePathOutPut);
  822. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  823. try
  824. {
  825. device.Process(document.Pages[i], fs);
  826. fs.Close();
  827. }
  828. catch (Exception ex)
  829. {
  830. fs.Close();
  831. File.Delete(filePathOutPut);
  832. }
  833. }
  834. #endregion
  835. string[] page = images.ToArray();
  836. int num = 0;
  837. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  838. {
  839. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  840. {
  841. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  842. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  843. APP.PageDrawList[i].PageNum = i + 1;
  844. APP.PageDrawList[i].ImgDocumentation = true;
  845. }
  846. else
  847. {
  848. Model_DrawData model_DrawData = new Model_DrawData();
  849. model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
  850. model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
  851. model_DrawData.PageNum = i + 1;
  852. model_DrawData.ImgDocumentation = true;
  853. APP.PageDrawList.Add(model_DrawData);
  854. }
  855. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  856. ImgPrintTwo.Visibility = Visibility.Collapsed;
  857. btnPrint.IsEnabled = true;
  858. APP.SaveDraw();
  859. num++;
  860. }
  861. if (num > 0)
  862. {
  863. APP.pageData.currpage = APP.pageData.pagenum + 1;
  864. APP.pageData.pagenum += num;
  865. }
  866. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  867. {
  868. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  869. imgCanvas.Source = null;
  870. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  871. ImgScreenshotTwo.Visibility = Visibility.Visible;
  872. btnScreenshot.IsEnabled = false;
  873. }
  874. else
  875. {
  876. imgDocumentation.Source = null;
  877. imgCanvas.Source = null;
  878. ///截图可用
  879. ImgScreenshot.Visibility = Visibility.Visible;
  880. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  881. btnScreenshot.IsEnabled = true;
  882. }
  883. }
  884. catch (Exception ex)
  885. {
  886. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  887. }
  888. }
  889. else//word
  890. {
  891. try
  892. {
  893. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  894. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  895. int num = 0;
  896. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  897. {
  898. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  899. {
  900. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  901. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  902. APP.PageDrawList[i].PageNum = i + 1;
  903. APP.PageDrawList[i].ImgDocumentation = true;
  904. }
  905. else
  906. {
  907. Model_DrawData model_DrawData = new Model_DrawData();
  908. model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
  909. model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
  910. model_DrawData.PageNum = i + 1;
  911. model_DrawData.ImgDocumentation = true;
  912. APP.PageDrawList.Add(model_DrawData);
  913. }
  914. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  915. ImgPrintTwo.Visibility = Visibility.Collapsed;
  916. btnPrint.IsEnabled = true;
  917. APP.SaveDraw();
  918. num++;
  919. }
  920. if (num > 0)
  921. {
  922. APP.pageData.currpage = APP.pageData.pagenum + 1;
  923. APP.pageData.pagenum += num;
  924. }
  925. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  926. {
  927. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  928. imgCanvas.Source = null;
  929. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  930. ImgScreenshotTwo.Visibility = Visibility.Visible;
  931. btnScreenshot.IsEnabled = false;
  932. }
  933. else
  934. {
  935. imgDocumentation.Source = null;
  936. imgCanvas.Source = null;
  937. ///截图可用
  938. ImgScreenshot.Visibility = Visibility.Visible;
  939. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  940. btnScreenshot.IsEnabled = true;
  941. }
  942. }
  943. catch (Exception ex)
  944. {
  945. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  946. }
  947. }
  948. }
  949. }
  950. }
  951. /// <summary>
  952. /// 返回一个时间戳到毫秒
  953. /// </summary>
  954. /// <returns></returns>
  955. public static long Timestamp()
  956. {
  957. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  958. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  959. return timestr;
  960. }
  961. #region 录制窗口
  962. #region 变量
  963. /// <summary>
  964. /// 视频保存路径
  965. /// </summary>
  966. //string RecordingPath;
  967. /// <summary>
  968. /// 图片保存路径
  969. /// </summary>
  970. string ImgPath;
  971. /// <summary>
  972. /// 音频保存路径名
  973. /// </summary>
  974. string AudioPathName;
  975. /// <summary>
  976. /// 视频保存路径名
  977. /// </summary>
  978. string VideoSavePathName;
  979. /// <summary>
  980. /// 暂停录制
  981. /// </summary>
  982. bool IsSuspendR = true;
  983. /// <summary>
  984. /// 录制是否已停止
  985. /// </summary>
  986. bool IsFirstR = true;
  987. /// <summary>
  988. /// 图片
  989. /// </summary>
  990. List<string> RsImgName = null;
  991. /// <summary>
  992. /// 是否开始截图计数
  993. /// </summary>
  994. bool IsStartCount = false;
  995. #endregion
  996. /// <summary>
  997. /// 录制窗口内容
  998. /// </summary>
  999. /// <param name="sender"></param>
  1000. /// <param name="e"></param>
  1001. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  1002. {
  1003. if (APP.pageData.currpage > 0)
  1004. {
  1005. blackboard_canvas.Visibility = Visibility.Visible;
  1006. }
  1007. else
  1008. {
  1009. System.Windows.MessageBox.Show("请先导入文档或截图!");
  1010. return;
  1011. }
  1012. StartRecord();
  1013. }
  1014. /// <summary>
  1015. /// 停止录制窗口内容
  1016. /// </summary>
  1017. /// <param name="sender"></param>
  1018. /// <param name="e"></param>
  1019. private void BtnStop_Click(object sender, RoutedEventArgs e)
  1020. {
  1021. blackboard_canvas.Visibility = Visibility.Collapsed;
  1022. EndRecord();
  1023. }
  1024. System.Timers.Timer timer;
  1025. /// <summary>
  1026. /// 设置录屏文件地址
  1027. /// </summary>
  1028. void SetUpVideoPathName()
  1029. {
  1030. }
  1031. /// <summary>
  1032. /// 开始录制和暂停录制
  1033. /// </summary>
  1034. void StartRecord()
  1035. {
  1036. if (IsSuspendR)
  1037. {
  1038. if (IsFirstR)//是否第一次录制 初始化录制
  1039. {
  1040. VideoInfo = new Model_Video();
  1041. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  1042. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  1043. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1044. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1045. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1046. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  1047. FileToolsCommon.CreateDirectory(ImgPath);
  1048. FileToolsCommon.CreateDirectory(AudioPathName);
  1049. AudioPathName += APP.WKData.WkName + ".MP3";
  1050. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1051. int num = 1;
  1052. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  1053. {
  1054. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  1055. num++;
  1056. }
  1057. #region 设置录屏唯一 废弃
  1058. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1059. //{
  1060. // MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1061. // if (dr == MessageBoxResult.OK)
  1062. // {
  1063. // try
  1064. // {
  1065. // FileToolsCommon.DeleteFile(VideoSavePathName);
  1066. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1067. // }
  1068. // catch (Exception ex)
  1069. // {
  1070. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1071. // }
  1072. // }
  1073. // else
  1074. // {
  1075. // return;
  1076. // }
  1077. //}
  1078. #endregion
  1079. #region 禁用按钮
  1080. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1081. ImgPrintTwo.Visibility = Visibility.Visible;
  1082. btnPrint.IsEnabled = false;
  1083. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1084. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1085. btnScreenshot.IsEnabled = false;
  1086. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1087. ImgImportTwo.Visibility = Visibility.Visible;
  1088. btnImport.IsEnabled = false;
  1089. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1090. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1091. btnScreenRecording.IsEnabled = false;
  1092. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1093. ImgUploadTwo.Visibility = Visibility.Visible;
  1094. btnUpload.IsEnabled = false;
  1095. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1096. ImgSetUpTwo.Visibility = Visibility.Visible;
  1097. btnSetUp.IsEnabled = false;
  1098. btnLoginType.IsEnabled = false;
  1099. #endregion
  1100. IsFirstR = false;
  1101. RsImgName = new List<string>();
  1102. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  1103. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  1104. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1105. timer.Enabled = true; //启动计时器
  1106. }
  1107. #region 录像倒计时
  1108. if (APP.W_CountdownWindow == null)
  1109. {
  1110. APP.W_CountdownWindow = new CountdownWindow();
  1111. //APP.W_CountdownWindow.Topmost = true;
  1112. }
  1113. else
  1114. {
  1115. APP.W_CountdownWindow.Initialize();
  1116. //APP.W_CountdownWindow.Topmost = true;
  1117. }
  1118. APP.W_CountdownWindow.Show();
  1119. #endregion
  1120. //继续录制
  1121. IsSuspendR = false;
  1122. //BtnRecording.Content = "暂停录制";
  1123. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1124. ImgStop.Visibility = Visibility.Collapsed;
  1125. ImgStopTwo.Visibility = Visibility.Visible;
  1126. TxbRecordingWord.Text = "暂停";
  1127. #region 2秒内不可点击
  1128. new Thread(new ThreadStart(new Action(() =>
  1129. {
  1130. Dispatcher.Invoke(() =>
  1131. {
  1132. BtnRecord.IsEnabled = false;
  1133. btnStop.IsEnabled = false;
  1134. });
  1135. Thread.Sleep(2000);
  1136. Dispatcher.Invoke(() =>
  1137. {
  1138. BtnRecord.IsEnabled = true;
  1139. btnStop.IsEnabled = true;
  1140. });
  1141. }))).Start();
  1142. #endregion
  1143. try
  1144. {
  1145. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1146. new Thread(new ThreadStart(new Action(() =>
  1147. {
  1148. Thread.Sleep(1000);
  1149. Dispatcher.Invoke(() =>
  1150. {
  1151. IsStartCount = true;
  1152. //timer.Start();
  1153. });
  1154. }))).Start();
  1155. }
  1156. catch (Exception ex)
  1157. {
  1158. System.Windows.MessageBox.Show(ex.Message);
  1159. }
  1160. }
  1161. else
  1162. {
  1163. //暂停
  1164. IsSuspendR = true;
  1165. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1166. ImgStop.Visibility = Visibility.Visible;
  1167. ImgStopTwo.Visibility = Visibility.Collapsed;
  1168. TxbRecordingWord.Text = "继续";
  1169. #region 2秒内不可点击
  1170. new Thread(new ThreadStart(new Action(() =>
  1171. {
  1172. Dispatcher.Invoke(() =>
  1173. {
  1174. BtnRecord.IsEnabled = false;
  1175. btnStop.IsEnabled = false;
  1176. });
  1177. Thread.Sleep(2000);
  1178. Dispatcher.Invoke(() =>
  1179. {
  1180. BtnRecord.IsEnabled = true;
  1181. btnStop.IsEnabled = true;
  1182. });
  1183. }))).Start();
  1184. #endregion
  1185. try
  1186. {
  1187. APP.FFmpeg.SuspendFFmpeg();
  1188. new Thread(new ThreadStart(new Action(() =>
  1189. {
  1190. while (APP.FFmpeg.myProcess != null)
  1191. {
  1192. Thread.Sleep(100);
  1193. }
  1194. IsStartCount = false;
  1195. }))).Start();
  1196. }
  1197. catch (Exception ex)
  1198. {
  1199. System.Windows.MessageBox.Show(ex.Message);
  1200. }
  1201. }
  1202. }
  1203. /// <summary>
  1204. /// 录制保存图片
  1205. /// </summary>
  1206. /// <param name="sender"></param>
  1207. /// <param name="e"></param>
  1208. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  1209. {
  1210. if (IsStartCount)
  1211. {
  1212. try
  1213. {
  1214. Dispatcher.Invoke(() =>
  1215. {
  1216. string FilePathName = ImgPath + RsImgName.Count + ".png";
  1217. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  1218. RsImgName.Add(FilePathName);
  1219. });
  1220. }
  1221. catch (Exception ex)
  1222. {
  1223. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1224. }
  1225. }
  1226. }
  1227. /// <summary>
  1228. /// 停止录制并生成录制文件
  1229. /// </summary>
  1230. void EndRecord()
  1231. {
  1232. if (!IsFirstR)
  1233. {
  1234. #region 恢复被禁用的按钮
  1235. ImgPrint.Visibility = Visibility.Visible;
  1236. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1237. btnPrint.IsEnabled = true;
  1238. ImgScreenshot.Visibility = Visibility.Visible;
  1239. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1240. btnScreenshot.IsEnabled = true;
  1241. ImgImport.Visibility = Visibility.Visible;
  1242. ImgImportTwo.Visibility = Visibility.Collapsed;
  1243. btnImport.IsEnabled = true;
  1244. ImgScreenRecording.Visibility = Visibility.Visible;
  1245. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  1246. btnScreenRecording.IsEnabled = true;
  1247. ImgUpload.Visibility = Visibility.Visible;
  1248. ImgUploadTwo.Visibility = Visibility.Collapsed;
  1249. btnUpload.IsEnabled = true;
  1250. ImgSetUp.Visibility = Visibility.Visible;
  1251. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  1252. btnSetUp.IsEnabled = true;
  1253. btnLoginType.IsEnabled = true;
  1254. #endregion
  1255. IsSuspendR = true;
  1256. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1257. ImgStop.Visibility = Visibility.Visible;
  1258. ImgStopTwo.Visibility = Visibility.Collapsed;
  1259. TxbRecordingWord.Text = "保存中";
  1260. #region 2秒内不可点击
  1261. new Thread(new ThreadStart(new Action(() =>
  1262. {
  1263. Dispatcher.Invoke(() =>
  1264. {
  1265. BtnRecord.IsEnabled = false;
  1266. btnStop.IsEnabled = false;
  1267. });
  1268. }))).Start();
  1269. #endregion
  1270. try
  1271. {
  1272. //缩略图
  1273. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  1274. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1275. //缩略图存储位置
  1276. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  1277. int gridActWidth = (int)GridMain.ActualWidth;
  1278. int gridActHeight = (int)GridMain.ActualHeight;
  1279. APP.FFmpeg.StopFFmpeg(AudioPathName);
  1280. new Thread(new ThreadStart(new Action(() =>
  1281. {
  1282. //停止截图
  1283. while (APP.FFmpeg.myProcess != null)
  1284. {
  1285. Thread.Sleep(100);
  1286. }
  1287. Dispatcher.Invoke(() =>
  1288. {
  1289. IsStartCount = false;
  1290. timer.Stop();
  1291. });
  1292. //}))).Start();
  1293. //new Thread(new ThreadStart(new Action(() =>
  1294. //{
  1295. //判断音频是否存在 判断音频临时文件夹是否存在
  1296. if (!FileToolsCommon.IsExistFile(AudioPathName))
  1297. {
  1298. Thread.Sleep(100);
  1299. }
  1300. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  1301. {
  1302. Thread.Sleep(100);
  1303. }
  1304. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, gridActWidth, gridActHeight);
  1305. //}))).Start();
  1306. //new Thread(new ThreadStart(new Action(() =>
  1307. //{
  1308. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  1309. {
  1310. Thread.Sleep(100);
  1311. }
  1312. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSavePathName) + "temp/"))
  1313. {
  1314. Thread.Sleep(100);
  1315. }
  1316. Dispatcher.Invoke(() =>
  1317. {
  1318. BtnRecord.IsEnabled = true;
  1319. btnStop.IsEnabled = true;
  1320. TxbRecordingWord.Text = "录制";
  1321. });
  1322. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1323. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1324. Thread.Sleep(500);
  1325. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  1326. VideoInfo.VideoPath = VideoSavePathName;
  1327. VideoInfo.ThumbnailPath = ThumbnailPathName;
  1328. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  1329. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  1330. VideoInfo.IsUpload = false;
  1331. VideoInfo.Uploaded = 0;
  1332. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  1333. APP.VideoList.Add(VideoInfo);
  1334. //保存数据
  1335. APP.SaveWkData();
  1336. IsFirstR = true;
  1337. }))).Start();
  1338. //List<Model_Video> VideoList
  1339. }
  1340. catch (Exception ex)
  1341. {
  1342. System.Windows.MessageBox.Show(ex.Message);
  1343. }
  1344. }
  1345. }
  1346. #endregion
  1347. /// <summary>
  1348. /// 增加事件
  1349. /// </summary>
  1350. /// <param name="sender"></param>
  1351. /// <param name="e"></param>
  1352. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  1353. {
  1354. if (APP.pageData.currpage > 0)
  1355. {
  1356. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1357. }
  1358. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  1359. {
  1360. blackboard_canvas.Visibility = Visibility.Visible;
  1361. }
  1362. APP.pageData.pagenum += 1;
  1363. APP.pageData.currpage = APP.pageData.pagenum;
  1364. myblackboard.changepage(APP.pageData.currpage - 1);
  1365. ///清空页面图片UI
  1366. imgCanvas.Source = null;
  1367. imgDocumentation.Source = null;
  1368. ///画板模型增加一页
  1369. Model_DrawData model_DrawData = new Model_DrawData();
  1370. model_DrawData.PageNum = APP.pageData.currpage;
  1371. APP.PageDrawList.Add(model_DrawData);
  1372. APP.SaveDraw();
  1373. if (btnImport.IsEnabled == true)
  1374. {
  1375. ///截图可用
  1376. ImgScreenshot.Visibility = Visibility.Visible;
  1377. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1378. btnScreenshot.IsEnabled = true;
  1379. }
  1380. }
  1381. /// <summary>
  1382. /// 打印事件
  1383. /// </summary>
  1384. /// <param name="sender"></param>
  1385. /// <param name="e"></param>
  1386. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  1387. {
  1388. try
  1389. {
  1390. //3种情况 1.文档图片 2.截图图片 3.没有图片
  1391. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  1392. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  1393. ////设置纸张横向
  1394. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  1395. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  1396. FileToolsCommon.CreateFile(imgPath);
  1397. imgPath += "\\101.pdf";
  1398. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  1399. document.Open();
  1400. iTextSharp.text.Image image;
  1401. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1402. {
  1403. long ii = Timestamp();
  1404. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1405. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  1406. RectangleF rectangleFs = new RectangleF();
  1407. MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  1408. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  1409. if (String.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  1410. {
  1411. }
  1412. else if (APP.PageDrawList[i].ImgDocumentation == true)
  1413. {
  1414. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  1415. }
  1416. else
  1417. {
  1418. RectangleF rectangleF = new RectangleF();
  1419. rectangleF.Width = (float)APP.PageDrawList[i].ImageSizes.CenterX;
  1420. rectangleF.Height = (float)APP.PageDrawList[i].ImageSizes.CenterY;
  1421. rectangleF.X = (float)APP.PageDrawList[i].ImageLocation.X;
  1422. rectangleF.Y = (float)APP.PageDrawList[i].ImageLocation.Y;
  1423. string msg = string.Empty;
  1424. bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
  1425. if (isImg)
  1426. {
  1427. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  1428. }
  1429. else
  1430. {
  1431. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  1432. }
  1433. }
  1434. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  1435. {
  1436. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1437. }
  1438. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  1439. {
  1440. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1441. }
  1442. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  1443. document.NewPage();
  1444. document.Add(image);
  1445. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  1446. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  1447. //p1.Leading = 150; //行间距
  1448. //document.Add(p1);
  1449. }
  1450. Console.WriteLine("转换成功!");
  1451. document.Close();
  1452. }
  1453. catch (Exception ex)
  1454. {
  1455. Console.WriteLine("转换失败,原因:" + ex.Message);
  1456. }
  1457. //document.Close();
  1458. ////Console.ReadKey();
  1459. if (APP.W_PrintWindow == null)
  1460. {
  1461. APP.W_PrintWindow = new PrintWindow();
  1462. //APP.W_PrintWindow.Topmost = true;
  1463. APP.W_PrintWindow.Owner = this;
  1464. }
  1465. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  1466. {
  1467. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath);
  1468. }
  1469. else
  1470. {
  1471. APP.W_PrintWindow.Initialize("");
  1472. }
  1473. APP.W_PrintWindow.ShowDialog();
  1474. //int pr = 1;
  1475. //string msg = string.Empty;
  1476. //string outPut = string.Empty;
  1477. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1478. //if(pr==0)
  1479. //{
  1480. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1481. // APP.OutPut = outPut.Split(',');
  1482. // string defa = string.Empty;
  1483. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1484. // int printResult = 1;
  1485. // string standardError = string.Empty;
  1486. // string standardOutput = string.Empty;
  1487. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1488. //}
  1489. }
  1490. /// 上一页
  1491. /// </summary>
  1492. /// <param name="sender"></param>
  1493. /// <param name="e"></param>
  1494. private void last_button_Click(object sender, RoutedEventArgs e)
  1495. {
  1496. if (APP.pageData.currpage > 1)
  1497. {
  1498. APP.pageData.currpage -= 1;
  1499. myblackboard.changepage(APP.pageData.currpage - 1);
  1500. if (btnImport.IsEnabled == true)
  1501. {
  1502. ///截图可用
  1503. ImgScreenshot.Visibility = Visibility.Visible;
  1504. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1505. btnScreenshot.IsEnabled = true;
  1506. }
  1507. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1508. {
  1509. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1510. {
  1511. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1512. }
  1513. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1514. {
  1515. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1516. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1517. {
  1518. imgCanvas.Source = null;
  1519. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1520. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1521. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1522. btnScreenshot.IsEnabled = false;
  1523. }
  1524. else
  1525. {
  1526. imgDocumentation.Source = null;
  1527. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1528. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1529. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1530. {
  1531. var group = IMG.FindResource("Imageview") as TransformGroup;
  1532. var transform = group.Children[1] as TranslateTransform;
  1533. #region 高低 缩放比例
  1534. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1535. {
  1536. var transform1 = group.Children[0] as ScaleTransform;
  1537. transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1538. transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1539. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  1540. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  1541. }
  1542. #endregion
  1543. #region XY轴
  1544. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1545. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1546. #endregion
  1547. mouseDown = false;
  1548. }
  1549. }
  1550. }
  1551. else
  1552. {
  1553. imgCanvas.Source = null;
  1554. imgDocumentation.Source = null;
  1555. }
  1556. }
  1557. }
  1558. }
  1559. /// <summary>
  1560. /// 下一页
  1561. /// </summary>
  1562. /// <param name="sender"></param>
  1563. /// <param name="e"></param>
  1564. private void next_btn_Click(object sender, RoutedEventArgs e)
  1565. {
  1566. if (APP.pageData.currpage < APP.pageData.pagenum)
  1567. {
  1568. APP.pageData.currpage += 1;
  1569. myblackboard.changepage(APP.pageData.currpage - 1);
  1570. if (btnImport.IsEnabled == true)
  1571. {
  1572. ///截图可用
  1573. ImgScreenshot.Visibility = Visibility.Visible;
  1574. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1575. btnScreenshot.IsEnabled = true;
  1576. }
  1577. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1578. {
  1579. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1580. {
  1581. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1582. }
  1583. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1584. {
  1585. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1586. {
  1587. imgCanvas.Source = null;
  1588. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1589. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1590. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1591. btnScreenshot.IsEnabled = false;
  1592. }
  1593. else
  1594. {
  1595. imgDocumentation.Source = null;
  1596. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1597. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1598. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1599. {
  1600. var group = IMG.FindResource("Imageview") as TransformGroup;
  1601. #region 高低 缩放比例
  1602. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1603. {
  1604. var transform1 = group.Children[0] as ScaleTransform;
  1605. transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1606. transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1607. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  1608. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  1609. }
  1610. #endregion
  1611. #region 坐标XY轴
  1612. var transform = group.Children[1] as TranslateTransform;
  1613. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1614. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1615. #endregion
  1616. mouseDown = false;
  1617. }
  1618. }
  1619. }
  1620. else
  1621. {
  1622. imgCanvas.Source = null;
  1623. imgDocumentation.Source = null;
  1624. }
  1625. }
  1626. }
  1627. }
  1628. /// <summary>
  1629. /// 生成图片
  1630. /// </summary>
  1631. /// <param name="_path">图片地址</param>
  1632. /// <param name="_saveimg">保存位置</param>
  1633. /// <param name="_rectangle">图片位置</param>
  1634. /// <param name="errmsg">错误消息</param>
  1635. /// <returns></returns>
  1636. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  1637. {
  1638. errmsg = null;
  1639. try
  1640. {
  1641. Bitmap bitmap = null;
  1642. //创建要显示的图片对象,根据参数的个数设置宽度
  1643. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  1644. Graphics g = Graphics.FromImage(backgroudImg);
  1645. //清除画布,背景设置为白色
  1646. g.Clear(System.Drawing.Color.White);
  1647. if (!string.IsNullOrWhiteSpace(_path))
  1648. {
  1649. bitmap = ImageHelper.ReadBitmapFile(_path);
  1650. g.DrawImage(bitmap, _rectangle);
  1651. }
  1652. backgroudImg.Save(_saveimg);
  1653. g.Dispose();
  1654. backgroudImg.Dispose();
  1655. if (bitmap != null)
  1656. {
  1657. bitmap.Dispose();
  1658. }
  1659. GC.Collect();
  1660. return true;
  1661. }
  1662. catch (Exception ex)
  1663. {
  1664. errmsg = ex.Message;
  1665. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  1666. return false;
  1667. }
  1668. }
  1669. /// <summary>
  1670. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1671. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1672. /// </summary>
  1673. /// <param name="pdfInputPath">Word文件路径</param>
  1674. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1675. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1676. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1677. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1678. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1679. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1680. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1681. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1682. {
  1683. // 返回的图片绝对路径集合
  1684. List<string> images = new List<string>();
  1685. try
  1686. {
  1687. // open word file
  1688. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1689. // validate parameter
  1690. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1691. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1692. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1693. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1694. if (startPageNum <= 0) { startPageNum = 1; }
  1695. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1696. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1697. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1698. if (resolution <= 0) { resolution = 128; }
  1699. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1700. {
  1701. Resolution = resolution
  1702. };
  1703. // start to convert each page
  1704. for (int i = startPageNum; i <= endPageNum; i++)
  1705. {
  1706. imageSaveOptions.PageIndex = i - 1;
  1707. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1708. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1709. APP.num++;
  1710. }
  1711. imageSaveOptions = null;
  1712. doc = null;
  1713. }
  1714. catch (Exception ex)
  1715. {
  1716. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1717. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1718. }
  1719. return images;
  1720. }
  1721. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1722. {
  1723. SaveFormat sf;// = SaveFormat.Unknown;
  1724. if (imageFormat.Equals(ImageFormat.Png))
  1725. {
  1726. sf = SaveFormat.Png;
  1727. }
  1728. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1729. {
  1730. sf = SaveFormat.Jpeg;
  1731. }
  1732. else if (imageFormat.Equals(ImageFormat.Tiff))
  1733. {
  1734. sf = SaveFormat.Tiff;
  1735. }
  1736. else if (imageFormat.Equals(ImageFormat.Bmp))
  1737. {
  1738. sf = SaveFormat.Bmp;
  1739. }
  1740. else
  1741. {
  1742. sf = SaveFormat.Unknown;
  1743. }
  1744. return sf;
  1745. }
  1746. #region 图像缩放,移动
  1747. private bool mouseDown;
  1748. private System.Windows.Point mouseXY;
  1749. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1750. {
  1751. var img = sender as ContentControl;
  1752. if (img == null)
  1753. {
  1754. return;
  1755. }
  1756. img.CaptureMouse();
  1757. mouseDown = true;
  1758. mouseXY = e.GetPosition(img);
  1759. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1760. }
  1761. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1762. {
  1763. System.Windows.Point point = e.GetPosition(imgCanvas);
  1764. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1765. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1766. //{
  1767. // Console.WriteLine("在范围内");
  1768. //}
  1769. }
  1770. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1771. {
  1772. var img = sender as ContentControl;
  1773. if (img == null)
  1774. {
  1775. return;
  1776. }
  1777. img.ReleaseMouseCapture();
  1778. mouseDown = false;
  1779. }
  1780. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1781. {
  1782. var img = sender as ContentControl;
  1783. if (img == null)
  1784. {
  1785. return;
  1786. }
  1787. if (mouseDown)
  1788. {
  1789. Domousemove(img, e);
  1790. }
  1791. }
  1792. /// <summary>
  1793. /// x y轴
  1794. /// </summary>
  1795. /// <param name="img"></param>
  1796. /// <param name="e"></param>
  1797. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1798. {
  1799. if (e.LeftButton != MouseButtonState.Pressed)
  1800. {
  1801. return;
  1802. }
  1803. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  1804. {
  1805. return;
  1806. }
  1807. var group = IMG.FindResource("Imageview") as TransformGroup;
  1808. var transform = group.Children[1] as TranslateTransform;
  1809. var position = e.GetPosition(img);
  1810. transform.X -= mouseXY.X - position.X;
  1811. transform.Y -= mouseXY.Y - position.Y;
  1812. mouseXY = position;
  1813. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1814. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform.X;
  1815. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform.Y;
  1816. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1817. }
  1818. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1819. {
  1820. var img = sender as ContentControl;
  1821. if (img == null)
  1822. {
  1823. return;
  1824. }
  1825. var point = e.GetPosition(img);
  1826. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1827. var PicLocate = e.GetPosition(imgCanvas);
  1828. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1829. var group = IMG.FindResource("Imageview") as TransformGroup;
  1830. var delta = e.Delta * 0.001;
  1831. DowheelZoom(group, point, delta);
  1832. }
  1833. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1834. {
  1835. var pointToContent = group.Inverse.Transform(point);
  1836. var transform = group.Children[0] as ScaleTransform;
  1837. if (transform.ScaleX + delta < 0.1) return;
  1838. transform.ScaleX += delta;
  1839. transform.ScaleY += delta;
  1840. var transform1 = group.Children[1] as TranslateTransform;
  1841. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1842. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1843. LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  1844. + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  1845. );
  1846. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1847. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  1848. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  1849. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  1850. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1851. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform1.X;
  1852. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform1.Y;
  1853. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform();
  1854. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX = imgCanvas.ActualWidth;
  1855. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY = imgCanvas.ActualHeight;
  1856. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1857. }
  1858. #endregion
  1859. #region 点阵笔相关
  1860. #region 值初始化
  1861. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  1862. /// <summary>
  1863. /// A4点阵纸点阵宽度
  1864. /// </summary>
  1865. private const int A4_WIDTH = 5600;
  1866. /// <summary>
  1867. /// A4点阵纸点阵高度
  1868. /// </summary>
  1869. private const int A4_HEIGHT = 7920;
  1870. /// <summary>
  1871. /// 画板
  1872. /// </summary>
  1873. private Graphics graphics;
  1874. /// <summary>
  1875. /// 笔画坐标数组
  1876. /// </summary>
  1877. private List<System.Drawing.Point> stroke;
  1878. /// <summary>
  1879. /// 笔序列号
  1880. /// </summary>
  1881. private string penSerial;
  1882. /// <summary>
  1883. /// 笔是否在点
  1884. /// </summary>
  1885. private bool isPenDown;
  1886. //当前点阵地址
  1887. private string currentPageSerial = string.Empty;
  1888. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  1889. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  1890. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  1891. #endregion
  1892. public void InitPen()
  1893. {
  1894. stroke = new List<System.Drawing.Point>();
  1895. //获取点阵笔实例,并绑定点阵笔事件
  1896. //将授权文件内容传入,获取点阵笔对象实例
  1897. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  1898. //绑定笔连接事件
  1899. APP.digitalPen.PenConnected += OnPenConnect;
  1900. //绑定笔断开事件
  1901. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  1902. //绑定笔书写输出坐标事件
  1903. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  1904. //绑定抬笔事件
  1905. APP.digitalPen.PenUp += OnPenUp;
  1906. //绑定落笔事件
  1907. APP.digitalPen.PenDown += OnPenDown;
  1908. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  1909. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  1910. //完成初始化点阵笔,开始与点阵笔通信
  1911. ERROR_CODE ER = APP.digitalPen.Start();
  1912. ////绑定笔在新的点阵地址页面书写事件
  1913. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  1914. ////绑定笔信息事件
  1915. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  1916. //启动接收笔数据,完成初始化工作
  1917. ERROR_CODE rc = APP.digitalPen.Start();
  1918. //判断是否成功
  1919. if (ER != ERROR_CODE.ERROR_OK)
  1920. {
  1921. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  1922. }
  1923. }
  1924. /// <summary>
  1925. /// 落笔
  1926. /// </summary>
  1927. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1928. /// <param name="penSerial">点阵笔序列号</param>
  1929. /// <param name="penType">点阵笔型号编号</param>
  1930. private void OnPenDown(ulong time, string penSerial, int penType)
  1931. {
  1932. if (this.CheckAccess())
  1933. {
  1934. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  1935. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1936. }
  1937. else
  1938. {
  1939. //labPenSerial.Text = penSerial;
  1940. //labPenStatus.Text = "PenDown";
  1941. isPenDown = true;
  1942. //Dispatcher.Invoke(new Action(() =>
  1943. //{
  1944. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  1945. // {
  1946. // if (APP.PageDrawList[i].PageCode == penSerial)
  1947. // {
  1948. // if (i < APP.pageData.pagenum)
  1949. // {
  1950. // if (i < APP.pageData.currpage)
  1951. // {
  1952. // int num = APP.pageData.currpage - i;
  1953. // APP.pageData.currpage -= num;
  1954. // myblackboard.changepage(APP.pageData.currpage - 1);
  1955. // if (APP.PageDrawList.Count > 0)
  1956. // {
  1957. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1958. // {
  1959. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1960. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1961. // }
  1962. // else
  1963. // {
  1964. // imgCanvas.Source = null;
  1965. // }
  1966. // }
  1967. // }
  1968. // else
  1969. // {
  1970. // int num = i - APP.pageData.currpage;
  1971. // APP.pageData.currpage += num;
  1972. // myblackboard.changepage(APP.pageData.currpage - 1);
  1973. // if (APP.PageDrawList.Count > 0)
  1974. // {
  1975. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1976. // {
  1977. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1978. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1979. // }
  1980. // else
  1981. // {
  1982. // imgCanvas.Source = null;
  1983. // }
  1984. // }
  1985. // }
  1986. // }
  1987. // return;
  1988. // }
  1989. // }
  1990. // //myblackboard.changepages(0, 0, true);
  1991. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  1992. //}));
  1993. }
  1994. //myblackboard.changepages(0, 0, true);
  1995. }
  1996. /// <summary>
  1997. /// 抬笔
  1998. /// </summary>
  1999. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2000. /// <param name="penSerial">点阵笔序列号</param>
  2001. /// <param name="penType">点阵笔型号编号</param>
  2002. private void OnPenUp(ulong time, string penSerial, int penType)
  2003. {
  2004. if (this.CheckAccess())
  2005. {
  2006. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  2007. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2008. }
  2009. else
  2010. {
  2011. isPenDown = false;
  2012. APP.PenSerial = penSerial;
  2013. //int leftPoints = stroke.Count % 3;
  2014. //if (0 != leftPoints)
  2015. //{
  2016. // int from = stroke.Count - leftPoints - 1;
  2017. // if (from < 0)
  2018. // from = 0;
  2019. // int to = stroke.Count - 1;
  2020. // DrawCoordinates(from, to);
  2021. //}
  2022. stroke.Clear();
  2023. }
  2024. if (APP.pageData.currpage > 0)
  2025. {
  2026. Dispatcher.Invoke(new Action(() =>
  2027. {
  2028. myblackboard.changepages(0, 0, true, Color, Size, APP.pageData.currpage - 1);
  2029. }));
  2030. }
  2031. }
  2032. /// <summary>
  2033. /// 笔断开
  2034. /// </summary>
  2035. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2036. /// <param name="penSerial">点阵笔序列号</param>
  2037. /// <param name="penType">点阵笔型号编号</param>
  2038. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  2039. {
  2040. if (this.CheckAccess())
  2041. {
  2042. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  2043. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2044. }
  2045. else
  2046. {
  2047. APP.PenSerial = penSerial;
  2048. APP.PenStatus = false;
  2049. Dispatcher.Invoke(new Action(() =>
  2050. {
  2051. txbNotConnected.Text = "未连接";
  2052. txbNotConnecteds.Text = "未连接";
  2053. }));
  2054. }
  2055. }
  2056. /// <summary>
  2057. /// 笔连接
  2058. /// </summary>
  2059. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2060. /// <param name="penSerial">点阵笔序列号</param>
  2061. /// <param name="penType">点阵笔型号编号</param>
  2062. private void OnPenConnect(ulong time, string penSerial, int penType)
  2063. {
  2064. if (this.CheckAccess())
  2065. {
  2066. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  2067. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2068. }
  2069. else
  2070. {
  2071. APP.PenSerial = penSerial;
  2072. APP.PenStatus = true;
  2073. this.penSerial = penSerial;
  2074. //连接后,在获取笔数据前,可以清除笔内的历史数据
  2075. //APP.digitalPen.ClearMemory(penSerial);
  2076. //开始接收笔数据
  2077. APP.digitalPen.GetPenData(penSerial);
  2078. Dispatcher.Invoke(new Action(() =>
  2079. {
  2080. txbNotConnected.Text = "已连接";
  2081. txbNotConnecteds.Text = "已连接";
  2082. }));
  2083. }
  2084. }
  2085. /// <summary>
  2086. /// 电池电量
  2087. /// </summary>
  2088. /// <param name="time"></param>
  2089. /// <param name="penSerial"></param>
  2090. /// <param name="penType"></param>
  2091. /// <param name="capacity"></param>
  2092. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  2093. {
  2094. if (this.CheckAccess())
  2095. {
  2096. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  2097. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  2098. }
  2099. else
  2100. {
  2101. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  2102. }
  2103. }
  2104. /// <summary>
  2105. /// 已用存储
  2106. /// </summary>
  2107. /// <param name="time"></param>
  2108. /// <param name="penSerial"></param>
  2109. /// <param name="penType"></param>
  2110. /// <param name="fillLevel"></param>
  2111. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  2112. {
  2113. if (this.CheckAccess())
  2114. {
  2115. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  2116. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  2117. }
  2118. else
  2119. {
  2120. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  2121. }
  2122. }
  2123. /// <summary>
  2124. /// 笔书写,收到坐标
  2125. /// </summary>
  2126. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2127. /// <param name="penSerial">点阵笔序列号</param>
  2128. /// <param name="penType">点阵笔型号编号</param>
  2129. /// <param name="pageSerial">点阵地址</param>
  2130. /// <param name="cx">x坐标</param>
  2131. /// <param name="cy">y坐标</param>
  2132. /// <param name="force">压力值</param>
  2133. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  2134. {
  2135. if (this.CheckAccess())
  2136. {
  2137. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  2138. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  2139. }
  2140. else
  2141. {
  2142. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  2143. if (!isPenDown)
  2144. {
  2145. return;
  2146. }
  2147. stroke.Add(new System.Drawing.Point(cx, cy));
  2148. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  2149. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  2150. //点
  2151. double testX = (double)cx * PropW;
  2152. double testY = (double)cy * PropH;
  2153. //pageSerial //点阵IP地址 与打印的页面关联
  2154. if (APP.pageData.currpage > 0)
  2155. {
  2156. Dispatcher.Invoke(new Action(() =>
  2157. {
  2158. //myblackboard.changepages(testX, testY,false);
  2159. myblackboard.changepages(testX, testY, false, Color, Size, APP.pageData.currpage - 1);
  2160. }));
  2161. }
  2162. ////每3个点画一条曲线
  2163. //if (stroke.Count % 3 == 0)
  2164. //{
  2165. // int from = stroke.Count - 3 - 1;
  2166. // if (from < 0)
  2167. // from = 0;
  2168. // int to = stroke.Count - 1;
  2169. // DrawCoordinates(from, to);
  2170. //}
  2171. }
  2172. }
  2173. /// <summary>
  2174. /// 停止笔
  2175. /// </summary>
  2176. public void StopDigitalPen()
  2177. {
  2178. //停止,释放资源
  2179. APP.digitalPen.Stop();
  2180. }
  2181. /// <summary>
  2182. /// 清空笔内存储
  2183. /// </summary>
  2184. public void ClearPenStorage()
  2185. {
  2186. if (!string.IsNullOrEmpty(penSerial))
  2187. APP.digitalPen.ClearMemory(penSerial);
  2188. }
  2189. /// <summary>
  2190. /// 获取剩余电量
  2191. /// </summary>
  2192. public void GetPenElectricityQuantity()
  2193. {
  2194. if (!string.IsNullOrEmpty(penSerial))
  2195. APP.digitalPen.GetBatteryCapacity(penSerial);
  2196. }
  2197. /// <summary>
  2198. /// 获取存储空间
  2199. /// </summary>
  2200. public void GetUsedStorage()
  2201. {
  2202. if (!string.IsNullOrEmpty(penSerial))
  2203. APP.digitalPen.GetMemoryFillLevel(penSerial);
  2204. }
  2205. /// <summary>
  2206. /// 开启悬浮
  2207. /// </summary>
  2208. public void 开启悬浮()
  2209. {
  2210. if (!string.IsNullOrEmpty(penSerial))
  2211. APP.digitalPen.SetPenHoverMode(true, penSerial);
  2212. }
  2213. /// <summary>
  2214. /// 关闭悬浮
  2215. /// </summary>
  2216. public void 关闭悬浮()
  2217. {
  2218. if (!string.IsNullOrEmpty(penSerial))
  2219. APP.digitalPen.SetPenHoverMode(false, penSerial);
  2220. }
  2221. #endregion
  2222. /// <summary>
  2223. /// 最小化
  2224. /// </summary>
  2225. /// <param name="sender"></param>
  2226. /// <param name="e"></param>
  2227. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  2228. {
  2229. if (this.WindowState == WindowState.Minimized)
  2230. {
  2231. this.WindowState = WindowState.Normal;
  2232. }
  2233. else
  2234. {
  2235. this.WindowState = WindowState.Minimized;
  2236. }
  2237. }
  2238. /// <summary>
  2239. /// 位置确定
  2240. /// </summary>
  2241. /// <param name="sender"></param>
  2242. /// <param name="e"></param>
  2243. private void BtnOk_Click(object sender, RoutedEventArgs e)
  2244. {
  2245. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2246. //btnOk.Visibility = Visibility.Collapsed;
  2247. //blackboard_canvas.Visibility = Visibility.Visible;
  2248. }
  2249. }
  2250. }