星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

XHMicroLessonSystemWindow.xaml.cs 94KB

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