星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

XHMicroLessonSystemWindow.xaml.cs 95KB

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. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  154. FileToolsCommon.CreateDirectory(imgPath);
  155. }
  156. }
  157. int I = 9999;
  158. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  159. {
  160. if (IsRbnOpen)
  161. {
  162. try
  163. {
  164. Dispatcher.Invoke(() =>
  165. {
  166. if (I > 10010)
  167. {
  168. long time = Timestamp();
  169. string imgPath= FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  170. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  171. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  172. if (!string.IsNullOrWhiteSpace(path))
  173. {
  174. RbnOpen.Add(path);
  175. imgPlayerRight.Visibility = Visibility.Visible;
  176. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  177. if ("1".Equals(APP.CameraPosition))
  178. {
  179. imgPlayerRight.Visibility = Visibility.Visible;
  180. imgPlayerLeft.Visibility = Visibility.Collapsed;
  181. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  182. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  183. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  184. }
  185. else if ("2".Equals(APP.CameraPosition))
  186. {
  187. imgPlayerRight.Visibility = Visibility.Collapsed;
  188. imgPlayerLeft.Visibility = Visibility.Visible;
  189. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  190. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  191. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  192. }
  193. else if ("3".Equals(APP.CameraPosition))
  194. {
  195. imgPlayerRight.Visibility = Visibility.Collapsed;
  196. imgPlayerLeft.Visibility = Visibility.Collapsed;
  197. imgPlayerRightUnder.Visibility = Visibility.Visible;
  198. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  199. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  200. }
  201. else if ("4".Equals(APP.CameraPosition))
  202. {
  203. imgPlayerRight.Visibility = Visibility.Collapsed;
  204. imgPlayerLeft.Visibility = Visibility.Collapsed;
  205. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  206. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  207. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  208. }
  209. else
  210. {
  211. imgPlayerLeft.Visibility = Visibility.Collapsed;
  212. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  213. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  214. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  215. }
  216. }
  217. }
  218. I++;
  219. });
  220. }
  221. catch (Exception ex)
  222. {
  223. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  224. }
  225. }
  226. }
  227. /// <summary>
  228. /// 摄像头关闭事件
  229. /// </summary>
  230. /// <param name="sender"></param>
  231. /// <param name="e"></param>
  232. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  233. {
  234. IsRbnOpen = false;
  235. imgPlayerRight.Visibility = Visibility.Collapsed;
  236. imgPlayerLeft.Visibility = Visibility.Collapsed;
  237. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  238. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  239. CameraHelper.CloseDevice();
  240. I = 9999;
  241. }
  242. #endregion
  243. #endregion
  244. /// <summary>
  245. /// 录屏事件
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  250. {
  251. if (APP.IsLoginType == false)
  252. {
  253. Login();
  254. return;
  255. }
  256. if (APP.W_ScreenRecordingToolbarWindow == null)
  257. {
  258. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  259. {
  260. Topmost = true
  261. };
  262. APP.W_ScreenRecordingToolbarWindow.Initialize();
  263. }
  264. else
  265. {
  266. APP.W_ScreenRecordingToolbarWindow.Initialize();
  267. }
  268. //显示在右下角
  269. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  270. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  271. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  272. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  273. APP.W_ScreenRecordingToolbarWindow.Show();
  274. Hide();
  275. }
  276. /// <summary>
  277. /// 上传事件
  278. /// </summary>
  279. /// <param name="sender"></param>
  280. /// <param name="e"></param>
  281. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  282. {
  283. if (APP.IsLoginType == false)
  284. {
  285. Login();
  286. return;
  287. }
  288. if(APP.fileDirectoryWindow==null)
  289. {
  290. APP.fileDirectoryWindow = new FileDirectoryWindow();
  291. APP.fileDirectoryWindow.Topmost = true;
  292. APP.fileDirectoryWindow.Owner = this;
  293. }
  294. else
  295. {
  296. Initialize();
  297. }
  298. APP.fileDirectoryWindow.Show();
  299. }
  300. /// <summary>
  301. /// 关闭事件
  302. /// </summary>
  303. /// <param name="sender"></param>
  304. /// <param name="e"></param>
  305. private void BtnDown_Click(object sender, RoutedEventArgs e)
  306. {
  307. if (IsFirstR)
  308. {
  309. APP.Killffmpeg();
  310. APP.SaveWkData();
  311. APP.SaveDraw();
  312. Thread.Sleep(100);
  313. System.Environment.Exit(0);
  314. }
  315. else
  316. {
  317. MessageBoxResult dr = System.Windows.MessageBox.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  318. if (dr == MessageBoxResult.OK)
  319. {
  320. APP.SaveWkData();
  321. APP.SaveDraw();
  322. BtnStop_Click(null, null);
  323. while (!IsFirstR)
  324. {
  325. Thread.Sleep(100);
  326. }
  327. System.Environment.Exit(0);
  328. }
  329. else
  330. {
  331. return;
  332. }
  333. }
  334. }
  335. /// <summary>
  336. /// 设置 保存事件
  337. /// </summary>
  338. /// <param name="sender"></param>
  339. /// <param name="e"></param>
  340. private void BtnSave_Click(object sender, RoutedEventArgs e)
  341. {
  342. //#region 合法性判断
  343. //if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  344. //{
  345. // System.Windows.MessageBox.Show("路径不可为空!");
  346. // return;
  347. //}
  348. //string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  349. //if (!APP.WKData.WkPath.Equals(temp))
  350. //{
  351. // APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  352. // if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  353. // {
  354. // //微课已存在
  355. // MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  356. // if (dr == MessageBoxResult.OK)
  357. // {
  358. // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  359. // }
  360. // else
  361. // {
  362. // return;
  363. // }
  364. // }
  365. // //创建文件夹
  366. // FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  367. //}
  368. //#endregion
  369. if (rbnMP4.IsChecked == true)
  370. {
  371. //存储文件
  372. FileToolsCommon.SetConfigValue("VideoType", "1");
  373. }
  374. else if (rbnFLV.IsChecked == true)
  375. {
  376. FileToolsCommon.SetConfigValue("VideoType", "2");
  377. }
  378. else
  379. {
  380. FileToolsCommon.SetConfigValue("VideoType", "3");
  381. }
  382. if (rbnY.IsChecked == true)
  383. {
  384. FileToolsCommon.SetConfigValue("IsSound", "true");
  385. }
  386. else
  387. {
  388. FileToolsCommon.SetConfigValue("IsSound", "false");
  389. }
  390. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  391. if (rbnRight.IsChecked == true)
  392. {
  393. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  394. }
  395. else if (rbnLeft.IsChecked == true)
  396. {
  397. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  398. }
  399. else if (rbnRightUnder.IsChecked == true)
  400. {
  401. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  402. }
  403. else if (rbnLeftUnder.IsChecked == true)
  404. {
  405. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  406. }
  407. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  408. GridMain.Visibility = Visibility.Visible;
  409. gridSetUp.Visibility = Visibility.Collapsed;
  410. imgPlayerRight.Visibility = Visibility.Collapsed;
  411. imgPlayerLeft.Visibility = Visibility.Collapsed;
  412. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  413. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  414. }
  415. /// <summary>
  416. /// 设置事件
  417. /// </summary>
  418. /// <param name="sender"></param>
  419. /// <param name="e"></param>
  420. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  421. {
  422. if (APP.IsLoginType == false)
  423. {
  424. Login();
  425. return;
  426. }
  427. if (!TxbRecordingWord.Text.Equals("暂停"))
  428. {
  429. GridMain.Visibility = Visibility.Collapsed;
  430. gridSetUp.Visibility = Visibility.Visible;
  431. txbStoragePath.Content = APP.WKData.WkPath;
  432. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  433. if ("1".Equals(APP.CameraPosition))
  434. {
  435. rbnRight.IsChecked = true;
  436. }
  437. else if ("2".Equals(APP.CameraPosition))
  438. {
  439. rbnLeft.IsChecked = true;
  440. }
  441. else if ("3".Equals(APP.CameraPosition))
  442. {
  443. rbnRightUnder.IsChecked = true;
  444. }
  445. else if ("4".Equals(APP.CameraPosition))
  446. {
  447. rbnLeftUnder.IsChecked = true;
  448. }
  449. }
  450. }
  451. /// <summary>
  452. /// 设置 浏览事件
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  457. {
  458. System.Diagnostics.Process.Start(APP.WKData.WkPath);
  459. //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  460. //Ofd = new System.Windows.Forms.FolderBrowserDialog();
  461. //Result = Ofd.ShowDialog();
  462. //if (Result == System.Windows.Forms.DialogResult.OK)
  463. //{
  464. // if (Ofd.SelectedPath != "")
  465. // {
  466. // //txbStoragePath.Text = Ofd.SelectedPath;
  467. // //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  468. // //string temp = ofd.SelectedPath;
  469. // //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  470. // }
  471. //}
  472. }
  473. /// <summary>
  474. /// 画笔颜色事件 白色
  475. /// </summary>
  476. /// <param name="sender"></param>
  477. /// <param name="e"></param>
  478. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  479. {
  480. ////创建 DrawingAttributes 类的一个实例
  481. //drawingAttributes = new DrawingAttributes();
  482. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  483. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  484. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  485. ////设置 DrawingAttributes 的 Color 属性设置颜色
  486. drawingAttributes.Color = Colors.White;
  487. Color = Colors.White;
  488. }
  489. /// <summary>
  490. /// 画笔颜色事件 红色
  491. /// </summary>
  492. /// <param name="sender"></param>
  493. /// <param name="e"></param>
  494. private void BtnRed_Click(object sender, RoutedEventArgs e)
  495. {
  496. //设置 DrawingAttributes 的 Color 属性设置颜色
  497. drawingAttributes.Color = Colors.Red;
  498. Color = Colors.Red;
  499. }
  500. /// <summary>
  501. /// 画笔颜色事件 灰色
  502. /// </summary>
  503. /// <param name="sender"></param>
  504. /// <param name="e"></param>
  505. private void BtnGray_Click(object sender, RoutedEventArgs e)
  506. {
  507. drawingAttributes.Color = Colors.Gray;
  508. Color = Colors.Gray;
  509. }
  510. /// <summary>
  511. /// 画笔颜色事件 青色
  512. /// </summary>
  513. /// <param name="sender"></param>
  514. /// <param name="e"></param>
  515. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  516. {
  517. drawingAttributes.Color = Colors.LimeGreen;
  518. Color = Colors.LimeGreen;
  519. }
  520. /// <summary>
  521. /// 画笔颜色事件 黄色
  522. /// </summary>
  523. /// <param name="sender"></param>
  524. /// <param name="e"></param>
  525. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  526. {
  527. drawingAttributes.Color = Colors.Gold;
  528. Color = Colors.Gold;
  529. }
  530. /// <summary>
  531. /// 画笔颜色事件 蓝色
  532. /// </summary>
  533. /// <param name="sender"></param>
  534. /// <param name="e"></param>
  535. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  536. {
  537. drawingAttributes.Color = Colors.DeepSkyBlue;
  538. Color = Colors.DeepSkyBlue;
  539. }
  540. /// <summary>
  541. /// 画笔粗细事件 细
  542. /// </summary>
  543. /// <param name="sender"></param>
  544. /// <param name="e"></param>
  545. private void RbnFine_Click(object sender, RoutedEventArgs e)
  546. {
  547. drawingAttributes.Width = 1;
  548. drawingAttributes.Height = 1;
  549. Size = 1;
  550. }
  551. /// <summary>
  552. /// 画笔粗细事件 中
  553. /// </summary>
  554. /// <param name="sender"></param>
  555. /// <param name="e"></param>
  556. private void RbnIn_Click(object sender, RoutedEventArgs e)
  557. {
  558. drawingAttributes.Width = 3;
  559. drawingAttributes.Height = 3;
  560. Size = 3;
  561. }
  562. /// <summary>
  563. /// 画笔粗细事件 粗
  564. /// </summary>
  565. /// <param name="sender"></param>
  566. /// <param name="e"></param>
  567. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  568. {
  569. drawingAttributes.Width = 5;
  570. drawingAttributes.Height = 5;
  571. Size = 5;
  572. }
  573. /// <summary>
  574. /// 登陆事件
  575. /// </summary>
  576. /// <param name="sender"></param>
  577. /// <param name="e"></param>
  578. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  579. {
  580. Login();
  581. }
  582. /// <summary>
  583. /// 登陆
  584. /// </summary>
  585. private void Login()
  586. {
  587. if (APP.W_LoginWindow == null)
  588. {
  589. APP.W_LoginWindow = new LoginWindow();
  590. APP.W_LoginWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  591. APP.W_LoginWindow.Owner = this;
  592. }
  593. else
  594. {
  595. APP.W_LoginWindow.Initialize();
  596. }
  597. APP.W_LoginWindow.ShowDialog();
  598. if (APP.IsLoginType)
  599. {
  600. txbLoginType.Text = APP.UserInfo.Username;
  601. ImgMyMine.Visibility = Visibility.Visible;
  602. ImgMyMineTwo.Visibility = Visibility.Collapsed;
  603. ImgUpload.Visibility = Visibility.Visible;
  604. ImgUploadTwo.Visibility = Visibility.Collapsed;
  605. }
  606. else
  607. {
  608. txbLoginType.Text = "未登录";
  609. ImgMyMine.Visibility = Visibility.Collapsed;
  610. ImgMyMineTwo.Visibility = Visibility.Visible;
  611. ImgUpload.Visibility = Visibility.Collapsed;
  612. ImgUploadTwo.Visibility = Visibility.Visible;
  613. }
  614. }
  615. /// <summary>
  616. /// 截图事件
  617. /// </summary>
  618. /// <param name="sender"></param>
  619. /// <param name="e"></param>
  620. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  621. {
  622. if (APP.IsLoginType == false)
  623. {
  624. Login();
  625. return;
  626. }
  627. string time = GetTimeStamp();
  628. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  629. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  630. if (APP.W_JieTuWindow != null)
  631. {
  632. APP.W_JieTuWindow.initialization();
  633. APP.W_JieTuWindow.Screenshot();
  634. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  635. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  636. }
  637. else
  638. {
  639. APP.W_JieTuWindow = new JieTuWindow();
  640. // 订阅事件
  641. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  642. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  643. APP.W_JieTuWindow.Show();
  644. }
  645. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  646. }
  647. /// <summary>
  648. /// 截图关闭窗口
  649. /// </summary>
  650. /// <param name="text"></param>
  651. private void frm_ChangeTextEvent(string text)
  652. {
  653. if ("关闭窗口".Equals(text))
  654. {
  655. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  656. {
  657. //APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
  658. //APP.JPaths[APP.pageData.currpage] = APP.ImgPath;
  659. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  660. {
  661. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  662. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  663. }
  664. else
  665. {
  666. Model_DrawData model_DrawData = new Model_DrawData();
  667. model_DrawData.PageImagePath = APP.ImgPath;
  668. model_DrawData.PdfImagePath = APP.ImgPath;
  669. APP.PageDrawList.Add(model_DrawData);
  670. }
  671. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  672. //{
  673. // //imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  674. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage-1].PageImagePath));
  675. //}
  676. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  677. {
  678. //imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  679. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  680. //btnOk.Visibility = Visibility.Visible;
  681. //blackboard_canvas.Visibility = Visibility.Collapsed;
  682. APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
  683. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  684. ImgPrintTwo.Visibility = Visibility.Collapsed;
  685. btnPrint.IsEnabled = true;
  686. }
  687. }
  688. }
  689. }
  690. /// <summary>
  691. /// 截图关闭 非正常关闭截图时,截图清空
  692. /// </summary>
  693. private void JietuWindow_click_closeJietuWindowClick()
  694. {
  695. APP.W_JieTuWindow = null;
  696. }
  697. /// <summary>
  698. /// 获取时间戳
  699. /// </summary>
  700. /// <returns></returns>
  701. public string GetTimeStamp()
  702. {
  703. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  704. return Convert.ToInt64(ts.TotalSeconds).ToString();
  705. }
  706. /// <summary>
  707. /// 导入事件
  708. /// </summary>
  709. /// <param name="sender"></param>
  710. /// <param name="e"></param>
  711. private void BtnImport_Click(object sender, RoutedEventArgs e)
  712. {
  713. if (APP.IsLoginType == false)
  714. {
  715. Login();
  716. return;
  717. }
  718. try
  719. {
  720. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  721. ofd = new System.Windows.Forms.OpenFileDialog
  722. {
  723. Filter = "文档|*.docx;*.doc;*ppt",
  724. InitialDirectory = desktopPath,
  725. Multiselect = false,
  726. AddExtension = true,
  727. DereferenceLinks = true
  728. };
  729. new Thread(
  730. o =>
  731. {
  732. Thread.Sleep(400);
  733. Dispatcher.Invoke(new Action(() =>
  734. {
  735. OpenDialog();
  736. }
  737. ));
  738. })
  739. {
  740. IsBackground = true
  741. }.Start();
  742. }
  743. catch (Exception ex)
  744. {
  745. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  746. }
  747. }
  748. /// <summary>
  749. /// 导入文档
  750. /// </summary>
  751. private void OpenDialog()
  752. {
  753. result = ofd.ShowDialog();
  754. if (result == System.Windows.Forms.DialogResult.OK)
  755. {
  756. if (ofd.FileName != "")
  757. {
  758. #region PPT转PDF
  759. string filepath = ofd.FileName;
  760. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  761. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  762. if (type.Contains("typezsygppt"))//ppt
  763. {
  764. try
  765. {
  766. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  767. path = pathTemp + path + ".pdf";
  768. //PPT转PDF
  769. Presentation ppt = new Presentation(filepath);
  770. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  771. #endregion
  772. #region PDF转图片
  773. // 图片绝对路径集合
  774. List<string> images = new List<string>();
  775. string directoryPath = pathTemp;
  776. //aspose许可证
  777. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  778. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  779. //l.SetLicense(licenseName);
  780. //定义Jpeg转换设备
  781. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  782. var device = new Aspose.Pdf.Devices.JpegDevice();
  783. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  784. //directoryPath += quality;
  785. Directory.CreateDirectory(directoryPath);
  786. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  787. device = new Aspose.Pdf.Devices.JpegDevice(100);
  788. //遍历每一页转为jpg
  789. for (var i = 1; i <= document.Pages.Count; i++)
  790. {
  791. long ii = Timestamp();
  792. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  793. images.Add(filePathOutPut);
  794. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  795. try
  796. {
  797. device.Process(document.Pages[i], fs);
  798. fs.Close();
  799. }
  800. catch (Exception ex)
  801. {
  802. fs.Close();
  803. File.Delete(filePathOutPut);
  804. }
  805. }
  806. #endregion
  807. //APP.Paths = images.ToArray();
  808. //ImgPDFPath = images.ToArray();
  809. string[] page = images.ToArray();
  810. if(page.Length>0)
  811. {
  812. APP.PageDrawList = null;
  813. APP.PageDrawList = new List<Model_DrawData>();
  814. }
  815. for (int i = 0; i < page.Length; i++)//给画板模型加图片路径
  816. {
  817. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  818. {
  819. APP.PageDrawList[i].PageImagePath = page[i]; //zxycs
  820. APP.PageDrawList[i].PdfImagePath = page[i];
  821. APP.PageDrawList[i].PageNum = i + 1;
  822. APP.PageDrawList[i].ImgDocumentation = true;
  823. }
  824. else
  825. {
  826. Model_DrawData model_DrawData = new Model_DrawData();
  827. model_DrawData.PageImagePath = page[i];
  828. model_DrawData.PdfImagePath = page[i];
  829. model_DrawData.PageNum = i + 1;
  830. model_DrawData.ImgDocumentation = true;
  831. APP.PageDrawList.Add(model_DrawData);
  832. }
  833. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  834. ImgPrintTwo.Visibility = Visibility.Collapsed;
  835. btnPrint.IsEnabled = true;
  836. APP.SaveDraw();
  837. }
  838. myblackboard.clear();
  839. APP.pageData.pagenum = 1;
  840. APP.pageData.currpage = 1;
  841. for (int i = 0; i < APP.PageDrawList.Count; i++)
  842. {
  843. APP.pageData.pagenum += 1;
  844. }
  845. if (APP.pageData.pagenum > 1)
  846. {
  847. APP.pageData.pagenum -= 1;
  848. }
  849. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.PageDrawList.Count)
  850. {
  851. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  852. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  853. }
  854. else
  855. {
  856. imgCanvas.Source = null;
  857. }
  858. }
  859. catch (Exception ex)
  860. {
  861. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  862. }
  863. }
  864. else//word
  865. {
  866. try
  867. {
  868. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  869. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  870. //APP.Paths = page;//cs
  871. //ImgPDFPath = page;
  872. if (page.Length > 0)
  873. {
  874. APP.PageDrawList = null;
  875. APP.PageDrawList = new List<Model_DrawData>();
  876. }
  877. for (int i = 0; i < page.Length; i++)//给画板模型加图片路径
  878. {
  879. if (APP.PageDrawList!=null&&APP.PageDrawList.Count > i)
  880. {
  881. APP.PageDrawList[i].PageImagePath = page[i]; //zxycs
  882. APP.PageDrawList[i].PdfImagePath = page[i];
  883. APP.PageDrawList[i].PageNum = i + 1;
  884. APP.PageDrawList[i].ImgDocumentation = true;
  885. }
  886. else
  887. {
  888. Model_DrawData model_DrawData = new Model_DrawData();
  889. model_DrawData.PageImagePath = page[i];
  890. model_DrawData.PdfImagePath = page[i];
  891. model_DrawData.PageNum = i + 1;
  892. model_DrawData.ImgDocumentation = true;
  893. APP.PageDrawList.Add(model_DrawData);
  894. }
  895. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  896. ImgPrintTwo.Visibility = Visibility.Collapsed;
  897. btnPrint.IsEnabled = true;
  898. APP.SaveDraw();
  899. }
  900. APP.pageData.pagenum = 1;
  901. APP.pageData.currpage = 1;
  902. //myblackboard.clear();
  903. for (int i = 0; i < APP.PageDrawList.Count; i++)
  904. {
  905. APP.pageData.pagenum += 1;
  906. }
  907. if (APP.pageData.pagenum > 1)
  908. {
  909. APP.pageData.pagenum -= 1;
  910. }
  911. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.PageDrawList.Count)
  912. {
  913. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  914. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  915. }
  916. else
  917. {
  918. imgCanvas.Source = null;
  919. }
  920. }
  921. catch (Exception ex)
  922. {
  923. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
  924. }
  925. }
  926. }
  927. }
  928. }
  929. /// <summary>
  930. /// 返回一个时间戳到毫秒
  931. /// </summary>
  932. /// <returns></returns>
  933. public static long Timestamp()
  934. {
  935. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  936. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  937. return timestr;
  938. }
  939. #region 录制窗口
  940. #region 变量
  941. /// <summary>
  942. /// 视频保存路径
  943. /// </summary>
  944. string RecordingPath;
  945. /// <summary>
  946. /// 图片保存路径
  947. /// </summary>
  948. string ImgPath;
  949. /// <summary>
  950. /// 音频保存路径名
  951. /// </summary>
  952. string AudioPathName;
  953. /// <summary>
  954. /// 视频保存路径名
  955. /// </summary>
  956. string VideoSavePathName;
  957. /// <summary>
  958. /// 暂停录制
  959. /// </summary>
  960. bool IsSuspendR = true;
  961. /// <summary>
  962. /// 录制是否已停止
  963. /// </summary>
  964. bool IsFirstR = true;
  965. /// <summary>
  966. /// 图片
  967. /// </summary>
  968. List<string> RsImgName = null;
  969. /// <summary>
  970. /// 是否开始截图计数
  971. /// </summary>
  972. bool IsStartCount = false;
  973. #endregion
  974. /// <summary>
  975. /// 录制窗口内容
  976. /// </summary>
  977. /// <param name="sender"></param>
  978. /// <param name="e"></param>
  979. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  980. {
  981. if (APP.IsLoginType == false)
  982. {
  983. Login();
  984. return;
  985. }
  986. blackboard_canvas.Visibility = Visibility.Visible;
  987. StartRecord();
  988. }
  989. /// <summary>
  990. /// 停止录制窗口内容
  991. /// </summary>
  992. /// <param name="sender"></param>
  993. /// <param name="e"></param>
  994. private void BtnStop_Click(object sender, RoutedEventArgs e)
  995. {
  996. if (APP.IsLoginType == false)
  997. {
  998. Login();
  999. return;
  1000. }
  1001. blackboard_canvas.Visibility = Visibility.Collapsed;
  1002. EndRecord();
  1003. }
  1004. System.Timers.Timer timer;
  1005. /// <summary>
  1006. /// 开始录制和暂停录制
  1007. /// </summary>
  1008. void StartRecord()
  1009. {
  1010. if (IsSuspendR)
  1011. {
  1012. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1013. ImgPrintTwo.Visibility = Visibility.Visible;
  1014. btnPrint.IsEnabled = false;
  1015. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1016. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1017. btnScreenshot.IsEnabled = false;
  1018. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1019. ImgImportTwo.Visibility = Visibility.Visible;
  1020. btnImport.IsEnabled = false;
  1021. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1022. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1023. btnScreenRecording.IsEnabled = false;
  1024. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1025. ImgUploadTwo.Visibility = Visibility.Visible;
  1026. btnUpload.IsEnabled = false;
  1027. ImgMyMine.Visibility = Visibility.Collapsed;//录制中不可点击我的
  1028. ImgMyMineTwo.Visibility = Visibility.Visible;
  1029. btnMyMine.IsEnabled = false;
  1030. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1031. ImgSetUpTwo.Visibility = Visibility.Visible;
  1032. btnSetUp.IsEnabled = false;
  1033. btnLoginType.IsEnabled = false;
  1034. if (IsFirstR)//是否第一次录制 初始化录制
  1035. {
  1036. VideoInfo = new Model_Video();
  1037. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  1038. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  1039. RecordingPath = APP.WKData.WkPath;
  1040. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1041. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1042. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1043. FileToolsCommon.CreateDirectory(RecordingPath);
  1044. FileToolsCommon.CreateDirectory(ImgPath);
  1045. FileToolsCommon.CreateDirectory(AudioPathName);
  1046. AudioPathName += APP.WKData.WkName + ".MP3";
  1047. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1048. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1049. {
  1050. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1051. if (dr == MessageBoxResult.OK)
  1052. {
  1053. try
  1054. {
  1055. FileToolsCommon.DeleteFile(VideoSavePathName);
  1056. APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1057. }
  1058. catch (Exception ex)
  1059. {
  1060. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1061. }
  1062. }
  1063. else
  1064. {
  1065. return;
  1066. }
  1067. }
  1068. IsFirstR = false;
  1069. RsImgName = new List<string>();
  1070. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  1071. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  1072. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1073. timer.Enabled = true; //启动计时器
  1074. }
  1075. #region 录像倒计时
  1076. if (APP.W_CountdownWindow == null)
  1077. {
  1078. APP.W_CountdownWindow = new CountdownWindow();
  1079. //APP.W_CountdownWindow.Topmost = true;
  1080. }
  1081. else
  1082. {
  1083. APP.W_CountdownWindow.Initialize();
  1084. APP.W_CountdownWindow.Topmost = true;
  1085. }
  1086. APP.W_CountdownWindow.Show();
  1087. #endregion
  1088. //继续录制
  1089. IsSuspendR = false;
  1090. //BtnRecording.Content = "暂停录制";
  1091. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1092. TxbRecordingWord.Text = "暂停";
  1093. try
  1094. {
  1095. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1096. new Thread(new ThreadStart(new Action(() =>
  1097. {
  1098. Thread.Sleep(1000);
  1099. Dispatcher.Invoke(() =>
  1100. {
  1101. IsStartCount = true;
  1102. //timer.Start();
  1103. });
  1104. }))).Start();
  1105. }
  1106. catch (Exception ex)
  1107. {
  1108. System.Windows.MessageBox.Show(ex.Message);
  1109. }
  1110. }
  1111. else
  1112. {
  1113. //暂停
  1114. IsSuspendR = true;
  1115. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1116. TxbRecordingWord.Text = "继续";
  1117. try
  1118. {
  1119. APP.FFmpeg.SuspendFFmpeg();
  1120. new Thread(new ThreadStart(new Action(() =>
  1121. {
  1122. while (APP.FFmpeg.myProcess != null)
  1123. {
  1124. Thread.Sleep(100);
  1125. }
  1126. IsStartCount = false;
  1127. }))).Start();
  1128. }
  1129. catch (Exception ex)
  1130. {
  1131. System.Windows.MessageBox.Show(ex.Message);
  1132. }
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// 录制保存图片
  1137. /// </summary>
  1138. /// <param name="sender"></param>
  1139. /// <param name="e"></param>
  1140. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  1141. {
  1142. if (IsStartCount)
  1143. {
  1144. try
  1145. {
  1146. Dispatcher.Invoke(() =>
  1147. {
  1148. string FilePathName = ImgPath + RsImgName.Count + ".png";
  1149. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  1150. RsImgName.Add(FilePathName);
  1151. });
  1152. }
  1153. catch (Exception ex)
  1154. {
  1155. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1156. }
  1157. }
  1158. }
  1159. /// <summary>
  1160. /// 停止录制并生成录制文件
  1161. /// </summary>
  1162. void EndRecord()
  1163. {
  1164. if (!IsFirstR)
  1165. {
  1166. ImgPrint.Visibility = Visibility.Visible;
  1167. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1168. btnPrint.IsEnabled = true;
  1169. ImgScreenshot.Visibility = Visibility.Visible;
  1170. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1171. btnScreenshot.IsEnabled = true;
  1172. ImgImport.Visibility = Visibility.Visible;
  1173. ImgImportTwo.Visibility = Visibility.Collapsed;
  1174. btnImport.IsEnabled = true;
  1175. ImgScreenRecording.Visibility = Visibility.Visible;
  1176. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  1177. btnScreenRecording.IsEnabled = true;
  1178. ImgUpload.Visibility = Visibility.Visible;
  1179. ImgUploadTwo.Visibility = Visibility.Collapsed;
  1180. btnUpload.IsEnabled = true;
  1181. ImgMyMine.Visibility = Visibility.Visible;
  1182. ImgMyMineTwo.Visibility = Visibility.Collapsed;
  1183. btnMyMine.IsEnabled = true;
  1184. ImgSetUp.Visibility = Visibility.Visible;
  1185. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  1186. btnSetUp.IsEnabled = true;
  1187. btnLoginType.IsEnabled = true;
  1188. IsSuspendR = true;
  1189. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1190. TxbRecordingWord.Text = "录制";
  1191. try
  1192. {
  1193. APP.FFmpeg.StopFFmpeg(AudioPathName);
  1194. new Thread(new ThreadStart(new Action(() =>
  1195. {
  1196. while (APP.FFmpeg.myProcess != null)
  1197. {
  1198. Thread.Sleep(100);
  1199. }
  1200. Dispatcher.Invoke(() =>
  1201. {
  1202. IsStartCount = false;
  1203. timer.Stop();
  1204. });
  1205. }))).Start();
  1206. new Thread(new ThreadStart(new Action(() =>
  1207. {
  1208. while (APP.FFmpeg.myProcess != null)
  1209. {
  1210. Thread.Sleep(100);
  1211. }
  1212. }))).Start();
  1213. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  1214. //生成缩略图
  1215. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  1216. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1217. //缩略图存储位置
  1218. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  1219. new Thread(new ThreadStart(new Action(() =>
  1220. {
  1221. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  1222. {
  1223. Thread.Sleep(100);
  1224. }
  1225. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1226. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  1227. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1228. VideoInfo.VideoPath = VideoSavePathName;
  1229. VideoInfo.ThumbnailPath = ThumbnailPathName;
  1230. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  1231. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  1232. VideoInfo.IsUpload = false;
  1233. VideoInfo.Uploaded = 0;
  1234. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  1235. APP.VideoList.Add(VideoInfo);
  1236. //保存数据
  1237. APP.SaveWkData();
  1238. IsFirstR = true;
  1239. }))).Start();
  1240. //List<Model_Video> VideoList
  1241. }
  1242. catch (Exception ex)
  1243. {
  1244. System.Windows.MessageBox.Show(ex.Message);
  1245. }
  1246. }
  1247. }
  1248. #endregion
  1249. /// <summary>
  1250. /// 增加事件
  1251. /// </summary>
  1252. /// <param name="sender"></param>
  1253. /// <param name="e"></param>
  1254. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  1255. {
  1256. if (APP.IsLoginType == false)
  1257. {
  1258. Login();
  1259. return;
  1260. }
  1261. if (APP.pageData.pagenum < 200)
  1262. {
  1263. if (APP.PageDrawList != null && APP.PageDrawList.Count > 0 && APP.PageDrawList.Count > APP.pageData.currpage - 1
  1264. && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1265. {
  1266. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1267. }
  1268. APP.pageData.pagenum += 1;
  1269. APP.pageData.currpage = APP.pageData.pagenum;
  1270. myblackboard.changepage(APP.pageData.currpage - 1);
  1271. imgCanvas.Source = null;
  1272. Model_DrawData model_DrawData = new Model_DrawData();
  1273. model_DrawData.PageNum = APP.pageData.currpage;
  1274. APP.PageDrawList.Add(model_DrawData);
  1275. APP.SaveDraw();//画板模型增加一页
  1276. }
  1277. else
  1278. {
  1279. System.Windows.Forms.MessageBox.Show("已达到最大页数无法继续增加!");
  1280. }
  1281. }
  1282. /// <summary>
  1283. /// 打印事件
  1284. /// </summary>
  1285. /// <param name="sender"></param>
  1286. /// <param name="e"></param>
  1287. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  1288. {
  1289. if (APP.IsLoginType == false)
  1290. {
  1291. Login();
  1292. return;
  1293. }
  1294. //for(int i=0;i< APP.pageData.pagenum; i++)
  1295. //{
  1296. //}
  1297. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  1298. try
  1299. {
  1300. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  1301. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  1302. ////设置纸张横向
  1303. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  1304. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  1305. FileToolsCommon.CreateFile(imgPath);
  1306. imgPath += "\\101.pdf";
  1307. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  1308. document.Open();
  1309. iTextSharp.text.Image image;
  1310. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1311. {
  1312. if (String.IsNullOrEmpty(APP.PageDrawList[i].PdfImagePath)) break;
  1313. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PdfImagePath);
  1314. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  1315. {
  1316. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1317. }
  1318. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  1319. {
  1320. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1321. }
  1322. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  1323. document.NewPage();
  1324. document.Add(image);
  1325. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  1326. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  1327. //p1.Leading = 150; //行间距
  1328. //document.Add(p1);
  1329. }
  1330. Console.WriteLine("转换成功!");
  1331. document.Close();
  1332. }
  1333. catch (Exception ex)
  1334. {
  1335. Console.WriteLine("转换失败,原因:" + ex.Message);
  1336. }
  1337. //document.Close();
  1338. ////Console.ReadKey();
  1339. if (APP.W_PrintWindow == null)
  1340. {
  1341. APP.W_PrintWindow = new PrintWindow();
  1342. APP.W_PrintWindow.Topmost = true;
  1343. APP.W_PrintWindow.Owner = this;
  1344. }
  1345. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PdfImagePath))
  1346. {
  1347. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PdfImagePath);
  1348. }
  1349. else
  1350. {
  1351. APP.W_PrintWindow.Initialize("");
  1352. }
  1353. APP.W_PrintWindow.Show();
  1354. //int pr = 1;
  1355. //string msg = string.Empty;
  1356. //string outPut = string.Empty;
  1357. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1358. //if(pr==0)
  1359. //{
  1360. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1361. // APP.OutPut = outPut.Split(',');
  1362. // string defa = string.Empty;
  1363. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1364. // int printResult = 1;
  1365. // string standardError = string.Empty;
  1366. // string standardOutput = string.Empty;
  1367. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1368. //}
  1369. }
  1370. /// <summary>
  1371. /// 我的
  1372. /// </summary>
  1373. /// <param name="sender"></param>
  1374. /// <param name="e"></param>
  1375. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  1376. {
  1377. if (APP.IsLoginType == false)
  1378. {
  1379. Login();
  1380. return;
  1381. }
  1382. }
  1383. /// <summary>
  1384. /// 上一页
  1385. /// </summary>
  1386. /// <param name="sender"></param>
  1387. /// <param name="e"></param>
  1388. private void last_button_Click(object sender, RoutedEventArgs e)
  1389. {
  1390. if (APP.pageData.currpage > 1)
  1391. {
  1392. try
  1393. {
  1394. Dispatcher.Invoke(() =>
  1395. {
  1396. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1397. FileToolsCommon.CreateDirectory(filePath);
  1398. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1399. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1400. //ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1401. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = filePathName;
  1402. });
  1403. }
  1404. catch (Exception ex)
  1405. {
  1406. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
  1407. }
  1408. APP.pageData.currpage -= 1;
  1409. myblackboard.changepage(APP.pageData.currpage - 1);
  1410. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1411. {
  1412. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1413. {
  1414. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1415. }
  1416. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1417. {
  1418. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1419. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1420. {
  1421. imgCanvas.Source = null;
  1422. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1423. }
  1424. else
  1425. {
  1426. imgDocumentation.Source = null;
  1427. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1428. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1429. {
  1430. var group = IMG.FindResource("Imageview") as TransformGroup;
  1431. var transform = group.Children[1] as TranslateTransform;
  1432. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1433. //{
  1434. // var transform1 = group.Children[0] as ScaleTransform;
  1435. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1436. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1437. //}
  1438. //var position = e.GetPosition(img);
  1439. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1440. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1441. mouseDown = false;
  1442. }
  1443. }
  1444. }
  1445. else
  1446. {
  1447. imgCanvas.Source = null;
  1448. imgDocumentation.Source = null;
  1449. }
  1450. }
  1451. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1452. //{
  1453. // imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1454. //}
  1455. }
  1456. }
  1457. /// <summary>
  1458. /// 下一页
  1459. /// </summary>
  1460. /// <param name="sender"></param>
  1461. /// <param name="e"></param>
  1462. private void next_btn_Click(object sender, RoutedEventArgs e)
  1463. {
  1464. if (APP.pageData.currpage < APP.pageData.pagenum)
  1465. {
  1466. try
  1467. {
  1468. Dispatcher.Invoke(() =>
  1469. {
  1470. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1471. FileToolsCommon.CreateDirectory(filePath);
  1472. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1473. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1474. //ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1475. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = filePathName;
  1476. });
  1477. }
  1478. catch (Exception ex)
  1479. {
  1480. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
  1481. }
  1482. APP.pageData.currpage += 1;
  1483. myblackboard.changepage(APP.pageData.currpage - 1);
  1484. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1485. {
  1486. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1487. {
  1488. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1489. }
  1490. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1491. {
  1492. if(APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1493. {
  1494. imgCanvas.Source = null;
  1495. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1496. }
  1497. else
  1498. {
  1499. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1500. imgDocumentation.Source = null;
  1501. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1502. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1503. {
  1504. var group = IMG.FindResource("Imageview") as TransformGroup;
  1505. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1506. //{
  1507. // var transform1 = group.Children[0] as ScaleTransform;
  1508. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1509. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1510. //}
  1511. var transform = group.Children[1] as TranslateTransform;
  1512. //var position = e.GetPosition(img);
  1513. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1514. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1515. mouseDown = false;
  1516. }
  1517. }
  1518. }
  1519. else
  1520. {
  1521. imgCanvas.Source = null;
  1522. imgDocumentation.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. }