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

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