星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 94KB

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