星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XHMicroLessonSystemWindow.xaml.cs 95KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  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. APP.fileDirectoryWindow.Initialize();
  297. }
  298. APP.fileDirectoryWindow.ShowDialog();
  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. imgDocumentation.Source = null;
  680. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  681. //btnOk.Visibility = Visibility.Visible;
  682. //blackboard_canvas.Visibility = Visibility.Collapsed;
  683. APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
  684. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  685. ImgPrintTwo.Visibility = Visibility.Collapsed;
  686. btnPrint.IsEnabled = true;
  687. }
  688. }
  689. }
  690. }
  691. /// <summary>
  692. /// 截图关闭 非正常关闭截图时,截图清空
  693. /// </summary>
  694. private void JietuWindow_click_closeJietuWindowClick()
  695. {
  696. APP.W_JieTuWindow = null;
  697. }
  698. /// <summary>
  699. /// 获取时间戳
  700. /// </summary>
  701. /// <returns></returns>
  702. public string GetTimeStamp()
  703. {
  704. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  705. return Convert.ToInt64(ts.TotalSeconds).ToString();
  706. }
  707. /// <summary>
  708. /// 导入事件
  709. /// </summary>
  710. /// <param name="sender"></param>
  711. /// <param name="e"></param>
  712. private void BtnImport_Click(object sender, RoutedEventArgs e)
  713. {
  714. if (APP.IsLoginType == false)
  715. {
  716. Login();
  717. return;
  718. }
  719. try
  720. {
  721. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  722. ofd = new System.Windows.Forms.OpenFileDialog
  723. {
  724. Filter = "文档|*.docx;*.doc;*ppt",
  725. InitialDirectory = desktopPath,
  726. Multiselect = false,
  727. AddExtension = true,
  728. DereferenceLinks = true
  729. };
  730. new Thread(
  731. o =>
  732. {
  733. Thread.Sleep(400);
  734. Dispatcher.Invoke(new Action(() =>
  735. {
  736. OpenDialog();
  737. }
  738. ));
  739. })
  740. {
  741. IsBackground = true
  742. }.Start();
  743. }
  744. catch (Exception ex)
  745. {
  746. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  747. }
  748. }
  749. /// <summary>
  750. /// 导入文档
  751. /// </summary>
  752. private void OpenDialog()
  753. {
  754. result = ofd.ShowDialog();
  755. if (result == System.Windows.Forms.DialogResult.OK)
  756. {
  757. if (ofd.FileName != "")
  758. {
  759. #region PPT转PDF
  760. string filepath = ofd.FileName;
  761. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  762. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  763. if (type.Contains("typezsygppt"))//ppt
  764. {
  765. try
  766. {
  767. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  768. path = pathTemp + path + ".pdf";
  769. //PPT转PDF
  770. Presentation ppt = new Presentation(filepath);
  771. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  772. #endregion
  773. #region PDF转图片
  774. // 图片绝对路径集合
  775. List<string> images = new List<string>();
  776. string directoryPath = pathTemp;
  777. //aspose许可证
  778. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  779. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  780. //l.SetLicense(licenseName);
  781. //定义Jpeg转换设备
  782. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  783. var device = new Aspose.Pdf.Devices.JpegDevice();
  784. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  785. //directoryPath += quality;
  786. Directory.CreateDirectory(directoryPath);
  787. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  788. device = new Aspose.Pdf.Devices.JpegDevice(100);
  789. //遍历每一页转为jpg
  790. for (var i = 1; i <= document.Pages.Count; i++)
  791. {
  792. long ii = Timestamp();
  793. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  794. images.Add(filePathOutPut);
  795. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  796. try
  797. {
  798. device.Process(document.Pages[i], fs);
  799. fs.Close();
  800. }
  801. catch (Exception ex)
  802. {
  803. fs.Close();
  804. File.Delete(filePathOutPut);
  805. }
  806. }
  807. #endregion
  808. //APP.Paths = images.ToArray();
  809. //ImgPDFPath = images.ToArray();
  810. string[] page = images.ToArray();
  811. if(page.Length>0)
  812. {
  813. APP.PageDrawList = null;
  814. APP.PageDrawList = new List<Model_DrawData>();
  815. }
  816. for (int i = 0; i < page.Length; i++)//给画板模型加图片路径
  817. {
  818. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  819. {
  820. APP.PageDrawList[i].PageImagePath = page[i]; //zxycs
  821. APP.PageDrawList[i].PdfImagePath = page[i];
  822. APP.PageDrawList[i].PageNum = i + 1;
  823. APP.PageDrawList[i].ImgDocumentation = true;
  824. }
  825. else
  826. {
  827. Model_DrawData model_DrawData = new Model_DrawData();
  828. model_DrawData.PageImagePath = page[i];
  829. model_DrawData.PdfImagePath = page[i];
  830. model_DrawData.PageNum = i + 1;
  831. model_DrawData.ImgDocumentation = true;
  832. APP.PageDrawList.Add(model_DrawData);
  833. }
  834. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  835. ImgPrintTwo.Visibility = Visibility.Collapsed;
  836. btnPrint.IsEnabled = true;
  837. APP.SaveDraw();
  838. }
  839. myblackboard.clear();
  840. APP.pageData.pagenum = 1;
  841. APP.pageData.currpage = 1;
  842. for (int i = 0; i < APP.PageDrawList.Count; i++)
  843. {
  844. APP.pageData.pagenum += 1;
  845. }
  846. if (APP.pageData.pagenum > 1)
  847. {
  848. APP.pageData.pagenum -= 1;
  849. }
  850. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.PageDrawList.Count)
  851. {
  852. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  853. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  854. imgCanvas.Source = null;
  855. }
  856. else
  857. {
  858. imgDocumentation.Source = null;
  859. imgCanvas.Source = null;
  860. }
  861. }
  862. catch (Exception ex)
  863. {
  864. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  865. }
  866. }
  867. else//word
  868. {
  869. try
  870. {
  871. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  872. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  873. //APP.Paths = page;//cs
  874. //ImgPDFPath = page;
  875. if (page.Length > 0)
  876. {
  877. APP.PageDrawList = null;
  878. APP.PageDrawList = new List<Model_DrawData>();
  879. }
  880. for (int i = 0; i < page.Length; i++)//给画板模型加图片路径
  881. {
  882. if (APP.PageDrawList!=null&&APP.PageDrawList.Count > i)
  883. {
  884. APP.PageDrawList[i].PageImagePath = page[i]; //zxycs
  885. APP.PageDrawList[i].PdfImagePath = page[i];
  886. APP.PageDrawList[i].PageNum = i + 1;
  887. APP.PageDrawList[i].ImgDocumentation = true;
  888. }
  889. else
  890. {
  891. Model_DrawData model_DrawData = new Model_DrawData();
  892. model_DrawData.PageImagePath = page[i];
  893. model_DrawData.PdfImagePath = page[i];
  894. model_DrawData.PageNum = i + 1;
  895. model_DrawData.ImgDocumentation = true;
  896. APP.PageDrawList.Add(model_DrawData);
  897. }
  898. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  899. ImgPrintTwo.Visibility = Visibility.Collapsed;
  900. btnPrint.IsEnabled = true;
  901. APP.SaveDraw();
  902. }
  903. APP.pageData.pagenum = 1;
  904. APP.pageData.currpage = 1;
  905. //myblackboard.clear();
  906. for (int i = 0; i < APP.PageDrawList.Count; i++)
  907. {
  908. APP.pageData.pagenum += 1;
  909. }
  910. if (APP.pageData.pagenum > 1)
  911. {
  912. APP.pageData.pagenum -= 1;
  913. }
  914. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.PageDrawList.Count)
  915. {
  916. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  917. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  918. imgCanvas.Source = null;
  919. }
  920. else
  921. {
  922. imgDocumentation.Source = null;
  923. imgCanvas.Source = null;
  924. }
  925. }
  926. catch (Exception ex)
  927. {
  928. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
  929. }
  930. }
  931. }
  932. }
  933. }
  934. /// <summary>
  935. /// 返回一个时间戳到毫秒
  936. /// </summary>
  937. /// <returns></returns>
  938. public static long Timestamp()
  939. {
  940. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  941. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  942. return timestr;
  943. }
  944. #region 录制窗口
  945. #region 变量
  946. /// <summary>
  947. /// 视频保存路径
  948. /// </summary>
  949. string RecordingPath;
  950. /// <summary>
  951. /// 图片保存路径
  952. /// </summary>
  953. string ImgPath;
  954. /// <summary>
  955. /// 音频保存路径名
  956. /// </summary>
  957. string AudioPathName;
  958. /// <summary>
  959. /// 视频保存路径名
  960. /// </summary>
  961. string VideoSavePathName;
  962. /// <summary>
  963. /// 暂停录制
  964. /// </summary>
  965. bool IsSuspendR = true;
  966. /// <summary>
  967. /// 录制是否已停止
  968. /// </summary>
  969. bool IsFirstR = true;
  970. /// <summary>
  971. /// 图片
  972. /// </summary>
  973. List<string> RsImgName = null;
  974. /// <summary>
  975. /// 是否开始截图计数
  976. /// </summary>
  977. bool IsStartCount = false;
  978. #endregion
  979. /// <summary>
  980. /// 录制窗口内容
  981. /// </summary>
  982. /// <param name="sender"></param>
  983. /// <param name="e"></param>
  984. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  985. {
  986. if (APP.IsLoginType == false)
  987. {
  988. Login();
  989. return;
  990. }
  991. blackboard_canvas.Visibility = Visibility.Visible;
  992. StartRecord();
  993. }
  994. /// <summary>
  995. /// 停止录制窗口内容
  996. /// </summary>
  997. /// <param name="sender"></param>
  998. /// <param name="e"></param>
  999. private void BtnStop_Click(object sender, RoutedEventArgs e)
  1000. {
  1001. if (APP.IsLoginType == false)
  1002. {
  1003. Login();
  1004. return;
  1005. }
  1006. blackboard_canvas.Visibility = Visibility.Collapsed;
  1007. EndRecord();
  1008. }
  1009. System.Timers.Timer timer;
  1010. /// <summary>
  1011. /// 开始录制和暂停录制
  1012. /// </summary>
  1013. void StartRecord()
  1014. {
  1015. if (IsSuspendR)
  1016. {
  1017. if (IsFirstR)//是否第一次录制 初始化录制
  1018. {
  1019. VideoInfo = new Model_Video();
  1020. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  1021. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  1022. RecordingPath = APP.WKData.WkPath;
  1023. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1024. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1025. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1026. FileToolsCommon.CreateDirectory(RecordingPath);
  1027. FileToolsCommon.CreateDirectory(ImgPath);
  1028. FileToolsCommon.CreateDirectory(AudioPathName);
  1029. AudioPathName += APP.WKData.WkName + ".MP3";
  1030. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1031. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1032. {
  1033. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1034. if (dr == MessageBoxResult.OK)
  1035. {
  1036. try
  1037. {
  1038. FileToolsCommon.DeleteFile(VideoSavePathName);
  1039. APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1040. }
  1041. catch (Exception ex)
  1042. {
  1043. LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1044. }
  1045. }
  1046. else
  1047. {
  1048. return;
  1049. }
  1050. }
  1051. #region 禁用按钮
  1052. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1053. ImgPrintTwo.Visibility = Visibility.Visible;
  1054. btnPrint.IsEnabled = false;
  1055. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1056. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1057. btnScreenshot.IsEnabled = false;
  1058. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1059. ImgImportTwo.Visibility = Visibility.Visible;
  1060. btnImport.IsEnabled = false;
  1061. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1062. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1063. btnScreenRecording.IsEnabled = false;
  1064. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1065. ImgUploadTwo.Visibility = Visibility.Visible;
  1066. btnUpload.IsEnabled = false;
  1067. ImgMyMine.Visibility = Visibility.Collapsed;//录制中不可点击我的
  1068. ImgMyMineTwo.Visibility = Visibility.Visible;
  1069. btnMyMine.IsEnabled = false;
  1070. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1071. ImgSetUpTwo.Visibility = Visibility.Visible;
  1072. btnSetUp.IsEnabled = false;
  1073. btnLoginType.IsEnabled = false;
  1074. #endregion
  1075. IsFirstR = false;
  1076. RsImgName = new List<string>();
  1077. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  1078. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  1079. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1080. timer.Enabled = true; //启动计时器
  1081. }
  1082. #region 录像倒计时
  1083. if (APP.W_CountdownWindow == null)
  1084. {
  1085. APP.W_CountdownWindow = new CountdownWindow();
  1086. //APP.W_CountdownWindow.Topmost = true;
  1087. }
  1088. else
  1089. {
  1090. APP.W_CountdownWindow.Initialize();
  1091. APP.W_CountdownWindow.Topmost = true;
  1092. }
  1093. APP.W_CountdownWindow.Show();
  1094. #endregion
  1095. //继续录制
  1096. IsSuspendR = false;
  1097. //BtnRecording.Content = "暂停录制";
  1098. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1099. TxbRecordingWord.Text = "暂停";
  1100. try
  1101. {
  1102. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1103. new Thread(new ThreadStart(new Action(() =>
  1104. {
  1105. Thread.Sleep(1000);
  1106. Dispatcher.Invoke(() =>
  1107. {
  1108. IsStartCount = true;
  1109. //timer.Start();
  1110. });
  1111. }))).Start();
  1112. }
  1113. catch (Exception ex)
  1114. {
  1115. System.Windows.MessageBox.Show(ex.Message);
  1116. }
  1117. }
  1118. else
  1119. {
  1120. //暂停
  1121. IsSuspendR = true;
  1122. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1123. TxbRecordingWord.Text = "继续";
  1124. try
  1125. {
  1126. APP.FFmpeg.SuspendFFmpeg();
  1127. new Thread(new ThreadStart(new Action(() =>
  1128. {
  1129. while (APP.FFmpeg.myProcess != null)
  1130. {
  1131. Thread.Sleep(100);
  1132. }
  1133. IsStartCount = false;
  1134. }))).Start();
  1135. }
  1136. catch (Exception ex)
  1137. {
  1138. System.Windows.MessageBox.Show(ex.Message);
  1139. }
  1140. }
  1141. }
  1142. /// <summary>
  1143. /// 录制保存图片
  1144. /// </summary>
  1145. /// <param name="sender"></param>
  1146. /// <param name="e"></param>
  1147. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  1148. {
  1149. if (IsStartCount)
  1150. {
  1151. try
  1152. {
  1153. Dispatcher.Invoke(() =>
  1154. {
  1155. string FilePathName = ImgPath + RsImgName.Count + ".png";
  1156. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  1157. RsImgName.Add(FilePathName);
  1158. });
  1159. }
  1160. catch (Exception ex)
  1161. {
  1162. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1163. }
  1164. }
  1165. }
  1166. /// <summary>
  1167. /// 停止录制并生成录制文件
  1168. /// </summary>
  1169. void EndRecord()
  1170. {
  1171. if (!IsFirstR)
  1172. {
  1173. ImgPrint.Visibility = Visibility.Visible;
  1174. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1175. btnPrint.IsEnabled = true;
  1176. ImgScreenshot.Visibility = Visibility.Visible;
  1177. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1178. btnScreenshot.IsEnabled = true;
  1179. ImgImport.Visibility = Visibility.Visible;
  1180. ImgImportTwo.Visibility = Visibility.Collapsed;
  1181. btnImport.IsEnabled = true;
  1182. ImgScreenRecording.Visibility = Visibility.Visible;
  1183. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  1184. btnScreenRecording.IsEnabled = true;
  1185. ImgUpload.Visibility = Visibility.Visible;
  1186. ImgUploadTwo.Visibility = Visibility.Collapsed;
  1187. btnUpload.IsEnabled = true;
  1188. ImgMyMine.Visibility = Visibility.Visible;
  1189. ImgMyMineTwo.Visibility = Visibility.Collapsed;
  1190. btnMyMine.IsEnabled = true;
  1191. ImgSetUp.Visibility = Visibility.Visible;
  1192. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  1193. btnSetUp.IsEnabled = true;
  1194. btnLoginType.IsEnabled = true;
  1195. IsSuspendR = true;
  1196. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1197. TxbRecordingWord.Text = "录制";
  1198. try
  1199. {
  1200. APP.FFmpeg.StopFFmpeg(AudioPathName);
  1201. new Thread(new ThreadStart(new Action(() =>
  1202. {
  1203. while (APP.FFmpeg.myProcess != null)
  1204. {
  1205. Thread.Sleep(100);
  1206. }
  1207. Dispatcher.Invoke(() =>
  1208. {
  1209. IsStartCount = false;
  1210. timer.Stop();
  1211. });
  1212. }))).Start();
  1213. new Thread(new ThreadStart(new Action(() =>
  1214. {
  1215. while (APP.FFmpeg.myProcess != null)
  1216. {
  1217. Thread.Sleep(100);
  1218. }
  1219. }))).Start();
  1220. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  1221. //生成缩略图
  1222. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  1223. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1224. //缩略图存储位置
  1225. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  1226. new Thread(new ThreadStart(new Action(() =>
  1227. {
  1228. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  1229. {
  1230. Thread.Sleep(100);
  1231. }
  1232. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1233. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1234. VideoInfo.VideoPath = VideoSavePathName;
  1235. VideoInfo.ThumbnailPath = ThumbnailPathName;
  1236. Thread.Sleep(500);
  1237. VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  1238. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  1239. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  1240. VideoInfo.IsUpload = false;
  1241. VideoInfo.Uploaded = 0;
  1242. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  1243. APP.VideoList.Add(VideoInfo);
  1244. //保存数据
  1245. APP.SaveWkData();
  1246. IsFirstR = true;
  1247. }))).Start();
  1248. //List<Model_Video> VideoList
  1249. }
  1250. catch (Exception ex)
  1251. {
  1252. System.Windows.MessageBox.Show(ex.Message);
  1253. }
  1254. }
  1255. }
  1256. #endregion
  1257. /// <summary>
  1258. /// 增加事件
  1259. /// </summary>
  1260. /// <param name="sender"></param>
  1261. /// <param name="e"></param>
  1262. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  1263. {
  1264. if (APP.IsLoginType == false)
  1265. {
  1266. Login();
  1267. return;
  1268. }
  1269. if (APP.pageData.pagenum < 200)
  1270. {
  1271. if (APP.PageDrawList != null && APP.PageDrawList.Count > 0 && APP.PageDrawList.Count > APP.pageData.currpage - 1
  1272. && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1273. {
  1274. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1275. }
  1276. APP.pageData.pagenum += 1;
  1277. APP.pageData.currpage = APP.pageData.pagenum;
  1278. myblackboard.changepage(APP.pageData.currpage - 1);
  1279. imgCanvas.Source = null;
  1280. Model_DrawData model_DrawData = new Model_DrawData();
  1281. model_DrawData.PageNum = APP.pageData.currpage;
  1282. APP.PageDrawList.Add(model_DrawData);
  1283. APP.SaveDraw();//画板模型增加一页
  1284. }
  1285. else
  1286. {
  1287. System.Windows.Forms.MessageBox.Show("已达到最大页数无法继续增加!");
  1288. }
  1289. }
  1290. /// <summary>
  1291. /// 打印事件
  1292. /// </summary>
  1293. /// <param name="sender"></param>
  1294. /// <param name="e"></param>
  1295. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  1296. {
  1297. if (APP.IsLoginType == false)
  1298. {
  1299. Login();
  1300. return;
  1301. }
  1302. //for(int i=0;i< APP.pageData.pagenum; i++)
  1303. //{
  1304. //}
  1305. ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
  1306. try
  1307. {
  1308. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  1309. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  1310. ////设置纸张横向
  1311. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  1312. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  1313. FileToolsCommon.CreateFile(imgPath);
  1314. imgPath += "\\101.pdf";
  1315. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  1316. document.Open();
  1317. iTextSharp.text.Image image;
  1318. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1319. {
  1320. if (String.IsNullOrEmpty(APP.PageDrawList[i].PdfImagePath)) break;
  1321. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PdfImagePath);
  1322. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  1323. {
  1324. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1325. }
  1326. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  1327. {
  1328. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1329. }
  1330. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  1331. document.NewPage();
  1332. document.Add(image);
  1333. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  1334. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  1335. //p1.Leading = 150; //行间距
  1336. //document.Add(p1);
  1337. }
  1338. Console.WriteLine("转换成功!");
  1339. document.Close();
  1340. }
  1341. catch (Exception ex)
  1342. {
  1343. Console.WriteLine("转换失败,原因:" + ex.Message);
  1344. }
  1345. //document.Close();
  1346. ////Console.ReadKey();
  1347. if (APP.W_PrintWindow == null)
  1348. {
  1349. APP.W_PrintWindow = new PrintWindow();
  1350. APP.W_PrintWindow.Topmost = true;
  1351. APP.W_PrintWindow.Owner = this;
  1352. }
  1353. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PdfImagePath))
  1354. {
  1355. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PdfImagePath);
  1356. }
  1357. else
  1358. {
  1359. APP.W_PrintWindow.Initialize("");
  1360. }
  1361. APP.W_PrintWindow.Show();
  1362. //int pr = 1;
  1363. //string msg = string.Empty;
  1364. //string outPut = string.Empty;
  1365. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1366. //if(pr==0)
  1367. //{
  1368. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1369. // APP.OutPut = outPut.Split(',');
  1370. // string defa = string.Empty;
  1371. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1372. // int printResult = 1;
  1373. // string standardError = string.Empty;
  1374. // string standardOutput = string.Empty;
  1375. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1376. //}
  1377. }
  1378. /// <summary>
  1379. /// 我的
  1380. /// </summary>
  1381. /// <param name="sender"></param>
  1382. /// <param name="e"></param>
  1383. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  1384. {
  1385. if (APP.IsLoginType == false)
  1386. {
  1387. Login();
  1388. return;
  1389. }
  1390. }
  1391. /// <summary>
  1392. /// 上一页
  1393. /// </summary>
  1394. /// <param name="sender"></param>
  1395. /// <param name="e"></param>
  1396. private void last_button_Click(object sender, RoutedEventArgs e)
  1397. {
  1398. if (APP.pageData.currpage > 1)
  1399. {
  1400. try
  1401. {
  1402. Dispatcher.Invoke(() =>
  1403. {
  1404. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1405. FileToolsCommon.CreateDirectory(filePath);
  1406. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1407. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1408. //ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1409. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = filePathName;
  1410. });
  1411. }
  1412. catch (Exception ex)
  1413. {
  1414. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
  1415. }
  1416. APP.pageData.currpage -= 1;
  1417. myblackboard.changepage(APP.pageData.currpage - 1);
  1418. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1419. {
  1420. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1421. {
  1422. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1423. }
  1424. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1425. {
  1426. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1427. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1428. {
  1429. imgCanvas.Source = null;
  1430. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1431. }
  1432. else
  1433. {
  1434. imgDocumentation.Source = null;
  1435. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1436. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1437. {
  1438. var group = IMG.FindResource("Imageview") as TransformGroup;
  1439. var transform = group.Children[1] as TranslateTransform;
  1440. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1441. //{
  1442. // var transform1 = group.Children[0] as ScaleTransform;
  1443. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1444. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1445. //}
  1446. //var position = e.GetPosition(img);
  1447. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1448. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1449. mouseDown = false;
  1450. }
  1451. }
  1452. }
  1453. else
  1454. {
  1455. imgCanvas.Source = null;
  1456. imgDocumentation.Source = null;
  1457. }
  1458. }
  1459. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1460. //{
  1461. // imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1462. //}
  1463. }
  1464. }
  1465. /// <summary>
  1466. /// 下一页
  1467. /// </summary>
  1468. /// <param name="sender"></param>
  1469. /// <param name="e"></param>
  1470. private void next_btn_Click(object sender, RoutedEventArgs e)
  1471. {
  1472. if (APP.pageData.currpage < APP.pageData.pagenum)
  1473. {
  1474. try
  1475. {
  1476. Dispatcher.Invoke(() =>
  1477. {
  1478. string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
  1479. FileToolsCommon.CreateDirectory(filePath);
  1480. string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
  1481. ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  1482. //ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
  1483. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = filePathName;
  1484. });
  1485. }
  1486. catch (Exception ex)
  1487. {
  1488. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
  1489. }
  1490. APP.pageData.currpage += 1;
  1491. myblackboard.changepage(APP.pageData.currpage - 1);
  1492. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1493. {
  1494. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1495. {
  1496. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1497. }
  1498. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1499. {
  1500. if(APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1501. {
  1502. imgCanvas.Source = null;
  1503. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1504. }
  1505. else
  1506. {
  1507. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1508. imgDocumentation.Source = null;
  1509. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1510. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1511. {
  1512. var group = IMG.FindResource("Imageview") as TransformGroup;
  1513. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1514. //{
  1515. // var transform1 = group.Children[0] as ScaleTransform;
  1516. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1517. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1518. //}
  1519. var transform = group.Children[1] as TranslateTransform;
  1520. //var position = e.GetPosition(img);
  1521. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1522. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1523. mouseDown = false;
  1524. }
  1525. }
  1526. }
  1527. else
  1528. {
  1529. imgCanvas.Source = null;
  1530. imgDocumentation.Source = null;
  1531. }
  1532. }
  1533. //if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  1534. //{
  1535. // imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  1536. //}
  1537. }
  1538. }
  1539. /// <summary>
  1540. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1541. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1542. /// </summary>
  1543. /// <param name="pdfInputPath">Word文件路径</param>
  1544. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1545. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1546. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1547. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1548. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1549. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1550. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1551. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1552. {
  1553. // 返回的图片绝对路径集合
  1554. List<string> images = new List<string>();
  1555. try
  1556. {
  1557. // open word file
  1558. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1559. // validate parameter
  1560. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1561. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1562. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1563. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1564. if (startPageNum <= 0) { startPageNum = 1; }
  1565. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1566. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1567. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1568. if (resolution <= 0) { resolution = 128; }
  1569. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1570. {
  1571. Resolution = resolution
  1572. };
  1573. // start to convert each page
  1574. for (int i = startPageNum; i <= endPageNum; i++)
  1575. {
  1576. imageSaveOptions.PageIndex = i - 1;
  1577. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1578. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1579. APP.num++;
  1580. }
  1581. imageSaveOptions = null;
  1582. doc = null;
  1583. }
  1584. catch (Exception ex)
  1585. {
  1586. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1587. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1588. }
  1589. return images;
  1590. }
  1591. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1592. {
  1593. SaveFormat sf;// = SaveFormat.Unknown;
  1594. if (imageFormat.Equals(ImageFormat.Png))
  1595. {
  1596. sf = SaveFormat.Png;
  1597. }
  1598. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1599. {
  1600. sf = SaveFormat.Jpeg;
  1601. }
  1602. else if (imageFormat.Equals(ImageFormat.Tiff))
  1603. {
  1604. sf = SaveFormat.Tiff;
  1605. }
  1606. else if (imageFormat.Equals(ImageFormat.Bmp))
  1607. {
  1608. sf = SaveFormat.Bmp;
  1609. }
  1610. else
  1611. {
  1612. sf = SaveFormat.Unknown;
  1613. }
  1614. return sf;
  1615. }
  1616. #region 图像缩放,移动
  1617. private bool mouseDown;
  1618. private System.Windows.Point mouseXY;
  1619. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1620. {
  1621. var img = sender as ContentControl;
  1622. if (img == null)
  1623. {
  1624. return;
  1625. }
  1626. img.CaptureMouse();
  1627. mouseDown = true;
  1628. mouseXY = e.GetPosition(img);
  1629. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1630. }
  1631. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1632. {
  1633. System.Windows.Point point = e.GetPosition(imgCanvas);
  1634. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1635. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1636. //{
  1637. // Console.WriteLine("在范围内");
  1638. //}
  1639. }
  1640. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1641. {
  1642. var img = sender as ContentControl;
  1643. if (img == null)
  1644. {
  1645. return;
  1646. }
  1647. img.ReleaseMouseCapture();
  1648. mouseDown = false;
  1649. }
  1650. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1651. {
  1652. var img = sender as ContentControl;
  1653. if (img == null)
  1654. {
  1655. return;
  1656. }
  1657. if (mouseDown)
  1658. {
  1659. Domousemove(img, e);
  1660. }
  1661. }
  1662. /// <summary>
  1663. /// x y轴
  1664. /// </summary>
  1665. /// <param name="img"></param>
  1666. /// <param name="e"></param>
  1667. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1668. {
  1669. if (e.LeftButton != MouseButtonState.Pressed)
  1670. {
  1671. return;
  1672. }
  1673. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  1674. {
  1675. return;
  1676. }
  1677. var group = IMG.FindResource("Imageview") as TransformGroup;
  1678. var transform = group.Children[1] as TranslateTransform;
  1679. var position = e.GetPosition(img);
  1680. transform.X -= mouseXY.X - position.X;
  1681. transform.Y -= mouseXY.Y - position.Y;
  1682. mouseXY = position;
  1683. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1684. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform.X;
  1685. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform.Y;
  1686. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1687. }
  1688. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1689. {
  1690. var img = sender as ContentControl;
  1691. if (img == null)
  1692. {
  1693. return;
  1694. }
  1695. var point = e.GetPosition(img);
  1696. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1697. var PicLocate = e.GetPosition(imgCanvas);
  1698. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1699. var group = IMG.FindResource("Imageview") as TransformGroup;
  1700. var delta = e.Delta * 0.001;
  1701. DowheelZoom(group, point, delta);
  1702. }
  1703. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1704. {
  1705. var pointToContent = group.Inverse.Transform(point);
  1706. var transform = group.Children[0] as ScaleTransform;
  1707. if (transform.ScaleX + delta < 0.1) return;
  1708. transform.ScaleX += delta;
  1709. transform.ScaleY += delta;
  1710. var transform1 = group.Children[1] as TranslateTransform;
  1711. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1712. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1713. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1714. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  1715. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  1716. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  1717. //APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1718. //APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform1.X;
  1719. //APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform1.Y;
  1720. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1721. }
  1722. #endregion
  1723. #region 点阵笔相关
  1724. #region 值初始化
  1725. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  1726. /// <summary>
  1727. /// A4点阵纸点阵宽度
  1728. /// </summary>
  1729. private const int A4_WIDTH = 5600;
  1730. /// <summary>
  1731. /// A4点阵纸点阵高度
  1732. /// </summary>
  1733. private const int A4_HEIGHT = 7920;
  1734. /// <summary>
  1735. /// 画板
  1736. /// </summary>
  1737. private Graphics graphics;
  1738. /// <summary>
  1739. /// 笔画坐标数组
  1740. /// </summary>
  1741. private List<System.Drawing.Point> stroke;
  1742. /// <summary>
  1743. /// 笔序列号
  1744. /// </summary>
  1745. private string penSerial;
  1746. /// <summary>
  1747. /// 笔是否在点
  1748. /// </summary>
  1749. private bool isPenDown;
  1750. //当前点阵地址
  1751. private string currentPageSerial = string.Empty;
  1752. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  1753. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  1754. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  1755. #endregion
  1756. public void InitPen()
  1757. {
  1758. stroke = new List<System.Drawing.Point>();
  1759. //获取点阵笔实例,并绑定点阵笔事件
  1760. //将授权文件内容传入,获取点阵笔对象实例
  1761. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  1762. //绑定笔连接事件
  1763. APP.digitalPen.PenConnected += OnPenConnect;
  1764. //绑定笔断开事件
  1765. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  1766. //绑定笔书写输出坐标事件
  1767. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  1768. //绑定抬笔事件
  1769. APP.digitalPen.PenUp += OnPenUp;
  1770. //绑定落笔事件
  1771. APP.digitalPen.PenDown += OnPenDown;
  1772. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  1773. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  1774. //完成初始化点阵笔,开始与点阵笔通信
  1775. ERROR_CODE ER = APP.digitalPen.Start();
  1776. ////绑定笔在新的点阵地址页面书写事件
  1777. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  1778. ////绑定笔信息事件
  1779. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  1780. //启动接收笔数据,完成初始化工作
  1781. ERROR_CODE rc = APP.digitalPen.Start();
  1782. //判断是否成功
  1783. if (ER != ERROR_CODE.ERROR_OK)
  1784. {
  1785. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  1786. }
  1787. }
  1788. /// <summary>
  1789. /// 落笔
  1790. /// </summary>
  1791. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1792. /// <param name="penSerial">点阵笔序列号</param>
  1793. /// <param name="penType">点阵笔型号编号</param>
  1794. private void OnPenDown(ulong time, string penSerial, int penType)
  1795. {
  1796. if (this.CheckAccess())
  1797. {
  1798. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  1799. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1800. }
  1801. else
  1802. {
  1803. //labPenSerial.Text = penSerial;
  1804. //labPenStatus.Text = "PenDown";
  1805. isPenDown = true;
  1806. Dispatcher.Invoke(new Action(() =>
  1807. {
  1808. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1809. {
  1810. if (APP.PageDrawList[i].PageCode == penSerial)
  1811. {
  1812. if (i < APP.pageData.pagenum)
  1813. {
  1814. if (i < APP.pageData.currpage)
  1815. {
  1816. int num = APP.pageData.currpage - i;
  1817. APP.pageData.currpage -= num;
  1818. myblackboard.changepage(APP.pageData.currpage - 1);
  1819. if (APP.PageDrawList.Count > 0)
  1820. {
  1821. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1822. {
  1823. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1824. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1825. }
  1826. else
  1827. {
  1828. imgCanvas.Source = null;
  1829. }
  1830. }
  1831. }
  1832. else
  1833. {
  1834. int num = i - APP.pageData.currpage;
  1835. APP.pageData.currpage += num;
  1836. myblackboard.changepage(APP.pageData.currpage - 1);
  1837. if (APP.PageDrawList.Count > 0)
  1838. {
  1839. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1840. {
  1841. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  1842. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1843. }
  1844. else
  1845. {
  1846. imgCanvas.Source = null;
  1847. }
  1848. }
  1849. }
  1850. }
  1851. return;
  1852. }
  1853. }
  1854. //myblackboard.changepages(0, 0, true);
  1855. //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  1856. }));
  1857. }
  1858. //myblackboard.changepages(0, 0, true);
  1859. }
  1860. /// <summary>
  1861. /// 抬笔
  1862. /// </summary>
  1863. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1864. /// <param name="penSerial">点阵笔序列号</param>
  1865. /// <param name="penType">点阵笔型号编号</param>
  1866. private void OnPenUp(ulong time, string penSerial, int penType)
  1867. {
  1868. if (this.CheckAccess())
  1869. {
  1870. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  1871. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1872. }
  1873. else
  1874. {
  1875. isPenDown = false;
  1876. APP.PenSerial = penSerial;
  1877. //int leftPoints = stroke.Count % 3;
  1878. //if (0 != leftPoints)
  1879. //{
  1880. // int from = stroke.Count - leftPoints - 1;
  1881. // if (from < 0)
  1882. // from = 0;
  1883. // int to = stroke.Count - 1;
  1884. // DrawCoordinates(from, to);
  1885. //}
  1886. stroke.Clear();
  1887. }
  1888. Dispatcher.Invoke(new Action(() =>
  1889. {
  1890. //myblackboard.changepages(0, 0, true);
  1891. myblackboard.changepages(0, 0, true, Color, Size);
  1892. }));
  1893. }
  1894. /// <summary>
  1895. /// 笔断开
  1896. /// </summary>
  1897. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1898. /// <param name="penSerial">点阵笔序列号</param>
  1899. /// <param name="penType">点阵笔型号编号</param>
  1900. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  1901. {
  1902. if (this.CheckAccess())
  1903. {
  1904. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  1905. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1906. }
  1907. else
  1908. {
  1909. APP.PenSerial = penSerial;
  1910. APP.PenStatus = false;
  1911. Dispatcher.Invoke(new Action(() =>
  1912. {
  1913. txbNotConnected.Text = "未连接";
  1914. txbNotConnecteds.Text = "未连接";
  1915. }));
  1916. }
  1917. }
  1918. /// <summary>
  1919. /// 笔连接
  1920. /// </summary>
  1921. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1922. /// <param name="penSerial">点阵笔序列号</param>
  1923. /// <param name="penType">点阵笔型号编号</param>
  1924. private void OnPenConnect(ulong time, string penSerial, int penType)
  1925. {
  1926. if (this.CheckAccess())
  1927. {
  1928. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  1929. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  1930. }
  1931. else
  1932. {
  1933. APP.PenSerial = penSerial;
  1934. APP.PenStatus = true;
  1935. this.penSerial = penSerial;
  1936. //连接后,在获取笔数据前,可以清除笔内的历史数据
  1937. //APP.digitalPen.ClearMemory(penSerial);
  1938. //开始接收笔数据
  1939. APP.digitalPen.GetPenData(penSerial);
  1940. Dispatcher.Invoke(new Action(() =>
  1941. {
  1942. txbNotConnected.Text = "已连接";
  1943. txbNotConnecteds.Text = "已连接";
  1944. }));
  1945. }
  1946. }
  1947. /// <summary>
  1948. /// 电池电量
  1949. /// </summary>
  1950. /// <param name="time"></param>
  1951. /// <param name="penSerial"></param>
  1952. /// <param name="penType"></param>
  1953. /// <param name="capacity"></param>
  1954. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  1955. {
  1956. if (this.CheckAccess())
  1957. {
  1958. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  1959. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  1960. }
  1961. else
  1962. {
  1963. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  1964. }
  1965. }
  1966. /// <summary>
  1967. /// 已用存储
  1968. /// </summary>
  1969. /// <param name="time"></param>
  1970. /// <param name="penSerial"></param>
  1971. /// <param name="penType"></param>
  1972. /// <param name="fillLevel"></param>
  1973. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  1974. {
  1975. if (this.CheckAccess())
  1976. {
  1977. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  1978. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  1979. }
  1980. else
  1981. {
  1982. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  1983. }
  1984. }
  1985. /// <summary>
  1986. /// 笔书写,收到坐标
  1987. /// </summary>
  1988. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  1989. /// <param name="penSerial">点阵笔序列号</param>
  1990. /// <param name="penType">点阵笔型号编号</param>
  1991. /// <param name="pageSerial">点阵地址</param>
  1992. /// <param name="cx">x坐标</param>
  1993. /// <param name="cy">y坐标</param>
  1994. /// <param name="force">压力值</param>
  1995. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  1996. {
  1997. if (this.CheckAccess())
  1998. {
  1999. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  2000. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  2001. }
  2002. else
  2003. {
  2004. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  2005. if (!isPenDown)
  2006. {
  2007. return;
  2008. }
  2009. stroke.Add(new System.Drawing.Point(cx, cy));
  2010. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  2011. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  2012. //点
  2013. double testX = (double)cx * PropW;
  2014. double testY = (double)cy * PropH;
  2015. //pageSerial //点阵IP地址 与打印的页面关联
  2016. Dispatcher.Invoke(new Action(() =>
  2017. {
  2018. //myblackboard.changepages(testX, testY,false);
  2019. myblackboard.changepages(testX, testY, false, Color, Size);
  2020. }));
  2021. ////每3个点画一条曲线
  2022. //if (stroke.Count % 3 == 0)
  2023. //{
  2024. // int from = stroke.Count - 3 - 1;
  2025. // if (from < 0)
  2026. // from = 0;
  2027. // int to = stroke.Count - 1;
  2028. // DrawCoordinates(from, to);
  2029. //}
  2030. }
  2031. }
  2032. /// <summary>
  2033. /// 停止笔
  2034. /// </summary>
  2035. public void StopDigitalPen()
  2036. {
  2037. //停止,释放资源
  2038. APP.digitalPen.Stop();
  2039. }
  2040. /// <summary>
  2041. /// 清空笔内存储
  2042. /// </summary>
  2043. public void ClearPenStorage()
  2044. {
  2045. if (!string.IsNullOrEmpty(penSerial))
  2046. APP.digitalPen.ClearMemory(penSerial);
  2047. }
  2048. /// <summary>
  2049. /// 获取剩余电量
  2050. /// </summary>
  2051. public void GetPenElectricityQuantity()
  2052. {
  2053. if (!string.IsNullOrEmpty(penSerial))
  2054. APP.digitalPen.GetBatteryCapacity(penSerial);
  2055. }
  2056. /// <summary>
  2057. /// 获取存储空间
  2058. /// </summary>
  2059. public void GetUsedStorage()
  2060. {
  2061. if (!string.IsNullOrEmpty(penSerial))
  2062. APP.digitalPen.GetMemoryFillLevel(penSerial);
  2063. }
  2064. /// <summary>
  2065. /// 开启悬浮
  2066. /// </summary>
  2067. public void 开启悬浮()
  2068. {
  2069. if (!string.IsNullOrEmpty(penSerial))
  2070. APP.digitalPen.SetPenHoverMode(true, penSerial);
  2071. }
  2072. /// <summary>
  2073. /// 关闭悬浮
  2074. /// </summary>
  2075. public void 关闭悬浮()
  2076. {
  2077. if (!string.IsNullOrEmpty(penSerial))
  2078. APP.digitalPen.SetPenHoverMode(false, penSerial);
  2079. }
  2080. #endregion
  2081. /// <summary>
  2082. /// 最小化
  2083. /// </summary>
  2084. /// <param name="sender"></param>
  2085. /// <param name="e"></param>
  2086. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  2087. {
  2088. if (Visibility == Visibility.Hidden)
  2089. Visibility = Visibility.Visible;
  2090. else
  2091. Visibility = Visibility.Hidden;
  2092. }
  2093. /// <summary>
  2094. /// 位置确定
  2095. /// </summary>
  2096. /// <param name="sender"></param>
  2097. /// <param name="e"></param>
  2098. private void BtnOk_Click(object sender, RoutedEventArgs e)
  2099. {
  2100. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2101. //btnOk.Visibility = Visibility.Collapsed;
  2102. //blackboard_canvas.Visibility = Visibility.Visible;
  2103. }
  2104. }
  2105. }