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

XHMicroLessonSystemWindow.xaml.cs 113KB

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