星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XHMicroLessonSystemWindow.xaml.cs 113KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638
  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. string time = GetTimeStamp();
  778. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  779. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath,false,out BitmapImage bitmap);
  780. if (this.WindowState == WindowState.Normal)//截图隐藏窗口
  781. {
  782. this.WindowState = WindowState.Minimized;
  783. }
  784. if (APP.W_JieTuWindow != null)
  785. {
  786. APP.W_JieTuWindow.initialization();
  787. APP.W_JieTuWindow.Screenshot();
  788. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  789. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  790. }
  791. else
  792. {
  793. APP.W_JieTuWindow = new JieTuWindow();
  794. // 订阅事件
  795. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  796. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  797. APP.W_JieTuWindow.Show();
  798. }
  799. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  800. }
  801. /// <summary>
  802. /// 截图关闭窗口
  803. /// </summary>
  804. /// <param name="text"></param>
  805. private void frm_ChangeTextEvent(string text)
  806. {
  807. if ("关闭窗口".Equals(text))
  808. {
  809. if (this.WindowState == WindowState.Minimized)//截图完恢复窗口
  810. {
  811. this.WindowState = WindowState.Normal;
  812. }
  813. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  814. {
  815. if (APP.pageData.currpage == 0)
  816. {
  817. APP.pageData.pagenum += 1;
  818. APP.pageData.currpage = APP.pageData.pagenum;
  819. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  820. }
  821. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  822. {
  823. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  824. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  825. }
  826. else
  827. {
  828. Model_DrawData model_DrawData = new Model_DrawData();
  829. model_DrawData.PageImagePath = APP.ImgPath;
  830. model_DrawData.PdfImagePath = APP.ImgPath;
  831. APP.PageDrawList.Add(model_DrawData);
  832. }
  833. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  834. {
  835. imgDocumentation.Source = null;
  836. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  837. APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
  838. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  839. ImgPrintTwo.Visibility = Visibility.Collapsed;
  840. btnPrint.IsEnabled = true;
  841. }
  842. }
  843. }
  844. }
  845. /// <summary>
  846. /// 截图关闭 非正常关闭截图时,截图清空
  847. /// </summary>
  848. private void JietuWindow_click_closeJietuWindowClick()
  849. {
  850. if (this.WindowState == WindowState.Minimized)//截图完恢复窗口
  851. {
  852. this.WindowState = WindowState.Normal;
  853. }
  854. APP.W_JieTuWindow = null;
  855. }
  856. /// <summary>
  857. /// 获取时间戳
  858. /// </summary>
  859. /// <returns></returns>
  860. public string GetTimeStamp()
  861. {
  862. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  863. return Convert.ToInt64(ts.TotalSeconds).ToString();
  864. }
  865. /// <summary>
  866. /// 导入事件
  867. /// </summary>
  868. /// <param name="sender"></param>
  869. /// <param name="e"></param>
  870. private void BtnImport_Click(object sender, RoutedEventArgs e)
  871. {
  872. try
  873. {
  874. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  875. ofd = new System.Windows.Forms.OpenFileDialog
  876. {
  877. Filter = "文档|*.docx;*.doc;*ppt",
  878. InitialDirectory = desktopPath,
  879. Multiselect = false,
  880. AddExtension = true,
  881. DereferenceLinks = true
  882. };
  883. new Thread(
  884. o =>
  885. {
  886. Thread.Sleep(400);
  887. Dispatcher.Invoke(new Action(() =>
  888. {
  889. OpenDialog();
  890. }
  891. ));
  892. })
  893. {
  894. IsBackground = true
  895. }.Start();
  896. }
  897. catch (Exception ex)
  898. {
  899. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  900. }
  901. }
  902. /// <summary>
  903. /// 导入文档
  904. /// </summary>
  905. private void OpenDialog()
  906. {
  907. result = ofd.ShowDialog();
  908. if (result == System.Windows.Forms.DialogResult.OK)
  909. {
  910. if (ofd.FileName != "")
  911. {
  912. APP.myloading.Show();
  913. #region PPT转PDF
  914. string filepath = ofd.FileName;
  915. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  916. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
  917. if (type.Contains("typezsygppt"))//ppt
  918. {
  919. try
  920. {
  921. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  922. path = pathTemp + path + ".pdf";
  923. //PPT转PDF
  924. Presentation ppt = new Presentation(filepath);
  925. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  926. #endregion
  927. #region PDF转图片
  928. // 图片绝对路径集合
  929. List<string> images = new List<string>();
  930. string directoryPath = pathTemp;
  931. //aspose许可证
  932. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  933. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  934. //l.SetLicense(licenseName);
  935. //定义Jpeg转换设备
  936. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  937. var device = new Aspose.Pdf.Devices.JpegDevice();
  938. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  939. //directoryPath += quality;
  940. Directory.CreateDirectory(directoryPath);
  941. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  942. device = new Aspose.Pdf.Devices.JpegDevice(100);
  943. //遍历每一页转为jpg
  944. for (var i = 1; i <= document.Pages.Count; i++)
  945. {
  946. long ii = Timestamp();
  947. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  948. images.Add(filePathOutPut);
  949. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  950. try
  951. {
  952. device.Process(document.Pages[i], fs);
  953. fs.Close();
  954. }
  955. catch (Exception ex)
  956. {
  957. fs.Close();
  958. File.Delete(filePathOutPut);
  959. }
  960. }
  961. #endregion
  962. string[] page = images.ToArray();
  963. int num = 0;
  964. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  965. {
  966. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  967. {
  968. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  969. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  970. APP.PageDrawList[i].PageNum = i + 1;
  971. APP.PageDrawList[i].ImgDocumentation = true;
  972. }
  973. else
  974. {
  975. Model_DrawData model_DrawData = new Model_DrawData();
  976. model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
  977. model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
  978. model_DrawData.PageNum = i + 1;
  979. model_DrawData.ImgDocumentation = true;
  980. APP.PageDrawList.Add(model_DrawData);
  981. }
  982. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  983. ImgPrintTwo.Visibility = Visibility.Collapsed;
  984. btnPrint.IsEnabled = true;
  985. APP.SaveDraw();
  986. num++;
  987. }
  988. if (num > 0)
  989. {
  990. APP.pageData.currpage = APP.pageData.pagenum + 1;
  991. APP.pageData.pagenum += num;
  992. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  993. }
  994. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  995. {
  996. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  997. imgCanvas.Source = null;
  998. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  999. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1000. btnScreenshot.IsEnabled = false;
  1001. }
  1002. else
  1003. {
  1004. imgDocumentation.Source = null;
  1005. imgCanvas.Source = null;
  1006. ///截图可用
  1007. ImgScreenshot.Visibility = Visibility.Visible;
  1008. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1009. btnScreenshot.IsEnabled = true;
  1010. }
  1011. APP.myloading.Hide();
  1012. }
  1013. catch (Exception ex)
  1014. {
  1015. APP.myloading.Hide();
  1016. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
  1017. }
  1018. }
  1019. else//word
  1020. {
  1021. try
  1022. {
  1023. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1024. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1025. int num = 0;
  1026. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1027. {
  1028. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1029. {
  1030. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1031. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1032. APP.PageDrawList[i].PageNum = i + 1;
  1033. APP.PageDrawList[i].ImgDocumentation = true;
  1034. }
  1035. else
  1036. {
  1037. Model_DrawData model_DrawData = new Model_DrawData();
  1038. model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
  1039. model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
  1040. model_DrawData.PageNum = i + 1;
  1041. model_DrawData.ImgDocumentation = true;
  1042. APP.PageDrawList.Add(model_DrawData);
  1043. }
  1044. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1045. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1046. btnPrint.IsEnabled = true;
  1047. APP.SaveDraw();
  1048. num++;
  1049. }
  1050. if (num > 0)
  1051. {
  1052. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1053. APP.pageData.pagenum += num;
  1054. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1055. }
  1056. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1057. {
  1058. imgCanvas.Source = null;
  1059. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1060. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1061. btnScreenshot.IsEnabled = false;
  1062. imgDocumentation.Visibility = Visibility.Visible;
  1063. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1064. }
  1065. else
  1066. {
  1067. imgDocumentation.Source = null;
  1068. imgCanvas.Source = null;
  1069. ///截图可用
  1070. ImgScreenshot.Visibility = Visibility.Visible;
  1071. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1072. btnScreenshot.IsEnabled = true;
  1073. }
  1074. APP.myloading.Hide();
  1075. }
  1076. catch (Exception ex)
  1077. {
  1078. APP.myloading.Hide();
  1079. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1080. }
  1081. }
  1082. }
  1083. }
  1084. }
  1085. /// <summary>
  1086. /// 返回一个时间戳到毫秒
  1087. /// </summary>
  1088. /// <returns></returns>
  1089. public static long Timestamp()
  1090. {
  1091. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1092. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1093. return timestr;
  1094. }
  1095. #region 录制窗口
  1096. #region 变量
  1097. /// <summary>
  1098. /// 视频保存路径
  1099. /// </summary>
  1100. //string RecordingPath;
  1101. /// <summary>
  1102. /// 图片保存路径
  1103. /// </summary>
  1104. string ImgPath;
  1105. /// <summary>
  1106. /// 音频保存路径名
  1107. /// </summary>
  1108. string AudioPathName;
  1109. /// <summary>
  1110. /// 视频保存路径名
  1111. /// </summary>
  1112. string VideoSavePathName;
  1113. /// <summary>
  1114. /// 暂停录制
  1115. /// </summary>
  1116. bool IsSuspendR = true;
  1117. /// <summary>
  1118. /// 录制是否已停止
  1119. /// </summary>
  1120. bool IsFirstR = true;
  1121. /// <summary>
  1122. /// 图片
  1123. /// </summary>
  1124. List<string> RsImgName = null;
  1125. /// <summary>
  1126. /// 是否开始截图计数
  1127. /// </summary>
  1128. bool IsStartCount = false;
  1129. #endregion
  1130. /// <summary>
  1131. /// 录制窗口内容
  1132. /// </summary>
  1133. /// <param name="sender"></param>
  1134. /// <param name="e"></param>
  1135. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  1136. {
  1137. if (APP.pageData.currpage > 0)
  1138. {
  1139. blackboard_canvas.Visibility = Visibility.Visible;
  1140. }
  1141. else
  1142. {
  1143. System.Windows.MessageBox.Show("请先导入文档或截图!");
  1144. return;
  1145. }
  1146. //btnStop.IsEnabled = true;//停止录制按钮可点击
  1147. StartRecord();
  1148. }
  1149. /// <summary>
  1150. /// 停止录制窗口内容
  1151. /// </summary>
  1152. /// <param name="sender"></param>
  1153. /// <param name="e"></param>
  1154. private void BtnStop_Click(object sender, RoutedEventArgs e)
  1155. {
  1156. blackboard_canvas.Visibility = Visibility.Collapsed;
  1157. EndRecord();
  1158. }
  1159. System.Timers.Timer timer;
  1160. /// <summary>
  1161. /// 设置录屏文件地址
  1162. /// </summary>
  1163. void SetUpVideoPathName()
  1164. {
  1165. }
  1166. /// <summary>
  1167. /// 开始录制和暂停录制
  1168. /// </summary>
  1169. void StartRecord()
  1170. {
  1171. if (IsSuspendR)
  1172. {
  1173. if (IsFirstR)//是否第一次录制 初始化录制
  1174. {
  1175. #region 计时器初始化
  1176. if (t == null)
  1177. {
  1178. t = new DispatcherTimer();
  1179. t.Tick += OnTimer;
  1180. t.Interval = new TimeSpan(0, 0, 0, 1);
  1181. t.IsEnabled = true;
  1182. t.Start();
  1183. }
  1184. t.Interval = new TimeSpan(0, 0, 0, 1);
  1185. txbTime.Visibility = Visibility.Visible;
  1186. Stack();
  1187. #endregion
  1188. VideoInfo = new Model_Video();
  1189. VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
  1190. VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
  1191. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1192. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1193. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1194. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  1195. FileToolsCommon.CreateDirectory(ImgPath);
  1196. FileToolsCommon.CreateDirectory(AudioPathName);
  1197. AudioPathName += APP.WKData.WkName + ".MP3";
  1198. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1199. int num = 1;
  1200. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  1201. {
  1202. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  1203. num++;
  1204. }
  1205. #region 设置录屏唯一 废弃
  1206. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1207. //{
  1208. // MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1209. // if (dr == MessageBoxResult.OK)
  1210. // {
  1211. // try
  1212. // {
  1213. // FileToolsCommon.DeleteFile(VideoSavePathName);
  1214. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1215. // }
  1216. // catch (Exception ex)
  1217. // {
  1218. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1219. // }
  1220. // }
  1221. // else
  1222. // {
  1223. // return;
  1224. // }
  1225. //}
  1226. #endregion
  1227. #region 禁用按钮
  1228. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1229. ImgPrintTwo.Visibility = Visibility.Visible;
  1230. btnPrint.IsEnabled = false;
  1231. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1232. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1233. btnScreenshot.IsEnabled = false;
  1234. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1235. ImgImportTwo.Visibility = Visibility.Visible;
  1236. btnImport.IsEnabled = false;
  1237. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1238. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1239. btnScreenRecording.IsEnabled = false;
  1240. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1241. ImgUploadTwo.Visibility = Visibility.Visible;
  1242. btnUpload.IsEnabled = false;
  1243. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1244. ImgSetUpTwo.Visibility = Visibility.Visible;
  1245. btnSetUp.IsEnabled = false;
  1246. btnLoginType.IsEnabled = false;
  1247. #endregion
  1248. #region 录像倒计时
  1249. if (APP.W_CountdownWindow == null)
  1250. {
  1251. APP.W_CountdownWindow = new CountdownWindow();
  1252. //APP.W_CountdownWindow.Topmost = true;
  1253. }
  1254. else
  1255. {
  1256. APP.W_CountdownWindow.Initialize();
  1257. //APP.W_CountdownWindow.Topmost = true;
  1258. }
  1259. APP.W_CountdownWindow.Show();
  1260. #endregion
  1261. IsFirstR = false;
  1262. RsImgName = new List<string>();
  1263. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  1264. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  1265. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1266. timer.Enabled = true; //启动计时器
  1267. }
  1268. //继续录制
  1269. IsSuspendR = false;
  1270. //BtnRecording.Content = "暂停录制";
  1271. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1272. ImgStop.Visibility = Visibility.Collapsed;
  1273. ImgStopTwo.Visibility = Visibility.Visible;
  1274. TxbRecordingWord.Text = "暂停";
  1275. Stack();
  1276. #region 2秒内不可点击
  1277. new Thread(new ThreadStart(new Action(() =>
  1278. {
  1279. Dispatcher.Invoke(() =>
  1280. {
  1281. BtnRecord.IsEnabled = false;
  1282. btnStop.IsEnabled = false;
  1283. });
  1284. Thread.Sleep(2000);
  1285. Dispatcher.Invoke(() =>
  1286. {
  1287. BtnRecord.IsEnabled = true;
  1288. btnStop.IsEnabled = true;
  1289. });
  1290. }))).Start();
  1291. #endregion
  1292. try
  1293. {
  1294. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1295. new Thread(new ThreadStart(new Action(() =>
  1296. {
  1297. Thread.Sleep(1000);
  1298. Dispatcher.Invoke(() =>
  1299. {
  1300. IsStartCount = true;
  1301. //timer.Start();
  1302. });
  1303. }))).Start();
  1304. }
  1305. catch (Exception ex)
  1306. {
  1307. System.Windows.MessageBox.Show(ex.Message);
  1308. }
  1309. }
  1310. else
  1311. {
  1312. //暂停
  1313. IsSuspendR = true;
  1314. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1315. ImgStop.Visibility = Visibility.Visible;
  1316. ImgStopTwo.Visibility = Visibility.Collapsed;
  1317. TxbRecordingWord.Text = "继续";
  1318. TimeOut();
  1319. #region 2秒内不可点击
  1320. new Thread(new ThreadStart(new Action(() =>
  1321. {
  1322. Dispatcher.Invoke(() =>
  1323. {
  1324. BtnRecord.IsEnabled = false;
  1325. btnStop.IsEnabled = false;
  1326. });
  1327. Thread.Sleep(2000);
  1328. Dispatcher.Invoke(() =>
  1329. {
  1330. BtnRecord.IsEnabled = true;
  1331. btnStop.IsEnabled = true;
  1332. });
  1333. }))).Start();
  1334. #endregion
  1335. try
  1336. {
  1337. APP.FFmpeg.SuspendFFmpeg();
  1338. new Thread(new ThreadStart(new Action(() =>
  1339. {
  1340. while (APP.FFmpeg.myProcess != null)
  1341. {
  1342. Thread.Sleep(100);
  1343. }
  1344. IsStartCount = false;
  1345. }))).Start();
  1346. }
  1347. catch (Exception ex)
  1348. {
  1349. System.Windows.MessageBox.Show(ex.Message);
  1350. }
  1351. }
  1352. }
  1353. /// <summary>
  1354. /// 录制保存图片
  1355. /// </summary>
  1356. /// <param name="sender"></param>
  1357. /// <param name="e"></param>
  1358. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  1359. {
  1360. if (IsStartCount)
  1361. {
  1362. try
  1363. {
  1364. Dispatcher.Invoke(() =>
  1365. {
  1366. string FilePathName = ImgPath + RsImgName.Count + ".png";
  1367. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
  1368. RsImgName.Add(FilePathName);
  1369. });
  1370. }
  1371. catch (Exception ex)
  1372. {
  1373. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  1374. }
  1375. }
  1376. }
  1377. /// <summary>
  1378. /// 停止录制并生成录制文件
  1379. /// </summary>
  1380. void EndRecord()
  1381. {
  1382. if (!IsFirstR)
  1383. {
  1384. #region 恢复被禁用的按钮
  1385. ImgPrint.Visibility = Visibility.Visible;
  1386. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1387. btnPrint.IsEnabled = true;
  1388. ImgScreenshot.Visibility = Visibility.Visible;
  1389. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1390. btnScreenshot.IsEnabled = true;
  1391. ImgImport.Visibility = Visibility.Visible;
  1392. ImgImportTwo.Visibility = Visibility.Collapsed;
  1393. btnImport.IsEnabled = true;
  1394. ImgScreenRecording.Visibility = Visibility.Visible;
  1395. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  1396. btnScreenRecording.IsEnabled = true;
  1397. ImgUpload.Visibility = Visibility.Visible;
  1398. ImgUploadTwo.Visibility = Visibility.Collapsed;
  1399. btnUpload.IsEnabled = true;
  1400. ImgSetUp.Visibility = Visibility.Visible;
  1401. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  1402. btnSetUp.IsEnabled = true;
  1403. btnLoginType.IsEnabled = true;
  1404. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  1405. #endregion
  1406. IsSuspendR = true;
  1407. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1408. ImgStop.Visibility = Visibility.Visible;
  1409. ImgStopTwo.Visibility = Visibility.Collapsed;
  1410. TimeOut();
  1411. txbType.Text = "保存中";
  1412. #region 2秒内不可点击
  1413. new Thread(new ThreadStart(new Action(() =>
  1414. {
  1415. Dispatcher.Invoke(() =>
  1416. {
  1417. BtnRecord.IsEnabled = false;
  1418. btnStop.IsEnabled = false;
  1419. });
  1420. }))).Start();
  1421. #endregion
  1422. try
  1423. {
  1424. #region 清空画板数据
  1425. APP.pageData.currpage = 0;
  1426. APP.pageData.pagenum = 0;
  1427. myblackboard.clear();
  1428. APP.PageDrawList.Clear();
  1429. #endregion
  1430. //缩略图
  1431. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  1432. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1433. //缩略图存储位置
  1434. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  1435. int gridActWidth = (int)GridMain.ActualWidth;
  1436. int gridActHeight = (int)GridMain.ActualHeight;
  1437. APP.FFmpeg.StopFFmpeg(AudioPathName);
  1438. new Thread(new ThreadStart(new Action(() =>
  1439. {
  1440. //停止截图
  1441. while (APP.FFmpeg.myProcess != null)
  1442. {
  1443. Thread.Sleep(100);
  1444. }
  1445. Dispatcher.Invoke(() =>
  1446. {
  1447. IsStartCount = false;
  1448. timer.Stop();
  1449. });
  1450. //}))).Start();
  1451. //new Thread(new ThreadStart(new Action(() =>
  1452. //{
  1453. //判断音频是否存在 判断音频临时文件夹是否存在
  1454. if (!FileToolsCommon.IsExistFile(AudioPathName))
  1455. {
  1456. Thread.Sleep(100);
  1457. }
  1458. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  1459. {
  1460. Thread.Sleep(100);
  1461. }
  1462. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, gridActWidth, gridActHeight);
  1463. //}))).Start();
  1464. //new Thread(new ThreadStart(new Action(() =>
  1465. //{
  1466. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  1467. {
  1468. Thread.Sleep(100);
  1469. }
  1470. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSavePathName) + "temp/"))
  1471. {
  1472. Thread.Sleep(100);
  1473. }
  1474. Dispatcher.Invoke(() =>
  1475. {
  1476. BtnRecord.IsEnabled = true;
  1477. btnStop.IsEnabled = true;
  1478. TxbRecordingWord.Text = "录制";
  1479. End();
  1480. txbTime.Text = "";
  1481. txbTime.Visibility = Visibility.Hidden;
  1482. txbType.Text = "";
  1483. });
  1484. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1485. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  1486. Thread.Sleep(500);
  1487. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  1488. VideoInfo.VideoPath = VideoSavePathName;
  1489. VideoInfo.ThumbnailPath = ThumbnailPathName;
  1490. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  1491. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  1492. VideoInfo.IsUpload = false;
  1493. VideoInfo.Uploaded = 0;
  1494. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  1495. APP.VideoList.Add(VideoInfo);
  1496. //保存数据
  1497. APP.SaveWkData();
  1498. IsFirstR = true;
  1499. }))).Start();
  1500. //List<Model_Video> VideoList
  1501. }
  1502. catch (Exception ex)
  1503. {
  1504. System.Windows.MessageBox.Show(ex.Message);
  1505. }
  1506. }
  1507. }
  1508. #endregion
  1509. /// <summary>
  1510. /// 增加事件
  1511. /// </summary>
  1512. /// <param name="sender"></param>
  1513. /// <param name="e"></param>
  1514. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  1515. {
  1516. if (APP.pageData.currpage > 0)
  1517. {
  1518. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1519. }
  1520. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  1521. {
  1522. blackboard_canvas.Visibility = Visibility.Visible;
  1523. }
  1524. APP.pageData.pagenum += 1;
  1525. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1526. APP.pageData.currpage = APP.pageData.pagenum;
  1527. myblackboard.changepage(APP.pageData.currpage - 1);
  1528. ///清空页面图片UI
  1529. imgCanvas.Source = null;
  1530. imgDocumentation.Source = null;
  1531. ///画板模型增加一页
  1532. Model_DrawData model_DrawData = new Model_DrawData();
  1533. model_DrawData.PageNum = APP.pageData.currpage;
  1534. APP.PageDrawList.Add(model_DrawData);
  1535. APP.SaveDraw();
  1536. if (btnImport.IsEnabled == true)
  1537. {
  1538. ///截图可用
  1539. ImgScreenshot.Visibility = Visibility.Visible;
  1540. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1541. btnScreenshot.IsEnabled = true;
  1542. }
  1543. }
  1544. /// <summary>
  1545. /// 打印事件
  1546. /// </summary>
  1547. /// <param name="sender"></param>
  1548. /// <param name="e"></param>
  1549. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  1550. {
  1551. try
  1552. {
  1553. //3种情况 1.文档图片 2.截图图片 3.没有图片
  1554. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  1555. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  1556. ////设置纸张横向
  1557. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  1558. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  1559. FileToolsCommon.CreateFile(imgPath);
  1560. imgPath += "\\101.pdf";
  1561. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  1562. document.Open();
  1563. iTextSharp.text.Image image;
  1564. for (int i = 0; i < APP.PageDrawList.Count; i++)
  1565. {
  1566. long ii = Timestamp();
  1567. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1568. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  1569. RectangleF rectangleFs = new RectangleF();
  1570. MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  1571. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  1572. if (String.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  1573. {
  1574. }
  1575. else if (APP.PageDrawList[i].ImgDocumentation == true)
  1576. {
  1577. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  1578. }
  1579. else
  1580. {
  1581. RectangleF rectangleF = new RectangleF();
  1582. rectangleF.Width = (float)APP.PageDrawList[i].ImageSizes.CenterX;
  1583. rectangleF.Height = (float)APP.PageDrawList[i].ImageSizes.CenterY;
  1584. rectangleF.X = (float)APP.PageDrawList[i].ImageLocation.X;
  1585. rectangleF.Y = (float)APP.PageDrawList[i].ImageLocation.Y;
  1586. string msg = string.Empty;
  1587. bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
  1588. if (isImg)
  1589. {
  1590. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  1591. }
  1592. else
  1593. {
  1594. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  1595. }
  1596. }
  1597. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  1598. {
  1599. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1600. }
  1601. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  1602. {
  1603. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  1604. }
  1605. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  1606. document.NewPage();
  1607. document.Add(image);
  1608. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  1609. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  1610. //p1.Leading = 150; //行间距
  1611. //document.Add(p1);
  1612. }
  1613. Console.WriteLine("转换成功!");
  1614. document.Close();
  1615. }
  1616. catch (Exception ex)
  1617. {
  1618. Console.WriteLine("转换失败,原因:" + ex.Message);
  1619. }
  1620. //document.Close();
  1621. ////Console.ReadKey();
  1622. if (APP.W_PrintWindow == null)
  1623. {
  1624. APP.W_PrintWindow = new PrintWindow();
  1625. //APP.W_PrintWindow.Topmost = true;
  1626. APP.W_PrintWindow.Owner = this;
  1627. }
  1628. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  1629. {
  1630. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath);
  1631. }
  1632. else
  1633. {
  1634. APP.W_PrintWindow.Initialize("");
  1635. }
  1636. APP.W_PrintWindow.ShowDialog();
  1637. //int pr = 1;
  1638. //string msg = string.Empty;
  1639. //string outPut = string.Empty;
  1640. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  1641. //if(pr==0)
  1642. //{
  1643. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  1644. // APP.OutPut = outPut.Split(',');
  1645. // string defa = string.Empty;
  1646. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  1647. // int printResult = 1;
  1648. // string standardError = string.Empty;
  1649. // string standardOutput = string.Empty;
  1650. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  1651. //}
  1652. }
  1653. /// 上一页
  1654. /// </summary>
  1655. /// <param name="sender"></param>
  1656. /// <param name="e"></param>
  1657. private void last_button_Click(object sender, RoutedEventArgs e)
  1658. {
  1659. if (APP.pageData.currpage > 1)
  1660. {
  1661. APP.pageData.currpage -= 1;
  1662. myblackboard.changepage(APP.pageData.currpage - 1);
  1663. if (btnImport.IsEnabled == true)
  1664. {
  1665. ///截图可用
  1666. ImgScreenshot.Visibility = Visibility.Visible;
  1667. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1668. btnScreenshot.IsEnabled = true;
  1669. }
  1670. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1671. {
  1672. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1673. {
  1674. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1675. }
  1676. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1677. {
  1678. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  1679. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1680. {
  1681. imgCanvas.Source = null;
  1682. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1683. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1684. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1685. btnScreenshot.IsEnabled = false;
  1686. }
  1687. else
  1688. {
  1689. imgDocumentation.Source = null;
  1690. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1691. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1692. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1693. {
  1694. var group = IMG.FindResource("Imageview") as TransformGroup;
  1695. var transform = group.Children[1] as TranslateTransform;
  1696. #region 高低 缩放比例
  1697. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1698. {
  1699. var transform1 = group.Children[0] as ScaleTransform;
  1700. transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1701. transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1702. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  1703. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  1704. }
  1705. #endregion
  1706. #region XY轴
  1707. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1708. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1709. #endregion
  1710. mouseDown = false;
  1711. }
  1712. }
  1713. }
  1714. else
  1715. {
  1716. imgCanvas.Source = null;
  1717. imgDocumentation.Source = null;
  1718. }
  1719. }
  1720. }
  1721. }
  1722. /// <summary>
  1723. /// 下一页
  1724. /// </summary>
  1725. /// <param name="sender"></param>
  1726. /// <param name="e"></param>
  1727. private void next_btn_Click(object sender, RoutedEventArgs e)
  1728. {
  1729. if (APP.pageData.currpage < APP.pageData.pagenum)
  1730. {
  1731. APP.pageData.currpage += 1;
  1732. myblackboard.changepage(APP.pageData.currpage - 1);
  1733. if (btnImport.IsEnabled == true)
  1734. {
  1735. ///截图可用
  1736. ImgScreenshot.Visibility = Visibility.Visible;
  1737. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1738. btnScreenshot.IsEnabled = true;
  1739. }
  1740. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  1741. {
  1742. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  1743. {
  1744. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  1745. }
  1746. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1747. {
  1748. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  1749. {
  1750. imgCanvas.Source = null;
  1751. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1752. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1753. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1754. btnScreenshot.IsEnabled = false;
  1755. }
  1756. else
  1757. {
  1758. imgDocumentation.Source = null;
  1759. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1760. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1761. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  1762. {
  1763. var group = IMG.FindResource("Imageview") as TransformGroup;
  1764. #region 高低 缩放比例
  1765. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  1766. {
  1767. var transform1 = group.Children[0] as ScaleTransform;
  1768. transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  1769. transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  1770. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  1771. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  1772. }
  1773. #endregion
  1774. #region 坐标XY轴
  1775. var transform = group.Children[1] as TranslateTransform;
  1776. transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  1777. transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  1778. #endregion
  1779. mouseDown = false;
  1780. }
  1781. }
  1782. }
  1783. else
  1784. {
  1785. imgCanvas.Source = null;
  1786. imgDocumentation.Source = null;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. /// <summary>
  1792. /// 生成图片
  1793. /// </summary>
  1794. /// <param name="_path">图片地址</param>
  1795. /// <param name="_saveimg">保存位置</param>
  1796. /// <param name="_rectangle">图片位置</param>
  1797. /// <param name="errmsg">错误消息</param>
  1798. /// <returns></returns>
  1799. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  1800. {
  1801. errmsg = null;
  1802. try
  1803. {
  1804. Bitmap bitmap = null;
  1805. //创建要显示的图片对象,根据参数的个数设置宽度
  1806. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  1807. Graphics g = Graphics.FromImage(backgroudImg);
  1808. //清除画布,背景设置为白色
  1809. g.Clear(System.Drawing.Color.White);
  1810. if (!string.IsNullOrWhiteSpace(_path))
  1811. {
  1812. bitmap = ImageHelper.ReadBitmapFile(_path);
  1813. g.DrawImage(bitmap, _rectangle);
  1814. }
  1815. backgroudImg.Save(_saveimg);
  1816. g.Dispose();
  1817. backgroudImg.Dispose();
  1818. if (bitmap != null)
  1819. {
  1820. bitmap.Dispose();
  1821. }
  1822. GC.Collect();
  1823. return true;
  1824. }
  1825. catch (Exception ex)
  1826. {
  1827. errmsg = ex.Message;
  1828. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  1829. return false;
  1830. }
  1831. }
  1832. /// <summary>
  1833. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  1834. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  1835. /// </summary>
  1836. /// <param name="pdfInputPath">Word文件路径</param>
  1837. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  1838. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  1839. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  1840. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  1841. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  1842. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  1843. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  1844. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  1845. {
  1846. // 返回的图片绝对路径集合
  1847. List<string> images = new List<string>();
  1848. try
  1849. {
  1850. // open word file
  1851. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  1852. // validate parameter
  1853. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  1854. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  1855. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  1856. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  1857. if (startPageNum <= 0) { startPageNum = 1; }
  1858. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  1859. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  1860. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  1861. if (resolution <= 0) { resolution = 128; }
  1862. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  1863. {
  1864. Resolution = resolution
  1865. };
  1866. // start to convert each page
  1867. for (int i = startPageNum; i <= endPageNum; i++)
  1868. {
  1869. imageSaveOptions.PageIndex = i - 1;
  1870. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1871. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1872. APP.num++;
  1873. }
  1874. imageSaveOptions = null;
  1875. doc = null;
  1876. }
  1877. catch (Exception ex)
  1878. {
  1879. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1880. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1881. }
  1882. return images;
  1883. }
  1884. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1885. {
  1886. SaveFormat sf;// = SaveFormat.Unknown;
  1887. if (imageFormat.Equals(ImageFormat.Png))
  1888. {
  1889. sf = SaveFormat.Png;
  1890. }
  1891. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1892. {
  1893. sf = SaveFormat.Jpeg;
  1894. }
  1895. else if (imageFormat.Equals(ImageFormat.Tiff))
  1896. {
  1897. sf = SaveFormat.Tiff;
  1898. }
  1899. else if (imageFormat.Equals(ImageFormat.Bmp))
  1900. {
  1901. sf = SaveFormat.Bmp;
  1902. }
  1903. else
  1904. {
  1905. sf = SaveFormat.Unknown;
  1906. }
  1907. return sf;
  1908. }
  1909. #region 图像缩放,移动
  1910. private bool mouseDown;
  1911. private System.Windows.Point mouseXY;
  1912. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1913. {
  1914. var img = sender as ContentControl;
  1915. if (img == null)
  1916. {
  1917. return;
  1918. }
  1919. img.CaptureMouse();
  1920. mouseDown = true;
  1921. mouseXY = e.GetPosition(img);
  1922. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1923. }
  1924. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1925. {
  1926. System.Windows.Point point = e.GetPosition(imgCanvas);
  1927. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1928. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1929. //{
  1930. // Console.WriteLine("在范围内");
  1931. //}
  1932. }
  1933. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1934. {
  1935. var img = sender as ContentControl;
  1936. if (img == null)
  1937. {
  1938. return;
  1939. }
  1940. img.ReleaseMouseCapture();
  1941. mouseDown = false;
  1942. }
  1943. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1944. {
  1945. var img = sender as ContentControl;
  1946. if (img == null)
  1947. {
  1948. return;
  1949. }
  1950. if (mouseDown)
  1951. {
  1952. Domousemove(img, e);
  1953. }
  1954. }
  1955. /// <summary>
  1956. /// x y轴
  1957. /// </summary>
  1958. /// <param name="img"></param>
  1959. /// <param name="e"></param>
  1960. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1961. {
  1962. if (e.LeftButton != MouseButtonState.Pressed)
  1963. {
  1964. return;
  1965. }
  1966. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  1967. {
  1968. return;
  1969. }
  1970. var group = IMG.FindResource("Imageview") as TransformGroup;
  1971. var transform = group.Children[1] as TranslateTransform;
  1972. var position = e.GetPosition(img);
  1973. transform.X -= mouseXY.X - position.X;
  1974. transform.Y -= mouseXY.Y - position.Y;
  1975. mouseXY = position;
  1976. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  1977. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform.X;
  1978. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform.Y;
  1979. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1980. }
  1981. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1982. {
  1983. var img = sender as ContentControl;
  1984. if (img == null)
  1985. {
  1986. return;
  1987. }
  1988. var point = e.GetPosition(img);
  1989. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1990. var PicLocate = e.GetPosition(imgCanvas);
  1991. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1992. var group = IMG.FindResource("Imageview") as TransformGroup;
  1993. var delta = e.Delta * 0.001;
  1994. DowheelZoom(group, point, delta);
  1995. }
  1996. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1997. {
  1998. var pointToContent = group.Inverse.Transform(point);
  1999. var transform = group.Children[0] as ScaleTransform;
  2000. if (transform.ScaleX + delta < 0.1) return;
  2001. transform.ScaleX += delta;
  2002. transform.ScaleY += delta;
  2003. var transform1 = group.Children[1] as TranslateTransform;
  2004. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  2005. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  2006. LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  2007. + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  2008. );
  2009. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  2010. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  2011. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  2012. APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  2013. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
  2014. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform1.X;
  2015. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform1.Y;
  2016. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform();
  2017. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX = imgCanvas.ActualWidth;
  2018. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY = imgCanvas.ActualHeight;
  2019. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2020. }
  2021. #endregion
  2022. #region 点阵笔相关
  2023. #region 值初始化
  2024. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  2025. /// <summary>
  2026. /// A4点阵纸点阵宽度
  2027. /// </summary>
  2028. private const int A4_WIDTH = 5600;
  2029. /// <summary>
  2030. /// A4点阵纸点阵高度
  2031. /// </summary>
  2032. private const int A4_HEIGHT = 7920;
  2033. /// <summary>
  2034. /// 画板
  2035. /// </summary>
  2036. private Graphics graphics;
  2037. /// <summary>
  2038. /// 笔画坐标数组
  2039. /// </summary>
  2040. private List<System.Drawing.Point> stroke;
  2041. /// <summary>
  2042. /// 笔序列号
  2043. /// </summary>
  2044. private string penSerial;
  2045. /// <summary>
  2046. /// 笔是否在点
  2047. /// </summary>
  2048. private bool isPenDown;
  2049. //当前点阵地址
  2050. private string currentPageSerial = string.Empty;
  2051. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  2052. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  2053. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  2054. #endregion
  2055. public void InitPen()
  2056. {
  2057. stroke = new List<System.Drawing.Point>();
  2058. //获取点阵笔实例,并绑定点阵笔事件
  2059. //将授权文件内容传入,获取点阵笔对象实例
  2060. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  2061. //绑定笔连接事件
  2062. APP.digitalPen.PenConnected += OnPenConnect;
  2063. //绑定笔断开事件
  2064. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  2065. //绑定笔书写输出坐标事件
  2066. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  2067. //绑定抬笔事件
  2068. APP.digitalPen.PenUp += OnPenUp;
  2069. //绑定落笔事件
  2070. APP.digitalPen.PenDown += OnPenDown;
  2071. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  2072. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  2073. //完成初始化点阵笔,开始与点阵笔通信
  2074. ERROR_CODE ER = APP.digitalPen.Start();
  2075. ////绑定笔在新的点阵地址页面书写事件
  2076. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  2077. ////绑定笔信息事件
  2078. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  2079. //启动接收笔数据,完成初始化工作
  2080. ERROR_CODE rc = APP.digitalPen.Start();
  2081. //判断是否成功
  2082. if (ER != ERROR_CODE.ERROR_OK)
  2083. {
  2084. System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  2085. }
  2086. }
  2087. /// <summary>
  2088. /// 落笔
  2089. /// </summary>
  2090. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2091. /// <param name="penSerial">点阵笔序列号</param>
  2092. /// <param name="penType">点阵笔型号编号</param>
  2093. private void OnPenDown(ulong time, string penSerial, int penType)
  2094. {
  2095. if (this.CheckAccess())
  2096. {
  2097. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  2098. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2099. }
  2100. else
  2101. {
  2102. //labPenSerial.Text = penSerial;
  2103. //labPenStatus.Text = "PenDown";
  2104. isPenDown = true;
  2105. //Dispatcher.Invoke(new Action(() =>
  2106. //{
  2107. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  2108. // {
  2109. // if (APP.PageDrawList[i].PageCode == penSerial)
  2110. // {
  2111. // if (i < APP.pageData.pagenum)
  2112. // {
  2113. // if (i < APP.pageData.currpage)
  2114. // {
  2115. // int num = APP.pageData.currpage - i;
  2116. // APP.pageData.currpage -= num;
  2117. // myblackboard.changepage(APP.pageData.currpage - 1);
  2118. // if (APP.PageDrawList.Count > 0)
  2119. // {
  2120. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2121. // {
  2122. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  2123. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2124. // }
  2125. // else
  2126. // {
  2127. // imgCanvas.Source = null;
  2128. // }
  2129. // }
  2130. // }
  2131. // else
  2132. // {
  2133. // int num = i - APP.pageData.currpage;
  2134. // APP.pageData.currpage += num;
  2135. // myblackboard.changepage(APP.pageData.currpage - 1);
  2136. // if (APP.PageDrawList.Count > 0)
  2137. // {
  2138. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2139. // {
  2140. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  2141. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2142. // }
  2143. // else
  2144. // {
  2145. // imgCanvas.Source = null;
  2146. // }
  2147. // }
  2148. // }
  2149. // }
  2150. // return;
  2151. // }
  2152. // }
  2153. // //myblackboard.changepages(0, 0, true);
  2154. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  2155. //}));
  2156. }
  2157. //myblackboard.changepages(0, 0, true);
  2158. }
  2159. /// <summary>
  2160. /// 抬笔
  2161. /// </summary>
  2162. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2163. /// <param name="penSerial">点阵笔序列号</param>
  2164. /// <param name="penType">点阵笔型号编号</param>
  2165. private void OnPenUp(ulong time, string penSerial, int penType)
  2166. {
  2167. if (this.CheckAccess())
  2168. {
  2169. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  2170. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2171. }
  2172. else
  2173. {
  2174. isPenDown = false;
  2175. APP.PenSerial = penSerial;
  2176. //int leftPoints = stroke.Count % 3;
  2177. //if (0 != leftPoints)
  2178. //{
  2179. // int from = stroke.Count - leftPoints - 1;
  2180. // if (from < 0)
  2181. // from = 0;
  2182. // int to = stroke.Count - 1;
  2183. // DrawCoordinates(from, to);
  2184. //}
  2185. stroke.Clear();
  2186. }
  2187. if (APP.pageData.currpage > 0)
  2188. {
  2189. Dispatcher.Invoke(new Action(() =>
  2190. {
  2191. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
  2192. }));
  2193. }
  2194. }
  2195. /// <summary>
  2196. /// 笔断开
  2197. /// </summary>
  2198. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2199. /// <param name="penSerial">点阵笔序列号</param>
  2200. /// <param name="penType">点阵笔型号编号</param>
  2201. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  2202. {
  2203. if (this.CheckAccess())
  2204. {
  2205. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  2206. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2207. }
  2208. else
  2209. {
  2210. APP.PenSerial = penSerial;
  2211. APP.PenStatus = false;
  2212. Dispatcher.Invoke(new Action(() =>
  2213. {
  2214. txbNotConnected.Text = "未连接";
  2215. txbNotConnecteds.Text = "未连接";
  2216. }));
  2217. }
  2218. }
  2219. /// <summary>
  2220. /// 笔连接
  2221. /// </summary>
  2222. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2223. /// <param name="penSerial">点阵笔序列号</param>
  2224. /// <param name="penType">点阵笔型号编号</param>
  2225. private void OnPenConnect(ulong time, string penSerial, int penType)
  2226. {
  2227. if (this.CheckAccess())
  2228. {
  2229. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  2230. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2231. }
  2232. else
  2233. {
  2234. APP.PenSerial = penSerial;
  2235. APP.PenStatus = true;
  2236. this.penSerial = penSerial;
  2237. //连接后,在获取笔数据前,可以清除笔内的历史数据
  2238. //APP.digitalPen.ClearMemory(penSerial);
  2239. //开始接收笔数据
  2240. APP.digitalPen.GetPenData(penSerial);
  2241. Dispatcher.Invoke(new Action(() =>
  2242. {
  2243. txbNotConnected.Text = "已连接";
  2244. txbNotConnecteds.Text = "已连接";
  2245. }));
  2246. }
  2247. }
  2248. /// <summary>
  2249. /// 电池电量
  2250. /// </summary>
  2251. /// <param name="time"></param>
  2252. /// <param name="penSerial"></param>
  2253. /// <param name="penType"></param>
  2254. /// <param name="capacity"></param>
  2255. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  2256. {
  2257. if (this.CheckAccess())
  2258. {
  2259. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  2260. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  2261. }
  2262. else
  2263. {
  2264. //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
  2265. }
  2266. }
  2267. /// <summary>
  2268. /// 已用存储
  2269. /// </summary>
  2270. /// <param name="time"></param>
  2271. /// <param name="penSerial"></param>
  2272. /// <param name="penType"></param>
  2273. /// <param name="fillLevel"></param>
  2274. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  2275. {
  2276. if (this.CheckAccess())
  2277. {
  2278. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  2279. this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  2280. }
  2281. else
  2282. {
  2283. //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
  2284. }
  2285. }
  2286. /// <summary>
  2287. /// 笔书写,收到坐标
  2288. /// </summary>
  2289. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2290. /// <param name="penSerial">点阵笔序列号</param>
  2291. /// <param name="penType">点阵笔型号编号</param>
  2292. /// <param name="pageSerial">点阵地址</param>
  2293. /// <param name="cx">x坐标</param>
  2294. /// <param name="cy">y坐标</param>
  2295. /// <param name="force">压力值</param>
  2296. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  2297. {
  2298. if (this.CheckAccess())
  2299. {
  2300. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  2301. this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  2302. }
  2303. else
  2304. {
  2305. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  2306. if (!isPenDown)
  2307. {
  2308. return;
  2309. }
  2310. stroke.Add(new System.Drawing.Point(cx, cy));
  2311. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  2312. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  2313. //点
  2314. double testX = (double)cx * PropW;
  2315. double testY = (double)cy * PropH;
  2316. //pageSerial //点阵IP地址 与打印的页面关联
  2317. if (APP.pageData.currpage > 0)
  2318. {
  2319. Dispatcher.Invoke(new Action(() =>
  2320. {
  2321. //myblackboard.changepages(testX, testY,false);
  2322. myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
  2323. #region 设置滚动条位置
  2324. //点在显示页面上方
  2325. if (testY < scroMain.VerticalOffset)
  2326. {
  2327. //滚动条当前位置
  2328. double RollCurrentLocation = scroMain.VerticalOffset;
  2329. //向上滚动至以点为中心需要滚动的距离
  2330. double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
  2331. //如果小于0则等于0
  2332. double RollLocation = RollCurrentLocation - UpRoll;
  2333. if (RollLocation < 0)
  2334. {
  2335. RollLocation = 0;
  2336. }
  2337. ////滚动条实际偏移量
  2338. //double RollOffset = RollCurrentLocation - RollLocation;
  2339. scroMain.ScrollToVerticalOffset(RollLocation);
  2340. }
  2341. //点在显示页面下方
  2342. if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
  2343. {
  2344. //滚动条当前位置
  2345. double RollCurrentLocation = scroMain.VerticalOffset;
  2346. //向下滚动至以点为中心需要滚动的距离
  2347. double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  2348. //如果小于0则等于0
  2349. double RollLocation = RollCurrentLocation + DownRoll;
  2350. //滚动条最大滚动值
  2351. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  2352. if (RollLocation > ScrollbarMaxNum)
  2353. {
  2354. RollLocation = ScrollbarMaxNum;
  2355. }
  2356. ////滚动条实际偏移量
  2357. //double RollOffset = RollLocation-RollCurrentLocation;
  2358. scroMain.ScrollToVerticalOffset(RollLocation);
  2359. }
  2360. #endregion
  2361. //gridM.Height //A4高度
  2362. //scroMain.VerticalOffset;//获取滚动条位置
  2363. //scroMain.ActualHeight//A4纸显示高度
  2364. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  2365. //Mouse.GetPosition(this)
  2366. if (testX > 0 && testY > 0)
  2367. {
  2368. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  2369. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  2370. SetCursorPos((int)getP.X, (int)getP.Y);
  2371. }
  2372. }));
  2373. }
  2374. ////每3个点画一条曲线
  2375. //if (stroke.Count % 3 == 0)
  2376. //{
  2377. // int from = stroke.Count - 3 - 1;
  2378. // if (from < 0)
  2379. // from = 0;
  2380. // int to = stroke.Count - 1;
  2381. // DrawCoordinates(from, to);
  2382. //}
  2383. }
  2384. }
  2385. /// <summary>
  2386. /// 停止笔
  2387. /// </summary>
  2388. public void StopDigitalPen()
  2389. {
  2390. //停止,释放资源
  2391. APP.digitalPen.Stop();
  2392. }
  2393. /// <summary>
  2394. /// 清空笔内存储
  2395. /// </summary>
  2396. public void ClearPenStorage()
  2397. {
  2398. if (!string.IsNullOrEmpty(penSerial))
  2399. APP.digitalPen.ClearMemory(penSerial);
  2400. }
  2401. /// <summary>
  2402. /// 获取剩余电量
  2403. /// </summary>
  2404. public void GetPenElectricityQuantity()
  2405. {
  2406. if (!string.IsNullOrEmpty(penSerial))
  2407. APP.digitalPen.GetBatteryCapacity(penSerial);
  2408. }
  2409. /// <summary>
  2410. /// 获取存储空间
  2411. /// </summary>
  2412. public void GetUsedStorage()
  2413. {
  2414. if (!string.IsNullOrEmpty(penSerial))
  2415. APP.digitalPen.GetMemoryFillLevel(penSerial);
  2416. }
  2417. /// <summary>
  2418. /// 开启悬浮
  2419. /// </summary>
  2420. public void 开启悬浮()
  2421. {
  2422. if (!string.IsNullOrEmpty(penSerial))
  2423. APP.digitalPen.SetPenHoverMode(true, penSerial);
  2424. }
  2425. /// <summary>
  2426. /// 关闭悬浮
  2427. /// </summary>
  2428. public void 关闭悬浮()
  2429. {
  2430. if (!string.IsNullOrEmpty(penSerial))
  2431. APP.digitalPen.SetPenHoverMode(false, penSerial);
  2432. }
  2433. #endregion
  2434. /// <summary>
  2435. /// 最小化
  2436. /// </summary>
  2437. /// <param name="sender"></param>
  2438. /// <param name="e"></param>
  2439. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  2440. {
  2441. if (this.WindowState == WindowState.Minimized)
  2442. {
  2443. this.WindowState = WindowState.Normal;
  2444. }
  2445. else
  2446. {
  2447. this.WindowState = WindowState.Minimized;
  2448. }
  2449. }
  2450. /// <summary>
  2451. /// 位置确定
  2452. /// </summary>
  2453. /// <param name="sender"></param>
  2454. /// <param name="e"></param>
  2455. private void BtnOk_Click(object sender, RoutedEventArgs e)
  2456. {
  2457. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2458. //btnOk.Visibility = Visibility.Collapsed;
  2459. //blackboard_canvas.Visibility = Visibility.Visible;
  2460. }
  2461. /// <summary>
  2462. /// 引用user32.dll动态链接库(windows api),
  2463. /// 使用库中定义 API:SetCursorPos
  2464. /// 设置光标位置
  2465. /// </summary>
  2466. [System.Runtime.InteropServices.DllImport("user32.dll")]
  2467. private static extern int SetCursorPos(int x, int y);
  2468. /// 截图的图片鼠标右键事件
  2469. /// </summary>
  2470. /// <param name="sender"></param>
  2471. /// <param name="e"></param>
  2472. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  2473. {
  2474. imgCanvas.Source = null;
  2475. }
  2476. private void Button_Click(object sender, RoutedEventArgs e)
  2477. {
  2478. //System.Windows.SplashScreen(LoadDialog);
  2479. //Common.system.SplashScreen.Show(typeof(LoadDialog));
  2480. //Thread.Sleep(5000);
  2481. //Common.system.SplashScreen.Close();
  2482. APP.myloading.Show();
  2483. Thread.Sleep(1000);
  2484. APP.myloading.Hide();
  2485. }
  2486. }
  2487. }