星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

XHMicroLessonSystemWindow.xaml.cs 108KB

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