星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

XHMicroLessonSystemWindow.xaml.cs 103KB

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