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

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