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

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