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

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