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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086
  1. using Accord.Video.FFMPEG;
  2. using Aspose.Slides;
  3. using ComeCapture;
  4. using Common.system;
  5. using NAudio.Wave;
  6. using NReco.VideoConverter;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Ink;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using TmatrixLibrary;
  21. using XHWK.Model;
  22. using XHWK.WKTool.Models;
  23. using XHWK.WKTool.Skin;
  24. using XHWK.WKTool.UControl;
  25. using XHWK.WKTool.Utils;
  26. using XHWK.WKTool.Utils.luobo;
  27. using XHWK.WKTool.Utils.pen;
  28. namespace XHWK.WKTool
  29. {
  30. using System.Globalization;
  31. using system;
  32. /// <summary>
  33. /// 主页面
  34. /// </summary>
  35. public partial class MainWindow : PenEventI
  36. {
  37. #region 字段
  38. public BlackboardNew myblackboard;
  39. /// <summary>
  40. /// 当前颜色
  41. /// </summary>
  42. private System.Windows.Media.Color _color = Colors.Red;
  43. //声明一个 DrawingAttributes 类型的变量
  44. private DrawingAttributes _drawingAttributes;
  45. /// <summary>
  46. /// 键盘钩子
  47. /// </summary>
  48. private KeyboardHookCommon _kHook;
  49. private System.Windows.Forms.OpenFileDialog _ofd;
  50. private System.Windows.Forms.FolderBrowserDialog _fbd;
  51. /// <summary>
  52. /// 笔迹粗细
  53. /// </summary>
  54. private int _penSize = 2;
  55. private System.Windows.Forms.DialogResult _result;
  56. private System.Windows.Forms.DialogResult _result2;
  57. private ModelVideo _videoInfo;
  58. //定义委托
  59. public delegate void ChangeTextHandler(string text);
  60. //定义委托
  61. public delegate void ChangeTextHandlers(string text, int i);
  62. #region 上传
  63. /// <summary>
  64. /// 视频模型
  65. /// </summary>
  66. private List<ModelVideo> _modelVideoList;
  67. #endregion 上传
  68. #endregion 字段
  69. #region 初始化
  70. private readonly ImageOperationUtil _imageOperationUtil;
  71. private readonly LuoBoPenUtil _luoBoPenUtil;
  72. /// <summary>
  73. /// 主页面
  74. /// </summary>
  75. public MainWindow()
  76. {
  77. InitializeComponent();
  78. #region 调整文字大小
  79. App.PageContextData.WordSize20 = 20.00;
  80. App.PageContextData.WordSize18 = 18.00;
  81. App.PageContextData.WordSize16 = 16.00;
  82. App.PageContextData.WordSize14 = 14.00;
  83. App.PageContextData.WordSize12 = 12.00;
  84. #endregion 调整文字大小
  85. ResizeMode = ResizeMode.CanMinimize;
  86. BtnPrint.IsEnabled = false;
  87. myblackboard = new BlackboardNew(BlackboardCanvas);
  88. App.PageContextData.pagenum = 0;
  89. App.PageContextData.currpage = 0;
  90. DataContext = App.PageContextData;
  91. //APP.SaveDraw();//画板模型第一页初始化
  92. App.PageDrawList = new List<ModelDrawData>();
  93. ModelDrawData modelDrawData = new ModelDrawData { PageNum = App.PageContextData.currpage };
  94. App.PageDrawList.Add(modelDrawData);
  95. Txbv.Text = (App.isDebug ? "测试版" : "正式版") + " v" + FileToolsCommon.GetConfigValue("VersionName");
  96. TxbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  97. TxbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  98. Initialize();
  99. //罗博手写板
  100. _luoBoPenUtil = new LuoBoPenUtil(this);
  101. _luoBoPenUtil.InitlbPen();
  102. //腾千里
  103. InitTqlpPen();
  104. SkinSelectInit();
  105. byte[] license = Convert.FromBase64String
  106. (
  107. "PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4="
  108. );
  109. new Aspose.Words.License().SetLicense(new MemoryStream(license));
  110. new Aspose.Pdf.License().SetLicense(new MemoryStream(license));
  111. new Aspose.Slides.License().SetLicense(new MemoryStream(license));
  112. _imageOperationUtil = new ImageOperationUtil
  113. (
  114. RectLeftUp,
  115. RectRightUp,
  116. RectLeftDown,
  117. RectRightDown,
  118. RectImgBorder,
  119. ImgCanvas,
  120. GridM
  121. );
  122. InitPrint();
  123. }
  124. private void LoadImage(BitmapImage image)
  125. {
  126. HeadImg.Source = image;
  127. try
  128. {
  129. switch (App.CameraPosition)
  130. {
  131. case "1":
  132. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  133. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  134. break;
  135. case "2":
  136. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  137. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  138. break;
  139. case "3":
  140. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  141. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  142. break;
  143. case "4":
  144. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  145. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  146. break;
  147. }
  148. }
  149. catch (Exception)
  150. {
  151. // ignored
  152. }
  153. }
  154. /// <summary>
  155. /// 初始化
  156. /// </summary>
  157. public void Initialize()
  158. {
  159. #region 数据初始化
  160. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  161. FileToolsCommon.CreateDirectory(pathTemp);
  162. App.PageContextData.pagenum = 0;
  163. App.PageContextData.currpage = App.PageContextData.pagenum;
  164. BtnStop.IsEnabled = false; //停止录制按钮不可点击
  165. #endregion 数据初始化
  166. _kHook = new KeyboardHookCommon();
  167. _kHook.KeyDownEvent += K_hook_KeyDownEvent;
  168. _kHook.Start(); //安装键盘钩子
  169. App.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  170. //创建 DrawingAttributes 类的一个实例
  171. _drawingAttributes = new DrawingAttributes();
  172. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  173. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  174. BlackboardCanvas.DefaultDrawingAttributes = _drawingAttributes;
  175. BlackboardCanvas.UseCustomCursor = true;
  176. _drawingAttributes.FitToCurve = true;
  177. _drawingAttributes.IgnorePressure = false;
  178. _drawingAttributes.Width = _penSize;
  179. _drawingAttributes.Height = _penSize;
  180. _drawingAttributes.Color = _color;
  181. BlackboardCanvas.Cursor = Cursors.Pen;
  182. }
  183. /// <summary>
  184. /// 初始化快捷键
  185. /// </summary>
  186. public void InitializeKeyDownEvent()
  187. {
  188. _kHook.Start(); //安装键盘钩子
  189. }
  190. /// <summary>
  191. /// 引用user32.dll动态链接库(windows api), 使用库中定义 API:SetCursorPos 设置光标位置
  192. /// </summary>
  193. [System.Runtime.InteropServices.DllImport("user32.dll")]
  194. private static extern int SetCursorPos(int x, int y);
  195. /// <summary>
  196. /// 快捷键
  197. /// </summary>
  198. /// <param name="sender">
  199. /// </param>
  200. /// <param name="e">
  201. /// </param>
  202. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  203. {
  204. if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
  205. {
  206. if (App.PageContextData.currpage > 1)
  207. {
  208. //上一页
  209. last_button_Click(null, null);
  210. }
  211. }
  212. if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
  213. {
  214. if (App.PageContextData.currpage < App.PageContextData.pagenum)
  215. {
  216. //下一页
  217. next_btn_Click(null, null);
  218. }
  219. }
  220. if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
  221. {
  222. if (RectImgBorder.Visibility != Visibility.Hidden)
  223. {
  224. HideAngleBorder();
  225. ImgCanvas.Source = null;
  226. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = null;
  227. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = null;
  228. }
  229. }
  230. }
  231. /// <summary>
  232. /// 加载完成后调整录制区域大小
  233. /// </summary>
  234. /// <param name="sender">
  235. /// </param>
  236. /// <param name="e">
  237. /// </param>
  238. private async void Window_Loaded(object sender, RoutedEventArgs e)
  239. {
  240. //调整录制区域宽高
  241. double proportion = 210.0 / 297.0;
  242. GridM.Height = GridM.ActualWidth / proportion;
  243. await CheckDevice();
  244. }
  245. private bool _microphoneGood;
  246. private bool _loudspeakerGood;
  247. private async Task CheckDevice()
  248. {
  249. Task<bool> checkMicrophone = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.Microphone));
  250. Task<bool> checkLoudspeaker = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.Loudspeaker));
  251. await Task.WhenAll(checkMicrophone, checkLoudspeaker);
  252. _microphoneGood = checkMicrophone.Result;
  253. _loudspeakerGood = checkMicrophone.Result;
  254. }
  255. #endregion 初始化
  256. #region 事件
  257. #region 登录
  258. /// <summary>
  259. /// 登录事件
  260. /// </summary>
  261. /// <param name="sender">
  262. /// </param>
  263. /// <param name="e">
  264. /// </param>
  265. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  266. {
  267. if ("未登录".Equals(TxbLoginType.Text) || ImgHeadImgN.Visibility == Visibility.Visible)
  268. {
  269. Login();
  270. }
  271. else
  272. {
  273. MessageBoxResult dr = MessageWindow.Show
  274. (
  275. "确定退出登录?",
  276. "提示",
  277. MessageBoxButton.OKCancel
  278. );
  279. if (dr != MessageBoxResult.OK)
  280. {
  281. return;
  282. }
  283. LoginType();
  284. Login();
  285. }
  286. }
  287. /// <summary>
  288. /// 登录
  289. /// </summary>
  290. private void Login()
  291. {
  292. if (App.W_LoginWindow == null)
  293. {
  294. App.W_LoginWindow = new LoginWindow
  295. {
  296. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  297. Owner = this
  298. };
  299. }
  300. else
  301. {
  302. App.W_LoginWindow.Initialize();
  303. }
  304. App.W_LoginWindow.ShowDialog();
  305. if (App.IsLoginType)
  306. {
  307. string headpicPath = FileToolsCommon.GetFileAbsolutePath("/Data/" + App.UserInfo.Username + ".png");
  308. if (FileToolsCommon.IsExistFile(headpicPath))
  309. {
  310. ImgHead.ImageSource = new BitmapImage(new Uri(headpicPath));
  311. }
  312. else
  313. {
  314. ImgHead.ImageSource = new BitmapImage(new Uri("pack://application:,,,/BlackImages/HM_HeadImg.png"));
  315. }
  316. TxbLoginType.Text = App.UserInfo.Username;
  317. ImgHeadImgN.Visibility = Visibility.Collapsed;
  318. ImgHeadImg.Visibility = Visibility.Visible;
  319. }
  320. else
  321. {
  322. TxbLoginType.Text = "未登录";
  323. ImgHeadImgN.Visibility = Visibility.Visible;
  324. ImgHeadImg.Visibility = Visibility.Collapsed;
  325. }
  326. }
  327. /// <summary>
  328. /// 状态更改为未登录
  329. /// </summary>
  330. private void LoginType()
  331. {
  332. App.IsLoginType = false;
  333. TxbLoginType.Text = "未登录";
  334. ImgHeadImgN.Visibility = Visibility.Visible;
  335. ImgHeadImg.Visibility = Visibility.Collapsed;
  336. App.UserInfo = new ModelUserInfo();
  337. }
  338. #endregion 登录
  339. #region 设置
  340. /// <summary>
  341. /// 设置 浏览事件
  342. /// </summary>
  343. /// <param name="sender">
  344. /// </param>
  345. /// <param name="e">
  346. /// </param>
  347. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  348. {
  349. _fbd = new System.Windows.Forms.FolderBrowserDialog();
  350. _result2 = _fbd.ShowDialog();
  351. if (_result2 != System.Windows.Forms.DialogResult.OK)
  352. {
  353. return;
  354. }
  355. if (_fbd.SelectedPath != "")
  356. {
  357. TxbStoragePath.Content = _fbd.SelectedPath;
  358. }
  359. }
  360. /// <summary>
  361. /// 打开文件所在位置
  362. /// </summary>
  363. /// <param name="sender">
  364. /// </param>
  365. /// <param name="e">
  366. /// </param>
  367. private void btnOpen_Click(object sender, RoutedEventArgs e)
  368. {
  369. Process.Start(App.WKData.WkPath);
  370. }
  371. /// <summary>
  372. /// 设置 保存事件
  373. /// </summary>
  374. /// <param name="sender">
  375. /// </param>
  376. /// <param name="e">
  377. /// </param>
  378. private void BtnSave_Click(object sender, RoutedEventArgs e)
  379. {
  380. try
  381. {
  382. BtnRecord.IsEnabled = true; //设置结束时可录制
  383. if (RbnMp4.IsChecked == true)
  384. {
  385. //存储文件
  386. FileToolsCommon.SetConfigValue("VideoType", "1");
  387. }
  388. else if (RbnFlv.IsChecked == true)
  389. {
  390. FileToolsCommon.SetConfigValue("VideoType", "2");
  391. }
  392. else
  393. {
  394. FileToolsCommon.SetConfigValue("VideoType", "3");
  395. }
  396. UpdateHideSrToolConfig();
  397. // < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  398. if (RbnRight.IsChecked == true)
  399. {
  400. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  401. }
  402. else if (RbnLeft.IsChecked == true)
  403. {
  404. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  405. }
  406. else if (RbnRightUnder.IsChecked == true)
  407. {
  408. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  409. }
  410. else if (RbnLeftUnder.IsChecked == true)
  411. {
  412. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  413. }
  414. //格式
  415. if (RbnMp4.IsChecked == true)
  416. {
  417. FileToolsCommon.SetConfigValue("VideoType", "1");
  418. }
  419. else if (RbnFlv.IsChecked == true)
  420. {
  421. FileToolsCommon.SetConfigValue("VideoType", "2");
  422. }
  423. else if (RbnAvi.IsChecked == true)
  424. {
  425. FileToolsCommon.SetConfigValue("VideoType", "3");
  426. }
  427. App.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  428. GridMain.Visibility = Visibility.Visible;
  429. GridM.IsEnabled = true;
  430. GridRecordingTitle.Visibility = Visibility.Visible;
  431. GridSetUp.Visibility = Visibility.Collapsed;
  432. HeadImg.Visibility = Visibility.Hidden;
  433. if (_isRbnOpen)
  434. {
  435. HeadImg.Visibility = Visibility.Visible;
  436. }
  437. if (!TxbStoragePath.Content.ToString().Equals(App.WKData.WkPath))
  438. {
  439. //存储文件
  440. FileToolsCommon.SetConfigValue("VideoSavePath", TxbStoragePath.Content.ToString());
  441. MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
  442. }
  443. }
  444. catch (Exception ex)
  445. {
  446. LogHelper.Logerror.Error("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
  447. }
  448. }
  449. /// <summary>
  450. /// 设置事件
  451. /// </summary>
  452. /// <param name="sender">
  453. /// </param>
  454. /// <param name="e">
  455. /// </param>
  456. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  457. {
  458. if (GridSetUp.Visibility == Visibility.Collapsed)
  459. {
  460. PageHide();
  461. GridSetUp.Visibility = Visibility.Visible;
  462. TxbStoragePath.Content = App.WKData.WkPath;
  463. #region 读取用户配置
  464. // < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  465. if ("1".Equals(App.CameraPosition))
  466. {
  467. RbnRight.IsChecked = true;
  468. }
  469. else if ("2".Equals(App.CameraPosition))
  470. {
  471. RbnLeft.IsChecked = true;
  472. }
  473. else if ("3".Equals(App.CameraPosition))
  474. {
  475. RbnRightUnder.IsChecked = true;
  476. }
  477. else if ("4".Equals(App.CameraPosition))
  478. {
  479. RbnLeftUnder.IsChecked = true;
  480. }
  481. string type = FileToolsCommon.GetConfigValue("VideoType"); //<!--视频格式 1、MP4 2、FlV 3、AVI-->
  482. if ("1".Equals(type))
  483. {
  484. RbnMp4.IsChecked = true;
  485. }
  486. else if ("2".Equals(type))
  487. {
  488. RbnFlv.IsChecked = true;
  489. }
  490. else if ("3".Equals(type))
  491. {
  492. RbnAvi.IsChecked = true;
  493. }
  494. string isHide = FileToolsCommon.GetConfigValue("IsHideSRTool"); //工具栏是否隐藏
  495. if (isHide.Equals("1"))
  496. {
  497. RbnHide.IsChecked = true;
  498. }
  499. else
  500. {
  501. Rbnvisi.IsChecked = true;
  502. }
  503. //加载皮肤按钮
  504. SkinSelectInit();
  505. #endregion 读取用户配置
  506. }
  507. else
  508. {
  509. GridMain.Visibility = Visibility.Visible;
  510. GridM.IsEnabled = true;
  511. GridRecordingTitle.Visibility = Visibility.Visible;
  512. GridSetUp.Visibility = Visibility.Collapsed;
  513. }
  514. }
  515. /// <summary>
  516. /// 更新隐藏录屏工具栏隐藏状态
  517. /// </summary>
  518. private void UpdateHideSrToolConfig()
  519. {
  520. if (RbnHide.IsChecked == true)
  521. {
  522. //隐藏
  523. FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
  524. App.IsHideSRTool = true;
  525. }
  526. else
  527. {
  528. //显示
  529. FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
  530. App.IsHideSRTool = false;
  531. }
  532. }
  533. #region 切换皮肤
  534. /// <summary>
  535. /// 科技蓝
  536. /// </summary>
  537. /// <param name="sender">
  538. /// </param>
  539. /// <param name="e">
  540. /// </param>
  541. private void BtnSkinTechnologyBlue_Click(object sender, RoutedEventArgs e)
  542. {
  543. if (App.SkinStyle != "1")
  544. {
  545. HideSkinSelect();
  546. SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
  547. App.SkinStyle = "1";
  548. FileToolsCommon.SetConfigValue("SkinStyle", "1");
  549. SkinConfig.SwitchSkin(1);
  550. }
  551. }
  552. /// <summary>
  553. /// 白色
  554. /// </summary>
  555. /// <param name="sender">
  556. /// </param>
  557. /// <param name="e">
  558. /// </param>
  559. private void BtnSkinWhite_Click(object sender, RoutedEventArgs e)
  560. {
  561. if (App.SkinStyle != "0")
  562. {
  563. HideSkinSelect();
  564. SkinSelectWhite.Visibility = Visibility.Visible;
  565. App.SkinStyle = "0";
  566. FileToolsCommon.SetConfigValue("SkinStyle", "0");
  567. SkinConfig.SwitchSkin(0);
  568. }
  569. }
  570. /// <summary>
  571. /// 隐藏皮肤选择键
  572. /// </summary>
  573. private void HideSkinSelect()
  574. {
  575. SkinSelectWhite.Visibility = Visibility.Hidden;
  576. SkinSelectTechnologyBlue.Visibility = Visibility.Hidden;
  577. }
  578. /// <summary>
  579. /// 加载皮肤选项
  580. /// </summary>
  581. private void SkinSelectInit()
  582. {
  583. if (App.SkinStyle == "0")
  584. {
  585. HideSkinSelect();
  586. SkinSelectWhite.Visibility = Visibility.Visible;
  587. SkinConfig.SwitchSkin(0);
  588. }
  589. else if (App.SkinStyle == "1")
  590. {
  591. HideSkinSelect();
  592. SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
  593. SkinConfig.SwitchSkin(1);
  594. }
  595. else
  596. {
  597. HideSkinSelect();
  598. SkinSelectWhite.Visibility = Visibility.Visible;
  599. }
  600. }
  601. #endregion 切换皮肤
  602. #endregion 设置
  603. private bool _isHasCode;
  604. /// <summary>
  605. /// 加页事件
  606. /// </summary>
  607. /// <param name="sender">
  608. /// </param>
  609. /// <param name="e">
  610. /// </param>
  611. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  612. {
  613. _luoBoPenUtil.lb_device_hand();
  614. PrepareRecord();
  615. if (App.PageContextData.currpage > 0)
  616. {
  617. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = true;
  618. }
  619. if (BlackboardCanvas.Visibility == Visibility.Collapsed)
  620. {
  621. BlackboardCanvas.Visibility = Visibility.Visible;
  622. }
  623. App.PageContextData.pagenum += 1;
  624. HideAngleBorder();
  625. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  626. App.PageContextData.currpage = App.PageContextData.pagenum;
  627. myblackboard.Changepage(App.PageContextData.currpage - 1);
  628. ScroMain.ScrollToVerticalOffset(0);
  629. //清空页面图片UI
  630. ImgCanvas.Source = null;
  631. ImgDocumentation.Source = null;
  632. ImgPpt.Source = null;
  633. if (App.PageContextData.pagenum == 1)
  634. {
  635. App.PageDrawList = new List<ModelDrawData>();
  636. }
  637. //画板模型增加一页
  638. ModelDrawData modelDrawData = new ModelDrawData { PageNum = App.PageContextData.currpage };
  639. App.PageDrawList.Add(modelDrawData);
  640. if (_recordType == 0)
  641. {
  642. BtnPrint.IsEnabled = true;
  643. }
  644. if (BtnImport.IsEnabled)
  645. {
  646. //截图可用
  647. BtnScreenshot.IsEnabled = true;
  648. }
  649. }
  650. /// <summary>
  651. /// 关闭事件
  652. /// </summary>
  653. /// <param name="sender">
  654. /// </param>
  655. /// <param name="e">
  656. /// </param>
  657. private void BtnClose_Click(object sender, RoutedEventArgs e)
  658. {
  659. if (_recordType == 0)
  660. {
  661. try
  662. {
  663. MessageBoxResult br = MessageWindow.Show
  664. (
  665. "确定退出系统?",
  666. "退出",
  667. MessageBoxButton.OKCancel
  668. );
  669. if (br == MessageBoxResult.OK)
  670. {
  671. try
  672. {
  673. App.Killffmpeg();
  674. }
  675. catch (Exception ex)
  676. {
  677. LogHelper.Logerror.Error("获取进程失败," + ex.Message, ex);
  678. }
  679. App.SaveWkData();
  680. App.SaveDraw();
  681. _tmc.TmatrixUninitialize();
  682. Application.Current.Shutdown();
  683. }
  684. }
  685. catch (Exception ex)
  686. {
  687. LogHelper.Logerror.Error("关闭微课失败," + ex.Message, ex);
  688. Close();
  689. Application.Current.Shutdown();
  690. _tmc.TmatrixUninitialize();
  691. Application.Current.Shutdown();
  692. }
  693. }
  694. else
  695. {
  696. MessageWindow.Show("当前正在录制,请先停止录制。");
  697. }
  698. }
  699. /// <summary>
  700. /// 打印事件
  701. /// </summary>
  702. /// <param name="sender">
  703. /// </param>
  704. /// <param name="e">
  705. /// </param>
  706. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  707. {
  708. try
  709. {
  710. //3种情况 1.文档图片 2.截图图片 3.没有图片
  711. if (App.PageDrawList.Count == 0)
  712. {
  713. MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
  714. return;
  715. }
  716. }
  717. catch (Exception ex)
  718. {
  719. MessageWindow.Show(ex.Message);
  720. Console.WriteLine(@"转换失败,原因:" + ex.Message);
  721. }
  722. if (GridPrintingTitle.Visibility == Visibility.Visible)
  723. {
  724. GridPrintingTitle.Visibility = Visibility.Collapsed;
  725. }
  726. else
  727. {
  728. GridPrintingTitle.Visibility = Visibility.Visible;
  729. if (App.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(App.PageDrawList[0].PageImagePath))
  730. {
  731. InitializePrint
  732. (
  733. App.PageDrawList[0].PageImagePath,
  734. GridM.ActualWidth,
  735. GridM.ActualHeight
  736. );
  737. }
  738. else
  739. {
  740. InitializePrint
  741. (
  742. "",
  743. GridM.ActualWidth,
  744. _gridActHeight
  745. );
  746. }
  747. }
  748. }
  749. /// <summary>
  750. /// 打印
  751. /// </summary>
  752. /// <param name="sender">
  753. /// </param>
  754. /// <param name="e">
  755. /// </param>
  756. private void BtnPrint_Print_Click(object sender, RoutedEventArgs e)
  757. {
  758. _isHasCode = true;
  759. Print();
  760. }
  761. private void BtnPrintCloseClick(object sender, RoutedEventArgs e)
  762. {
  763. GridPrintingTitle.Visibility = Visibility.Collapsed;
  764. }
  765. /// <summary>
  766. /// 打印说明
  767. /// </summary>
  768. /// <param name="sender">
  769. /// </param>
  770. /// <param name="e">
  771. /// </param>
  772. private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
  773. {
  774. Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
  775. }
  776. private void PageHide()
  777. {
  778. //设置
  779. GridSetUp.Visibility = Visibility.Collapsed;
  780. //我的
  781. GridMyVideo.Visibility = Visibility.Collapsed;
  782. //首页
  783. GridMain.Visibility = Visibility.Collapsed;
  784. GridM.IsEnabled = true;
  785. //打印
  786. GridPrintContent.Visibility = Visibility.Collapsed;
  787. //标题 录制
  788. GridRecordingTitle.Visibility = Visibility.Collapsed;
  789. //标题 打印
  790. GridPrintingTitle.Visibility = Visibility.Collapsed;
  791. }
  792. private void Print()
  793. {
  794. if (!ZPrintUtils.IsExistAcroRd32())
  795. {
  796. MessageBoxResult dr = MessageWindow.Show
  797. (
  798. "需要安装PDF阅读器,是否下载安装?",
  799. "提示",
  800. MessageBoxButton.OKCancel
  801. );
  802. if (dr == MessageBoxResult.OK)
  803. {
  804. ZPrintUtils.InstallAcroRd32ByUser();
  805. }
  806. return;
  807. }
  808. BtnPrint.IsEnabled = false;
  809. PrintModel printmodel = new PrintModel();
  810. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  811. imgPath = imgPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
  812. printmodel.filepath = imgPath;
  813. //打印数量
  814. printmodel.num = 1;
  815. _printMsg = "准备中";
  816. _msgnum = 0;
  817. _num = 0;
  818. GridPrintMask.Visibility = Visibility.Visible;
  819. Task.Run
  820. (
  821. () =>
  822. {
  823. StartPrint(printmodel);
  824. }
  825. );
  826. _timesPrint = new System.Timers.Timer(100);
  827. _timesPrint.Elapsed += Times_ElapsedClick;
  828. _timesPrint.Start();
  829. _timesPrintMsg = new System.Timers.Timer(500);
  830. _timesPrintMsg.Elapsed += TimesPrintMsg_Elapsed;
  831. _timesPrintMsg.Start();
  832. GridPrintingTitle.Visibility = Visibility.Collapsed;
  833. }
  834. private void Print_No_Code_Click(object sender, RoutedEventArgs e)
  835. {
  836. _isHasCode = false;
  837. Print();
  838. }
  839. /// <summary>
  840. /// 窗体移动
  841. /// </summary>
  842. /// <param name="sender">
  843. /// </param>
  844. /// <param name="e">
  845. /// </param>
  846. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  847. {
  848. DragMove();
  849. }
  850. #region 摄像头
  851. private bool _isRbnOpen;
  852. /// <summary>
  853. /// 摄像头打开事件
  854. /// </summary>
  855. /// <param name="sender">
  856. /// </param>
  857. /// <param name="e">
  858. /// </param>
  859. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  860. {
  861. if (!_isRbnOpen)
  862. {
  863. #region 防止连击
  864. if (_isPressButton)
  865. {
  866. return;
  867. }
  868. _isPressButton = true;
  869. Task.Run
  870. (
  871. () =>
  872. {
  873. Thread.Sleep(3000);
  874. _isPressButton = false;
  875. }
  876. );
  877. #endregion 防止连击
  878. CameraHelper.UpdateCameraDevices();
  879. if (CameraHelper.CameraDevices.Count > 0)
  880. {
  881. if (string.IsNullOrWhiteSpace(App.CameraName))
  882. {
  883. App.CameraName = CameraHelper.CameraDevices[0].MonikerString;
  884. }
  885. int cameraIndex = 0;
  886. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  887. {
  888. if (CameraHelper.CameraDevices[i].MonikerString == App.CameraName)
  889. {
  890. cameraIndex = i;
  891. }
  892. }
  893. CameraHelper.imageCallback = LoadImage;
  894. CameraHelper.StartCameraDevice(cameraIndex, this.Dispatcher);
  895. _isRbnOpen = true;
  896. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  897. FileToolsCommon.CreateDirectory(imgPath);
  898. HeadImg.Visibility = Visibility.Visible;
  899. // < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  900. switch (App.CameraPosition)
  901. {
  902. case "1":
  903. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  904. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  905. break;
  906. case "2":
  907. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  908. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  909. break;
  910. case "3":
  911. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  912. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  913. break;
  914. case "4":
  915. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  916. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  917. break;
  918. }
  919. RbnTurnOff.IsEnabled = false;
  920. Task.Run
  921. (
  922. () =>
  923. {
  924. Thread.Sleep(3000);
  925. Dispatcher.Invoke
  926. (
  927. () =>
  928. {
  929. RbnTurnOff.IsEnabled = true;
  930. }
  931. );
  932. }
  933. );
  934. }
  935. }
  936. }
  937. /// <summary>
  938. /// 摄像头关闭事件
  939. /// </summary>
  940. /// <param name="sender">
  941. /// </param>
  942. /// <param name="e">
  943. /// </param>
  944. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  945. {
  946. if (_isRbnOpen)
  947. {
  948. #region 防止连击
  949. if (_isPressButton)
  950. {
  951. return;
  952. }
  953. _isPressButton = true;
  954. Task.Run
  955. (
  956. () =>
  957. {
  958. Thread.Sleep(300);
  959. _isPressButton = false;
  960. }
  961. );
  962. #endregion 防止连击
  963. _isRbnOpen = false;
  964. HeadImg.Visibility = Visibility.Hidden;
  965. RbnOpen.IsEnabled = false;
  966. CameraHelper.CloseDevice();
  967. RbnOpen.IsEnabled = true;
  968. }
  969. }
  970. #endregion 摄像头
  971. #region 设备检测
  972. /// <summary>
  973. /// 设备检测
  974. /// </summary>
  975. /// <param name="sender">
  976. /// </param>
  977. /// <param name="e">
  978. /// </param>
  979. private void BtnDevice_Click(object sender, RoutedEventArgs e)
  980. {
  981. if (_isRbnOpen)
  982. {
  983. MessageWindow.Show("请从应用右下角关闭摄像头后再进行设备检测!");
  984. return;
  985. }
  986. DeviceWindow deviceWin = new DeviceWindow();
  987. deviceWin.ShowDialog();
  988. }
  989. #endregion 设备检测
  990. #endregion 事件
  991. #region 画笔
  992. /// <summary>
  993. /// 画笔颜色事件 蓝色
  994. /// </summary>
  995. /// <param name="sender">
  996. /// </param>
  997. /// <param name="e">
  998. /// </param>
  999. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  1000. {
  1001. _drawingAttributes.Color = Colors.DeepSkyBlue;
  1002. _color = Colors.DeepSkyBlue;
  1003. ImgRed.Visibility = Visibility.Collapsed;
  1004. ImgGray.Visibility = Visibility.Collapsed;
  1005. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1006. ImgYellow.Visibility = Visibility.Collapsed;
  1007. ImgBlue.Visibility = Visibility.Visible;
  1008. }
  1009. /// <summary>
  1010. /// 画笔颜色事件 青色
  1011. /// </summary>
  1012. /// <param name="sender">
  1013. /// </param>
  1014. /// <param name="e">
  1015. /// </param>
  1016. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  1017. {
  1018. _drawingAttributes.Color = Colors.LimeGreen;
  1019. _color = Colors.LimeGreen;
  1020. ImgRed.Visibility = Visibility.Collapsed;
  1021. ImgGray.Visibility = Visibility.Collapsed;
  1022. ImgCyanBlue.Visibility = Visibility.Visible;
  1023. ImgYellow.Visibility = Visibility.Collapsed;
  1024. ImgBlue.Visibility = Visibility.Collapsed;
  1025. }
  1026. /// <summary>
  1027. /// 画笔颜色事件 黑色
  1028. /// </summary>
  1029. /// <param name="sender">
  1030. /// </param>
  1031. /// <param name="e">
  1032. /// </param>
  1033. private void BtnGray_Click(object sender, RoutedEventArgs e)
  1034. {
  1035. _drawingAttributes.Color = Colors.Black;
  1036. _color = Colors.Black;
  1037. ImgRed.Visibility = Visibility.Collapsed;
  1038. ImgGray.Visibility = Visibility.Visible;
  1039. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1040. ImgYellow.Visibility = Visibility.Collapsed;
  1041. ImgBlue.Visibility = Visibility.Collapsed;
  1042. }
  1043. /// <summary>
  1044. /// 画笔颜色事件 红色
  1045. /// </summary>
  1046. /// <param name="sender">
  1047. /// </param>
  1048. /// <param name="e">
  1049. /// </param>
  1050. private void BtnRed_Click(object sender, RoutedEventArgs e)
  1051. {
  1052. //设置 DrawingAttributes 的 Color 属性设置颜色
  1053. _drawingAttributes.Color = Colors.Red;
  1054. _color = Colors.Red;
  1055. ImgRed.Visibility = Visibility.Visible;
  1056. ImgGray.Visibility = Visibility.Collapsed;
  1057. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1058. ImgYellow.Visibility = Visibility.Collapsed;
  1059. ImgBlue.Visibility = Visibility.Collapsed;
  1060. }
  1061. /// <summary>
  1062. /// 画笔颜色事件 白色
  1063. /// </summary>
  1064. /// <param name="sender">
  1065. /// </param>
  1066. /// <param name="e">
  1067. /// </param>
  1068. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  1069. {
  1070. _drawingAttributes.Color = Colors.White;
  1071. _color = Colors.White;
  1072. }
  1073. /// <summary>
  1074. /// 画笔颜色事件 黄色
  1075. /// </summary>
  1076. /// <param name="sender">
  1077. /// </param>
  1078. /// <param name="e">
  1079. /// </param>
  1080. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  1081. {
  1082. _drawingAttributes.Color = Colors.Gold;
  1083. _color = Colors.Gold;
  1084. ImgRed.Visibility = Visibility.Collapsed;
  1085. ImgGray.Visibility = Visibility.Collapsed;
  1086. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1087. ImgYellow.Visibility = Visibility.Visible;
  1088. ImgBlue.Visibility = Visibility.Collapsed;
  1089. }
  1090. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1091. {
  1092. _mouseDown = true;
  1093. _imageOperationUtil.SetMouseDown(_mouseDown);
  1094. }
  1095. /// <summary>
  1096. /// 画笔粗细事件 粗
  1097. /// </summary>
  1098. /// <param name="sender">
  1099. /// </param>
  1100. /// <param name="e">
  1101. /// </param>
  1102. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  1103. {
  1104. _drawingAttributes.Width = 5;
  1105. _drawingAttributes.Height = 5;
  1106. _penSize = 5;
  1107. }
  1108. /// <summary>
  1109. /// 画笔粗细事件 细
  1110. /// </summary>
  1111. /// <param name="sender">
  1112. /// </param>
  1113. /// <param name="e">
  1114. /// </param>
  1115. private void RbnFine_Click(object sender, RoutedEventArgs e)
  1116. {
  1117. _drawingAttributes.Width = 1;
  1118. _drawingAttributes.Height = 1;
  1119. _penSize = 1;
  1120. }
  1121. /// <summary>
  1122. /// 画笔粗细事件 中
  1123. /// </summary>
  1124. /// <param name="sender">
  1125. /// </param>
  1126. /// <param name="e">
  1127. /// </param>
  1128. private void RbnIn_Click(object sender, RoutedEventArgs e)
  1129. {
  1130. _drawingAttributes.Width = 3;
  1131. _drawingAttributes.Height = 3;
  1132. _penSize = 3;
  1133. }
  1134. #endregion 画笔
  1135. #region 导入截图
  1136. /// <summary>
  1137. /// 防止图片地址重复
  1138. /// </summary>
  1139. private long _wordImgNum = 9999;
  1140. /// <summary>
  1141. /// 返回一个时间戳到毫秒
  1142. /// </summary>
  1143. /// <returns>
  1144. /// </returns>
  1145. public static long Timestamp()
  1146. {
  1147. TimeSpan ts = DateTime.UtcNow
  1148. - new DateTime
  1149. (
  1150. 1970,
  1151. 1,
  1152. 1,
  1153. 0,
  1154. 0,
  1155. 0,
  1156. 0
  1157. );
  1158. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1159. return timestr;
  1160. }
  1161. /// <summary>
  1162. /// 获取时间戳
  1163. /// </summary>
  1164. /// <returns>
  1165. /// </returns>
  1166. public string GetTimeStamp()
  1167. {
  1168. TimeSpan ts = DateTime.Now
  1169. - new DateTime
  1170. (
  1171. 1970,
  1172. 1,
  1173. 1,
  1174. 0,
  1175. 0,
  1176. 0,
  1177. 0
  1178. );
  1179. return Convert.ToInt64(ts.TotalSeconds).ToString();
  1180. }
  1181. /// <summary>
  1182. /// 导入-结束
  1183. /// </summary>
  1184. /// <returns>
  1185. /// </returns>
  1186. public void InvokeServerCompate(object obj)
  1187. {
  1188. //APP.myloading.Hide();
  1189. App.myloading.Hide();
  1190. }
  1191. public void WindowType()
  1192. {
  1193. this.Activate();
  1194. }
  1195. /// <summary>
  1196. /// 导入事件
  1197. /// </summary>
  1198. /// <param name="sender">
  1199. /// </param>
  1200. /// <param name="e">
  1201. /// </param>
  1202. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1203. {
  1204. try
  1205. {
  1206. PrepareRecord();
  1207. HideAngleBorder();
  1208. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1209. _ofd = new System.Windows.Forms.OpenFileDialog
  1210. {
  1211. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1212. //增加导入图片
  1213. Filter = @"文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1214. InitialDirectory = desktopPath,
  1215. Multiselect = false,
  1216. AddExtension = true,
  1217. DereferenceLinks = true
  1218. };
  1219. App.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1220. }
  1221. catch (Exception ex)
  1222. {
  1223. LogHelper.Logerror.Error("【导入(BtnImport_Click)" + ex.Message, ex);
  1224. }
  1225. }
  1226. /// <summary>
  1227. /// 截图事件
  1228. /// </summary>
  1229. /// <param name="sender">
  1230. /// </param>
  1231. /// <param name="e">
  1232. /// </param>
  1233. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  1234. {
  1235. if (_recordType == 4)
  1236. {
  1237. return;
  1238. }
  1239. JietuAction();
  1240. }
  1241. private async void JietuAction()
  1242. {
  1243. PrepareRecord();
  1244. HideAngleBorder();
  1245. if (WindowState == WindowState.Normal) //截图隐藏窗口
  1246. {
  1247. WindowState = WindowState.Minimized;
  1248. }
  1249. await Task.Delay(300);
  1250. ImgCanvas.Margin = new Thickness
  1251. (
  1252. 0,
  1253. 0,
  1254. 0,
  1255. 0
  1256. );
  1257. App.ImgPath = string.Empty;
  1258. string time = GetTimeStamp();
  1259. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  1260. App.ImgPath = desktopPath;
  1261. ImageHelper.GetScreenshot
  1262. (
  1263. new Rectangle
  1264. (
  1265. 0,
  1266. 0,
  1267. 0,
  1268. 0
  1269. )
  1270. {
  1271. Location = default,
  1272. Size = default
  1273. },
  1274. desktopPath,
  1275. false,
  1276. out var _
  1277. );
  1278. _kHook.Stop();
  1279. if (App.W_JieTuWindow != null)
  1280. {
  1281. App.W_JieTuWindow.initialization();
  1282. App.W_JieTuWindow.Screenshot();
  1283. App.W_JieTuWindow.InitializeKeyDownEvent();
  1284. App.W_JieTuWindow.WindowState = WindowState.Maximized;
  1285. App.W_JieTuWindow.Visibility = Visibility.Visible;
  1286. }
  1287. else
  1288. {
  1289. App.W_JieTuWindow = new JieTuWindow();
  1290. App.W_JieTuWindow.InitializeKeyDownEvent();
  1291. // 订阅事件
  1292. App.W_JieTuWindow.ChangeTextEvent += frm_ChangeTextEvent;
  1293. App.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  1294. App.W_JieTuWindow.Show();
  1295. }
  1296. }
  1297. /// <summary>
  1298. /// 截图关闭窗口
  1299. /// </summary>
  1300. /// <param name="text">
  1301. /// </param>
  1302. private void frm_ChangeTextEvent(string text)
  1303. {
  1304. if ("关闭窗口".Equals(text))
  1305. {
  1306. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1307. {
  1308. WindowState = WindowState.Normal;
  1309. Activate();
  1310. }
  1311. InitializeKeyDownEvent();
  1312. if (!string.IsNullOrWhiteSpace(App.ImgPath) && File.Exists(App.ImgPath))
  1313. {
  1314. if (App.PageContextData.currpage == 0)
  1315. {
  1316. App.PageContextData.pagenum += 1;
  1317. App.PageContextData.currpage = App.PageContextData.pagenum;
  1318. myblackboard.Changepage(App.PageContextData.currpage - 1);
  1319. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1320. #region 插入页码
  1321. #endregion 插入页码
  1322. }
  1323. if (App.PageDrawList.Count >= App.PageContextData.currpage)
  1324. {
  1325. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
  1326. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
  1327. }
  1328. else
  1329. {
  1330. ModelDrawData modelDrawData = new ModelDrawData { PageImagePath = App.ImgPath, PdfImagePath = App.ImgPath };
  1331. App.PageDrawList.Add(modelDrawData);
  1332. }
  1333. if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  1334. {
  1335. ImgDocumentation.Source = null;
  1336. BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1337. _mouseDown = false;
  1338. _imageOperationUtil.SetMouseDown(_mouseDown);
  1339. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1340. {
  1341. X = 0.1,
  1342. Y = 0.1
  1343. };
  1344. App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
  1345. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  1346. ImgCanvas.Source = bitImg;
  1347. ImgCanvas.Width = bitImg.Width;
  1348. ImgCanvas.Height = bitImg.Height;
  1349. ScroMain.ScrollToVerticalOffset(0);
  1350. App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1351. {
  1352. CenterX = ImgCanvas.Width,
  1353. CenterY = ImgCanvas.Height
  1354. };
  1355. BtnPrint.IsEnabled = true;
  1356. }
  1357. }
  1358. }
  1359. else if ("取消".Equals(text))
  1360. {
  1361. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1362. {
  1363. WindowState = WindowState.Normal;
  1364. }
  1365. }
  1366. }
  1367. /// <summary>
  1368. /// 导入-开始
  1369. /// </summary>
  1370. /// <returns>
  1371. /// </returns>
  1372. private object InvokeServering()
  1373. {
  1374. Dispatcher.Invoke
  1375. (
  1376. () =>
  1377. {
  1378. _result = _ofd.ShowDialog();
  1379. }
  1380. );
  1381. if (_result == System.Windows.Forms.DialogResult.OK)
  1382. {
  1383. if (_ofd.FileName != "")
  1384. {
  1385. List<string> imagelist = new List<string>()
  1386. {
  1387. "jpg",
  1388. "jpeg",
  1389. "png",
  1390. "bmp"
  1391. };
  1392. Dispatcher.Invoke
  1393. (
  1394. () =>
  1395. {
  1396. App.myloading.Show();
  1397. myblackboard.Changepage(App.PageContextData.pagenum);
  1398. }
  1399. );
  1400. string filepath = _ofd.FileName;
  1401. string filesuff = filepath.Substring(filepath.LastIndexOf(".", StringComparison.Ordinal) + 1).ToLower();
  1402. if (_ofd.SafeFileName != null)
  1403. {
  1404. string path = _ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1405. string type = _ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1406. if (type.Contains("typezsygppt")) //ppt
  1407. {
  1408. try
  1409. {
  1410. #region PPT转PDF
  1411. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1412. path = pathTemp + path + ".pdf";
  1413. FileToolsCommon.CreateDirectory(pathTemp);
  1414. //PPT转PDF
  1415. Presentation ppt = new Presentation(filepath);
  1416. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1417. #endregion PPT转PDF
  1418. #region PDF转图片
  1419. // 图片绝对路径集合
  1420. List<string> images = new List<string>();
  1421. string directoryPath = pathTemp;
  1422. //定义Jpeg转换设备
  1423. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(path);
  1424. Directory.CreateDirectory(directoryPath);
  1425. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1426. var device = new Aspose.Pdf.Devices.JpegDevice(100);
  1427. //遍历每一页转为jpg
  1428. for (int i = 1; i <= pdfDoc.Pages.Count; i++)
  1429. {
  1430. long ii = Timestamp();
  1431. string filePathOutPut = Path.Combine
  1432. (
  1433. directoryPath,
  1434. string.Format
  1435. (
  1436. "{0}{1}.jpg",
  1437. ii,
  1438. i
  1439. )
  1440. );
  1441. images.Add(filePathOutPut);
  1442. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1443. try
  1444. {
  1445. device.Process(pdfDoc.Pages[i], fs);
  1446. fs.Close();
  1447. }
  1448. catch (Exception)
  1449. {
  1450. fs.Close();
  1451. File.Delete(filePathOutPut);
  1452. }
  1453. }
  1454. #endregion PDF转图片
  1455. Dispatcher.Invoke
  1456. (
  1457. () =>
  1458. {
  1459. string[] page = images.ToArray();
  1460. int num = 0;
  1461. int iStart = App.PageContextData.pagenum; //导入文档的开始下标
  1462. int iEnd = page.Length + App.PageContextData.pagenum; //导入文档的结束下标
  1463. for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1464. {
  1465. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1466. {
  1467. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1468. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1469. App.PageDrawList[i].PageNum = i + 1;
  1470. App.PageDrawList[i].ImgDocumentation = true;
  1471. App.PageDrawList[i].Type = "ppt";
  1472. }
  1473. else
  1474. {
  1475. ModelDrawData modelDrawData = new ModelDrawData
  1476. {
  1477. PageImagePath = page[i - App.PageContextData.pagenum],
  1478. PdfImagePath = page[i - App.PageContextData.pagenum],
  1479. PageNum = i + 1,
  1480. ImgDocumentation = true,
  1481. Type = "ppt"
  1482. };
  1483. if (App.PageDrawList != null)
  1484. {
  1485. App.PageDrawList.Add(modelDrawData);
  1486. }
  1487. }
  1488. BtnPrint.IsEnabled = true;
  1489. App.SaveDraw();
  1490. num++;
  1491. }
  1492. if (num > 0)
  1493. {
  1494. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1495. App.PageContextData.pagenum += num;
  1496. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1497. }
  1498. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1499. {
  1500. ImgCanvas.Source = null;
  1501. BtnScreenshot.IsEnabled = false;
  1502. ImgDocumentation.Source = null;
  1503. ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1504. ScroMain.ScrollToVerticalOffset(0);
  1505. for (int i = iStart; i < iEnd; i++)
  1506. {
  1507. App.PageDrawList[i].ImageLocation = new TranslateTransform
  1508. {
  1509. X = 0.1,
  1510. Y = 0.1
  1511. };
  1512. App.PageDrawList[i].IsImageLocation = true;
  1513. App.PageDrawList[i].ImageSizes = new ScaleTransform
  1514. {
  1515. CenterX = ImgCanvas.Width,
  1516. CenterY = ImgCanvas.Height
  1517. };
  1518. }
  1519. }
  1520. else
  1521. {
  1522. ImgDocumentation.Source = null;
  1523. ImgCanvas.Source = null;
  1524. ImgPpt.Source = null;
  1525. //截图可用
  1526. BtnScreenshot.IsEnabled = true;
  1527. }
  1528. }
  1529. );
  1530. }
  1531. catch (Exception ex)
  1532. {
  1533. Dispatcher.Invoke
  1534. (
  1535. () =>
  1536. {
  1537. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1538. }
  1539. );
  1540. LogHelper.Logerror.Error("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1541. }
  1542. }
  1543. else if (type.Contains("typepdf"))
  1544. {
  1545. try
  1546. {
  1547. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1548. #region PDF转图片
  1549. // 图片绝对路径集合
  1550. List<string> images = new List<string>();
  1551. string directoryPath = pathTemp;
  1552. //aspose许可证
  1553. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1554. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1555. //l.SetLicense(licenseName);
  1556. //定义Jpeg转换设备
  1557. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(filepath);
  1558. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1559. //directoryPath += quality;
  1560. Directory.CreateDirectory(directoryPath);
  1561. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1562. var device = new Aspose.Pdf.Devices.JpegDevice(100);
  1563. //遍历每一页转为jpg
  1564. for (int i = 1; i <= pdfDoc.Pages.Count; i++)
  1565. {
  1566. long ii = Timestamp();
  1567. string filePathOutPut = Path.Combine
  1568. (
  1569. directoryPath,
  1570. string.Format
  1571. (
  1572. "{0}{1}.jpg",
  1573. ii,
  1574. i
  1575. )
  1576. );
  1577. images.Add(filePathOutPut);
  1578. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1579. try
  1580. {
  1581. device.Process(pdfDoc.Pages[i], fs);
  1582. fs.Close();
  1583. }
  1584. catch (Exception)
  1585. {
  1586. fs.Close();
  1587. File.Delete(filePathOutPut);
  1588. }
  1589. }
  1590. #endregion PDF转图片
  1591. string[] page = images.ToArray();
  1592. int num = 0;
  1593. Dispatcher.Invoke
  1594. (
  1595. () =>
  1596. {
  1597. for (int i = App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1598. {
  1599. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1600. {
  1601. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1602. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1603. App.PageDrawList[i].PageNum = i + 1;
  1604. App.PageDrawList[i].ImgDocumentation = true;
  1605. App.PageDrawList[i].Type = "word";
  1606. }
  1607. else
  1608. {
  1609. ModelDrawData modelDrawData = new ModelDrawData
  1610. {
  1611. PageImagePath = page[i - App.PageContextData.pagenum],
  1612. PdfImagePath = page[i - App.PageContextData.pagenum],
  1613. PageNum = i + 1,
  1614. ImgDocumentation = true,
  1615. Type = "word"
  1616. };
  1617. if (App.PageDrawList != null)
  1618. {
  1619. App.PageDrawList.Add(modelDrawData);
  1620. }
  1621. }
  1622. BtnPrint.IsEnabled = true;
  1623. App.SaveDraw();
  1624. num++;
  1625. }
  1626. if (num > 0)
  1627. {
  1628. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1629. App.PageContextData.pagenum += num;
  1630. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1631. }
  1632. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1633. {
  1634. ImgCanvas.Source = null;
  1635. ImgPpt.Source = null;
  1636. BtnScreenshot.IsEnabled = false;
  1637. ImgDocumentation.Visibility = Visibility.Visible;
  1638. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
  1639. ScroMain.ScrollToVerticalOffset(0);
  1640. }
  1641. else
  1642. {
  1643. ImgDocumentation.Source = null;
  1644. ImgCanvas.Source = null;
  1645. ImgPpt.Source = null;
  1646. //截图可用
  1647. BtnScreenshot.IsEnabled = true;
  1648. }
  1649. }
  1650. );
  1651. }
  1652. catch (Exception ex)
  1653. {
  1654. Dispatcher.Invoke
  1655. (
  1656. () =>
  1657. {
  1658. MessageWindow.Show(ex.Message);
  1659. }
  1660. );
  1661. LogHelper.Logerror.Error("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1662. }
  1663. }
  1664. else if (imagelist.Contains(filesuff)) //导入图片
  1665. {
  1666. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1667. if (!Directory.Exists(imagepath))
  1668. {
  1669. Directory.CreateDirectory(imagepath);
  1670. }
  1671. TimeSpan ts = DateTime.UtcNow
  1672. - new DateTime
  1673. (
  1674. 1970,
  1675. 1,
  1676. 1,
  1677. 0,
  1678. 0,
  1679. 0,
  1680. 0
  1681. );
  1682. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1683. string filepathCopy = Path.Combine(imagepath, timestr + _ofd.SafeFileName);
  1684. File.Copy(filepath, filepathCopy);
  1685. filepath = filepathCopy;
  1686. App.ImgPath = filepath;
  1687. Dispatcher.Invoke
  1688. (
  1689. () =>
  1690. {
  1691. if (App.PageContextData.currpage == 0)
  1692. {
  1693. App.PageContextData.pagenum += 1;
  1694. App.PageContextData.currpage = App.PageContextData.pagenum;
  1695. myblackboard.Changepage(App.PageContextData.currpage - 1);
  1696. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1697. #region 插入页码
  1698. #endregion 插入页码
  1699. }
  1700. else
  1701. {
  1702. App.PageContextData.pagenum += 1;
  1703. App.PageContextData.currpage = App.PageContextData.pagenum;
  1704. myblackboard.Changepage(App.PageContextData.currpage - 1);
  1705. }
  1706. if (App.PageDrawList.Count >= App.PageContextData.currpage)
  1707. {
  1708. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
  1709. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
  1710. }
  1711. else
  1712. {
  1713. ModelDrawData modelDrawData = new ModelDrawData { PageImagePath = App.ImgPath, PdfImagePath = App.ImgPath };
  1714. App.PageDrawList.Add(modelDrawData);
  1715. }
  1716. if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  1717. {
  1718. ImgDocumentation.Source = null;
  1719. BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1720. _mouseDown = false;
  1721. _imageOperationUtil.SetMouseDown(_mouseDown);
  1722. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1723. {
  1724. X = 0.1,
  1725. Y = 0.1
  1726. };
  1727. App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
  1728. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  1729. ImgCanvas.Source = bitImg;
  1730. ImgCanvas.Width = bitImg.Width;
  1731. ImgCanvas.Height = bitImg.Height;
  1732. ScroMain.ScrollToVerticalOffset(0);
  1733. ImgCanvas.Margin = new Thickness
  1734. (
  1735. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
  1736. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
  1737. 0,
  1738. 0
  1739. );
  1740. App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1741. {
  1742. CenterX = ImgCanvas.Width,
  1743. CenterY = ImgCanvas.Height
  1744. };
  1745. BtnPrint.IsEnabled = true;
  1746. }
  1747. }
  1748. );
  1749. }
  1750. else //word
  1751. {
  1752. try
  1753. {
  1754. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1755. _wordImgNum += 1;
  1756. string[] page = ZAsposeUtil.ConvertWordToImage
  1757. (
  1758. filepath,
  1759. paths,
  1760. "" + _wordImgNum
  1761. )
  1762. .ToArray();
  1763. int num = 0;
  1764. Dispatcher.Invoke
  1765. (
  1766. () =>
  1767. {
  1768. for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1769. {
  1770. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1771. {
  1772. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1773. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1774. App.PageDrawList[i].PageNum = i + 1;
  1775. App.PageDrawList[i].ImgDocumentation = true;
  1776. App.PageDrawList[i].Type = "word";
  1777. }
  1778. else
  1779. {
  1780. ModelDrawData modelDrawData = new ModelDrawData
  1781. {
  1782. PageImagePath = page[i - App.PageContextData.pagenum],
  1783. PdfImagePath = page[i - App.PageContextData.pagenum],
  1784. PageNum = i + 1,
  1785. ImgDocumentation = true,
  1786. Type = "word"
  1787. };
  1788. if (App.PageDrawList != null)
  1789. {
  1790. App.PageDrawList.Add(modelDrawData);
  1791. }
  1792. }
  1793. BtnPrint.IsEnabled = true;
  1794. App.SaveDraw();
  1795. num++;
  1796. }
  1797. if (num > 0)
  1798. {
  1799. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1800. App.PageContextData.pagenum += num;
  1801. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1802. }
  1803. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1804. {
  1805. ImgCanvas.Source = null;
  1806. ImgPpt.Source = null;
  1807. BtnScreenshot.IsEnabled = false;
  1808. ImgDocumentation.Visibility = Visibility.Visible;
  1809. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
  1810. ScroMain.ScrollToVerticalOffset(0);
  1811. }
  1812. else
  1813. {
  1814. ImgDocumentation.Source = null;
  1815. ImgCanvas.Source = null;
  1816. ImgPpt.Source = null;
  1817. //截图可用
  1818. BtnScreenshot.IsEnabled = true;
  1819. }
  1820. }
  1821. );
  1822. }
  1823. catch (Exception ex)
  1824. {
  1825. Dispatcher.Invoke
  1826. (
  1827. () =>
  1828. {
  1829. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1830. }
  1831. );
  1832. LogHelper.Logerror.Error("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1833. }
  1834. }
  1835. }
  1836. #region 插入页码
  1837. #endregion 插入页码
  1838. }
  1839. }
  1840. //OpenDialog();
  1841. return "";
  1842. }
  1843. /// <summary>
  1844. /// 截图关闭 非正常关闭截图时,截图清空
  1845. /// </summary>
  1846. private void JietuWindow_click_closeJietuWindowClick()
  1847. {
  1848. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1849. {
  1850. WindowState = WindowState.Normal;
  1851. }
  1852. App.W_JieTuWindow = null;
  1853. }
  1854. #region 导入转换图片
  1855. #endregion 导入转换图片
  1856. #endregion 导入截图
  1857. #region 上传 列表
  1858. /// <summary>
  1859. /// 搜索集合匹配的索引
  1860. /// </summary>
  1861. /// <typeparam name="T">
  1862. /// </typeparam>
  1863. /// <param name="parent">
  1864. /// </param>
  1865. /// <param name="childName">
  1866. /// </param>
  1867. /// <returns>
  1868. /// </returns>
  1869. public static List<T> FindChilds<T>(DependencyObject parent, string childName) where T : DependencyObject
  1870. {
  1871. List<T> list = new List<T>();
  1872. if (parent == null)
  1873. {
  1874. return list;
  1875. }
  1876. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  1877. for (int i = 0; i < childrenCount; i++)
  1878. {
  1879. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  1880. // 如果子控件不是需查找的控件类型
  1881. T childType = child as T;
  1882. if (childType == null)
  1883. {
  1884. // 在下一级控件中递归查找
  1885. FindChilds<T>(child, childName);
  1886. list.AddRange(FindChilds<T>(child, childName));
  1887. }
  1888. else if (!string.IsNullOrEmpty(childName))
  1889. {
  1890. FrameworkElement frameworkElement = child as FrameworkElement;
  1891. // 如果控件名称符合参数条件
  1892. if (frameworkElement != null && frameworkElement.Name == childName)
  1893. {
  1894. list.Add((T)child);
  1895. }
  1896. }
  1897. else
  1898. {
  1899. // 查找到了控件
  1900. list.Add((T)child);
  1901. }
  1902. }
  1903. return list;
  1904. }
  1905. /// <summary>
  1906. /// 加载视频列表
  1907. /// </summary>
  1908. public void LoadingVideoList()
  1909. {
  1910. try
  1911. {
  1912. _modelVideoList = new List<ModelVideo>();
  1913. foreach (ModelWkData vdata in App.WKDataList)
  1914. {
  1915. #region 计时器初始化
  1916. if (vdata.VideoList == null)
  1917. {
  1918. continue;
  1919. }
  1920. foreach (ModelVideo videoinfo in vdata.VideoList)
  1921. {
  1922. try
  1923. {
  1924. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  1925. {
  1926. continue;
  1927. }
  1928. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  1929. {
  1930. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMb(videoinfo.VideoPath).ToString(CultureInfo.InvariantCulture) + " MB";
  1931. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  1932. }
  1933. _modelVideoList.Add(videoinfo);
  1934. }
  1935. catch (Exception ex)
  1936. {
  1937. LogHelper.Logerror.Error("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1938. }
  1939. }
  1940. #endregion 计时器初始化
  1941. }
  1942. //翻转
  1943. if (_modelVideoList.Count > 1)
  1944. {
  1945. _modelVideoList.Reverse();
  1946. }
  1947. }
  1948. catch (Exception ex)
  1949. {
  1950. LogHelper.Logerror.Error("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1951. }
  1952. }
  1953. /// <summary>
  1954. /// 上传事件
  1955. /// </summary>
  1956. /// <param name="sender">
  1957. /// </param>
  1958. /// <param name="e">
  1959. /// </param>
  1960. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  1961. {
  1962. if (GridMyVideo.Visibility == Visibility.Visible)
  1963. {
  1964. GridMyVideo.Visibility = Visibility.Collapsed;
  1965. GridMain.Visibility = Visibility.Visible;
  1966. GridM.IsEnabled = true;
  1967. GridRecordingTitle.Visibility = Visibility.Visible;
  1968. }
  1969. else
  1970. {
  1971. PageHide();
  1972. GridMyVideo.Visibility = Visibility.Visible;
  1973. LoadUploadInitData();
  1974. }
  1975. }
  1976. #endregion 上传 列表
  1977. #region 新上传 显示缩略图
  1978. #region 初始值
  1979. private readonly double _controlHeight = 260;
  1980. private readonly double _controlWidth = 250;
  1981. /// <summary>
  1982. /// 当前页
  1983. /// </summary>
  1984. private int _currentPage = 1;
  1985. /// <summary>
  1986. /// 横向间隔
  1987. /// </summary>
  1988. private double _intervalX;
  1989. /// <summary>
  1990. /// 纵向间隔
  1991. /// </summary>
  1992. private double _intervalY;
  1993. /// <summary>
  1994. /// 页面高
  1995. /// </summary>
  1996. private double _pageH;
  1997. /// <summary>
  1998. /// 每页显示的视频数
  1999. /// </summary>
  2000. private int _pageShowNum;
  2001. /// <summary>
  2002. /// 页面宽
  2003. /// </summary>
  2004. private double _pageW;
  2005. /// <summary>
  2006. /// 总页数
  2007. /// </summary>
  2008. private int _totalPage;
  2009. /// <summary>
  2010. /// 视频信息列表
  2011. /// </summary>
  2012. private readonly List<Uc_VideoItem> _videoControlList = new List<Uc_VideoItem>();
  2013. #endregion 初始值
  2014. /// <summary>
  2015. /// 加载当前页数据
  2016. /// </summary>
  2017. private void LoadCurrentPageData()
  2018. {
  2019. LblVideoPageNum.Content = _currentPage + "/" + _totalPage;
  2020. //隐藏显示的控件
  2021. if (_videoControlList.Count > 0)
  2022. {
  2023. foreach (Uc_VideoItem item in _videoControlList)
  2024. {
  2025. if (item.Visibility != Visibility.Hidden)
  2026. {
  2027. item.Visibility = Visibility.Hidden;
  2028. }
  2029. }
  2030. }
  2031. double w = _intervalX; //每次增加250
  2032. double h = _intervalY; //每次增加260
  2033. //加载控件
  2034. for (int i = 0; i < _pageShowNum; i++)
  2035. {
  2036. int dataIndex = (_currentPage - 1) * _pageShowNum + i;
  2037. if (dataIndex == _modelVideoList.Count)
  2038. {
  2039. return;
  2040. }
  2041. Uc_VideoItem videoItem;
  2042. if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
  2043. {
  2044. videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
  2045. }
  2046. else
  2047. {
  2048. if (!FileToolsCommon.IsExistFile(_modelVideoList[dataIndex].ThumbnailPath))
  2049. {
  2050. continue;
  2051. }
  2052. videoItem = new Uc_VideoItem(_modelVideoList[dataIndex]) { Tag = _modelVideoList[dataIndex].FileGuid };
  2053. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2054. videoItem.Click_UploadLogin += Login;
  2055. videoItem.Width = _controlWidth;
  2056. videoItem.Height = _controlHeight;
  2057. videoItem.HorizontalAlignment = HorizontalAlignment.Left;
  2058. videoItem.VerticalAlignment = VerticalAlignment.Top;
  2059. GridMyVideo.Children.Add(videoItem);
  2060. _videoControlList.Add(videoItem);
  2061. }
  2062. videoItem.Margin = new Thickness
  2063. (
  2064. w,
  2065. h,
  2066. 0,
  2067. 0
  2068. );
  2069. videoItem.Visibility = Visibility.Visible;
  2070. if (w + _controlWidth + _controlWidth > _pageW)
  2071. {
  2072. w = _intervalX;
  2073. h += _controlHeight + _intervalY;
  2074. }
  2075. else
  2076. {
  2077. w += _controlWidth + _intervalX;
  2078. }
  2079. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2080. //return;
  2081. }
  2082. }
  2083. /// <summary>
  2084. /// 初始化加载上传页面数据
  2085. /// </summary>
  2086. private void LoadUploadInitData()
  2087. {
  2088. App.myloading.Show();
  2089. //加载视频列表
  2090. LoadingVideoList();
  2091. if (_modelVideoList.Count > 0)
  2092. {
  2093. LblVideoMess.Visibility = Visibility.Hidden;
  2094. BtnVideoUpPage.Visibility = Visibility.Visible;
  2095. LblVideoPageNum.Visibility = Visibility.Visible;
  2096. BtnVideoDownPage.Visibility = Visibility.Visible;
  2097. if (GridMyVideo.ActualHeight > 0)
  2098. {
  2099. _pageW = GridMyVideo.ActualWidth;
  2100. _pageH = GridMyVideo.ActualHeight;
  2101. }
  2102. else
  2103. {
  2104. _pageW = GridRecordingArea.ActualWidth;
  2105. _pageH = GridRecordingArea.ActualHeight;
  2106. }
  2107. //获取设置控件大小 新增 页面原始1061 911
  2108. //ControlWidth = 250.00 * PropWid;
  2109. //ControlHeight = 260.00 * PropHei;
  2110. //ControlWidth=
  2111. //ControlHeight=
  2112. //根据页面大小获取每页显示的数量 H260W250
  2113. int videoRow = (int)((_pageH - 50) / _controlHeight);
  2114. int videColumn = (int)(_pageW / _controlWidth);
  2115. //横向间隔
  2116. _intervalX = (_pageW - (videColumn * _controlWidth)) / (videColumn + 1);
  2117. _intervalY = (_pageH - 50 - (videoRow * _controlHeight)) / (videoRow + 1);
  2118. _pageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2119. //获取总页数
  2120. _totalPage = _modelVideoList.Count / _pageShowNum + (_modelVideoList.Count % _pageShowNum > 0 ? 1 : 0);
  2121. //如果当前页大于总页数 总页数为当前页
  2122. if (_totalPage < _currentPage)
  2123. {
  2124. _currentPage = _totalPage;
  2125. }
  2126. LoadCurrentPageData();
  2127. }
  2128. else
  2129. {
  2130. LblVideoMess.Visibility = Visibility.Visible;
  2131. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2132. LblVideoPageNum.Visibility = Visibility.Hidden;
  2133. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2134. //隐藏显示的控件
  2135. if (_videoControlList.Count > 0)
  2136. {
  2137. foreach (Uc_VideoItem item in _videoControlList)
  2138. {
  2139. if (item.Visibility != Visibility.Hidden)
  2140. {
  2141. item.Visibility = Visibility.Hidden;
  2142. }
  2143. }
  2144. }
  2145. }
  2146. App.myloading.Hide();
  2147. }
  2148. #region 分页
  2149. /// <summary>
  2150. /// 下一页
  2151. /// </summary>
  2152. /// <param name="sender">
  2153. /// </param>
  2154. /// <param name="e">
  2155. /// </param>
  2156. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2157. {
  2158. if (_currentPage < _totalPage)
  2159. {
  2160. _currentPage++;
  2161. LoadCurrentPageData();
  2162. }
  2163. }
  2164. /// <summary>
  2165. /// 上一页
  2166. /// </summary>
  2167. /// <param name="sender">
  2168. /// </param>
  2169. /// <param name="e">
  2170. /// </param>
  2171. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2172. {
  2173. if (_currentPage > 1)
  2174. {
  2175. _currentPage--;
  2176. LoadCurrentPageData();
  2177. }
  2178. }
  2179. #endregion 分页
  2180. #endregion 新上传 显示缩略图
  2181. #region 录屏
  2182. /// <summary>
  2183. /// 录屏事件
  2184. /// </summary>
  2185. /// <param name="sender">
  2186. /// </param>
  2187. /// <param name="e">
  2188. /// </param>
  2189. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2190. {
  2191. _luoBoPenUtil.lb_device_mouse();
  2192. if (!_microphoneGood)
  2193. {
  2194. MessageWindow.Show("麦克风不可用");
  2195. return;
  2196. }
  2197. if (!_loudspeakerGood)
  2198. {
  2199. MessageWindow.Show("扬声器不可用");
  2200. return;
  2201. }
  2202. PrepareRecord();
  2203. _kHook.Stop();
  2204. if (App.W_ScreenRecordingToolbarWindow == null)
  2205. {
  2206. App.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow { Topmost = true };
  2207. App.W_ScreenRecordingToolbarWindow.Initialize();
  2208. }
  2209. else
  2210. {
  2211. App.W_ScreenRecordingToolbarWindow.Initialize();
  2212. }
  2213. App.W_ScreenRecordingToolbarWindow.ClickStopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2214. //显示在右下角
  2215. App.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2216. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2217. float dip = graphics.DpiX;
  2218. App.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Width;
  2219. App.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Height - 100;
  2220. App.W_ScreenRecordingToolbarWindow.Topmost = true;
  2221. App.W_ScreenRecordingToolbarWindow.Show();
  2222. Hide();
  2223. }
  2224. /// <summary>
  2225. /// 保存录屏中
  2226. /// </summary>
  2227. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2228. {
  2229. TxbTime.Text = "00:00";
  2230. TxbType.Text = "保存中";
  2231. _recordType = 4;
  2232. RecordBtnStatus();
  2233. new Thread
  2234. (
  2235. () =>
  2236. {
  2237. while (FileToolsCommon.IsExistDirectory(App.WKData.WkPath + "_temppath/"))
  2238. {
  2239. Thread.Sleep(100);
  2240. }
  2241. Thread.Sleep(100);
  2242. Dispatcher.Invoke
  2243. (
  2244. () =>
  2245. {
  2246. _recordType = 0;
  2247. RecordBtnStatus();
  2248. }
  2249. );
  2250. }
  2251. ).Start();
  2252. }
  2253. #endregion 录屏
  2254. #region 录制窗口
  2255. #region 变量
  2256. /// <summary>
  2257. /// 录制大小
  2258. /// </summary>
  2259. private int _gridActHeight = 898;
  2260. /// <summary>
  2261. /// 录制大小
  2262. /// </summary>
  2263. private int _gridActWidth = 1276;
  2264. /// <summary>
  2265. /// 录制类型 0停止,1录制中,2暂停中 3倒计时 4合并中
  2266. /// </summary>
  2267. private int _recordType;
  2268. /// <summary>
  2269. /// 录制计时
  2270. /// </summary>
  2271. private DateTime _srTime = DateTime.Now;
  2272. /// <summary>
  2273. /// 音频保存路径名
  2274. /// </summary>
  2275. private string _tempAudioPathName;
  2276. /// <summary>
  2277. /// 视频合成前路径名
  2278. /// </summary>
  2279. private string _tempVideoPathName;
  2280. /// <summary>
  2281. /// 截图定时器
  2282. /// </summary>
  2283. private Timer _timer;
  2284. /// <summary>
  2285. /// 视频保存路径名
  2286. /// </summary>
  2287. private string _videoSavePathName;
  2288. #endregion 变量
  2289. private bool _isPressButton;
  2290. //视频写入
  2291. private readonly VideoFileWriter _videoWriter = new VideoFileWriter();
  2292. //录制麦克风的声音
  2293. private WaveInEvent _waveIn;
  2294. private bool _waveInRuning;
  2295. //音频写入
  2296. private WaveFileWriter _writer;
  2297. /// <summary>
  2298. /// 录制窗口内容
  2299. /// </summary>
  2300. /// <param name="sender">
  2301. /// </param>
  2302. /// <param name="e">
  2303. /// </param>
  2304. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2305. {
  2306. RecordAction();
  2307. }
  2308. private async void RecordAction()
  2309. {
  2310. #region 防止连击
  2311. if (_isPressButton)
  2312. {
  2313. return;
  2314. }
  2315. _isPressButton = true;
  2316. new Thread
  2317. (
  2318. () =>
  2319. {
  2320. Thread.Sleep(500);
  2321. _isPressButton = false;
  2322. }
  2323. ).Start();
  2324. #endregion 防止连击
  2325. if (_recordType == 4)
  2326. {
  2327. return;
  2328. }
  2329. if (_recordType != 0)
  2330. {
  2331. if (_recordType == 1)
  2332. {
  2333. //录制中暂停
  2334. _recordType = 2;
  2335. RecordBtnStatus();
  2336. }
  2337. else if (_recordType == 2)
  2338. {
  2339. //暂停中继续录制
  2340. _recordType = 1;
  2341. RecordBtnStatus();
  2342. }
  2343. }
  2344. else
  2345. {
  2346. if (App.PageContextData.currpage == 0)
  2347. {
  2348. MessageWindow.Show("请先导入文档或截图!");
  2349. return;
  2350. }
  2351. StartPauseGrid.Visibility = Visibility.Hidden;
  2352. StopGrid.Visibility = Visibility.Hidden;
  2353. CloseGrid.Visibility = Visibility.Hidden;
  2354. if (!_microphoneGood)
  2355. {
  2356. StartPauseGrid.Visibility = Visibility.Visible;
  2357. StopGrid.Visibility = Visibility.Visible;
  2358. CloseGrid.Visibility = Visibility.Visible;
  2359. MessageWindow.Show("麦克风不可用");
  2360. return;
  2361. }
  2362. BlackboardCanvas.Visibility = Visibility.Visible;
  2363. if (RectImgBorder.Visibility != Visibility.Hidden)
  2364. {
  2365. HideAngleBorder();
  2366. }
  2367. PrepareRecord();
  2368. BtnPrint.IsEnabled = false;
  2369. BtnScreenshot.IsEnabled = false;
  2370. BtnImport.IsEnabled = false;
  2371. BtnScreenRecording.IsEnabled = false;
  2372. BtnUpload.IsEnabled = false;
  2373. BtnSetUp.IsEnabled = false;
  2374. BtnDevice.IsEnabled = false;
  2375. BtnLoginType.IsEnabled = false;
  2376. BlackboardCanvas.Visibility = Visibility.Visible;
  2377. TxbType.Text = "准备录制";
  2378. BtnRecord.Visibility = Visibility.Collapsed;
  2379. BtnRecordSuspend.Visibility = Visibility.Visible;
  2380. BtnRecord.IsEnabled = true;
  2381. BtnStop.IsEnabled = true;
  2382. #region 录像倒计时
  2383. if (App.W_CountdownWindow == null)
  2384. {
  2385. App.W_CountdownWindow = new CountdownWindow();
  2386. }
  2387. App.W_CountdownWindow.InitAndShow();
  2388. _recordType = 3;
  2389. RecordBtnStatus();
  2390. #endregion 录像倒计时
  2391. await Task.Delay(3000);
  2392. //停止中开始录制
  2393. CloseGrid.Visibility = Visibility.Visible;
  2394. _recordType = 1;
  2395. RecordBtnStatus();
  2396. await StartRecord();
  2397. StartPauseGrid.Visibility = Visibility.Visible;
  2398. StopGrid.Visibility = Visibility.Visible;
  2399. }
  2400. RecordBtnStatus();
  2401. }
  2402. private void RecordBtnStatus()
  2403. {
  2404. if (_recordType == 0)
  2405. {
  2406. StartPauseGrid.Visibility = Visibility.Visible;
  2407. TxbType.Text = "准备录制";
  2408. BtnRecord.Visibility = Visibility.Visible;
  2409. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2410. BtnScreenRecording.IsEnabled = true;
  2411. BtnRecord.IsEnabled = true;
  2412. BtnStop.IsEnabled = false;
  2413. SheXiangTouSp.Visibility = Visibility.Visible;
  2414. }
  2415. else if (_recordType == 1)
  2416. {
  2417. StartPauseGrid.Visibility = Visibility.Visible;
  2418. TxbType.Text = "录制中";
  2419. BtnRecord.Visibility = Visibility.Collapsed;
  2420. BtnRecordSuspend.Visibility = Visibility.Visible;
  2421. SheXiangTouSp.Visibility = Visibility.Hidden;
  2422. }
  2423. else if (_recordType == 2)
  2424. {
  2425. StartPauseGrid.Visibility = Visibility.Visible;
  2426. TxbType.Text = "暂停中";
  2427. BtnRecord.Visibility = Visibility.Visible;
  2428. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2429. SheXiangTouSp.Visibility = Visibility.Hidden;
  2430. }
  2431. else if (_recordType == 3)
  2432. {
  2433. TxbType.Text = "倒计时";
  2434. SheXiangTouSp.Visibility = Visibility.Hidden;
  2435. }
  2436. else if (_recordType == 4)
  2437. {
  2438. TxbType.Text = "合并中";
  2439. StartPauseGrid.Visibility = Visibility.Hidden;
  2440. BtnScreenRecording.IsEnabled = false;
  2441. SheXiangTouSp.Visibility = Visibility.Hidden;
  2442. }
  2443. }
  2444. /// <summary>
  2445. /// 停止录制窗口内容
  2446. /// </summary>
  2447. /// <param name="sender">
  2448. /// </param>
  2449. /// <param name="e">
  2450. /// </param>
  2451. private async void BtnStop_Click(object sender, RoutedEventArgs e)
  2452. {
  2453. #region 防止连击
  2454. if (_isPressButton)
  2455. {
  2456. return;
  2457. }
  2458. else
  2459. {
  2460. _isPressButton = true;
  2461. new Thread
  2462. (
  2463. () =>
  2464. {
  2465. Thread.Sleep(500);
  2466. _isPressButton = false;
  2467. }
  2468. ).Start();
  2469. }
  2470. #endregion 防止连击
  2471. if (_recordType != 0)
  2472. {
  2473. _recordType = 4;
  2474. BlackboardCanvas.Visibility = Visibility.Collapsed;
  2475. RecordBtnStatus();
  2476. //鼠标模式
  2477. _luoBoPenUtil.lb_device_mouse();
  2478. await EndRecord();
  2479. _recordType = 0;
  2480. RecordBtnStatus();
  2481. }
  2482. }
  2483. /// <summary>
  2484. /// 停止录制并生成录制文件
  2485. /// </summary>
  2486. private async Task EndRecord()
  2487. {
  2488. #region 恢复被禁用的按钮
  2489. BtnScreenshot.IsEnabled = true;
  2490. BtnImport.IsEnabled = true;
  2491. BtnScreenRecording.IsEnabled = true;
  2492. BtnUpload.IsEnabled = true;
  2493. BtnSetUp.IsEnabled = true;
  2494. BtnDevice.IsEnabled = true;
  2495. BtnLoginType.IsEnabled = true;
  2496. #endregion 恢复被禁用的按钮
  2497. App.PageContextData.currpage = 0;
  2498. App.PageContextData.pagenum = 0;
  2499. myblackboard.Clear();
  2500. App.PageDrawList.Clear();
  2501. ImgCanvas.Source = null;
  2502. ImgDocumentation.Source = null;
  2503. ImgPpt.Source = null;
  2504. GridPage.Visibility = Visibility.Collapsed;
  2505. BtnRecord.IsEnabled = false;
  2506. BtnStop.IsEnabled = false;
  2507. BtnScreenRecording.IsEnabled = false;
  2508. _timer.Change(-1, 0);
  2509. _timer.Dispose();
  2510. _timer = null;
  2511. TxbTime.Text = "00:00";
  2512. TxbType.Text = "保存中";
  2513. _recordType = 4;
  2514. RecordBtnStatus();
  2515. await Task.Run
  2516. (
  2517. () =>
  2518. {
  2519. try
  2520. {
  2521. _videoWriter.Close();
  2522. _waveIn.StopRecording();
  2523. //等待音频结束回调
  2524. while (_waveInRuning)
  2525. {
  2526. Thread.Sleep(300);
  2527. }
  2528. Process[] killProcessArray = Process.GetProcessesByName("ffmpeg");
  2529. foreach (Process killProcess in killProcessArray)
  2530. {
  2531. killProcess.Kill();
  2532. }
  2533. FFMpegConverter ffMpeg = new FFMpegConverter();
  2534. FFMpegInput[] input =
  2535. {
  2536. new FFMpegInput(_tempVideoPathName),
  2537. new FFMpegInput(_tempAudioPathName)
  2538. };
  2539. // 音视频合并
  2540. ffMpeg.ConvertMedia
  2541. (
  2542. input,
  2543. _videoSavePathName,
  2544. "mp4",
  2545. new OutputSettings()
  2546. );
  2547. //生成缩略图
  2548. string thumbnailPath = FileToolsCommon.GetDirectoryName(_videoSavePathName) + "ThumbnailPath/";
  2549. FileToolsCommon.CreateDirectory(thumbnailPath);
  2550. //缩略图存储位置
  2551. string thumbnailPathName = thumbnailPath + FileToolsCommon.GetIoFileName(_videoSavePathName).Replace(".", "") + ".JPG";
  2552. FileToolsCommon.DeleteFile(thumbnailPathName);
  2553. _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2554. _videoInfo.VideoPath = _videoSavePathName;
  2555. _videoInfo.ThumbnailPath = thumbnailPathName;
  2556. _videoInfo.FileGuid = Guid.NewGuid().ToString();
  2557. _videoInfo.IsUpload = false;
  2558. _videoInfo.Uploaded = 0;
  2559. try
  2560. {
  2561. ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
  2562. }
  2563. catch (Exception ex)
  2564. {
  2565. LogHelper.Logerror.Error("录制生成缩略图", ex);
  2566. }
  2567. if (!App.VideoList.Exists(x => x.FileGuid == _videoInfo.FileGuid) || !App.VideoList.Exists(x => x.VideoPath == _videoInfo.VideoPath))
  2568. {
  2569. App.VideoList.Add(_videoInfo);
  2570. //保存数据
  2571. App.SaveWkData();
  2572. }
  2573. try
  2574. {
  2575. FileToolsCommon.DeleteFile(_tempVideoPathName);
  2576. FileToolsCommon.DeleteFile(_tempAudioPathName);
  2577. }
  2578. catch (Exception ex)
  2579. {
  2580. LogHelper.Logerror.Error("删除录制临时文件", ex);
  2581. }
  2582. }
  2583. catch (Exception ex)
  2584. {
  2585. Dispatcher.Invoke
  2586. (
  2587. () =>
  2588. {
  2589. MessageWindow.Show(ex.Message);
  2590. }
  2591. );
  2592. }
  2593. }
  2594. );
  2595. BtnRecord.IsEnabled = true;
  2596. BtnStop.IsEnabled = false;
  2597. BtnPrint.IsEnabled = false;
  2598. BtnScreenRecording.IsEnabled = true;
  2599. TxbType.Text = "准备就绪";
  2600. _recordType = 0;
  2601. RecordBtnStatus();
  2602. }
  2603. /// <summary>
  2604. /// 录制保存图片
  2605. /// </summary>
  2606. private void RecordSaveImage()
  2607. {
  2608. try
  2609. {
  2610. //保存图片
  2611. try
  2612. {
  2613. Dispatcher.Invoke
  2614. (
  2615. () =>
  2616. {
  2617. Bitmap bm = ImageHelper.SaveUi2Bitmap(GridMain, _gridActWidth, _gridActHeight);
  2618. _videoWriter.WriteVideoFrame(bm);
  2619. bm.Dispose();
  2620. }
  2621. );
  2622. }
  2623. catch (Exception e)
  2624. {
  2625. Console.WriteLine(e.Message);
  2626. }
  2627. }
  2628. catch (Exception ex)
  2629. {
  2630. LogHelper.Logerror.Error("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2631. }
  2632. }
  2633. /// <summary>
  2634. /// 开始录制和暂停录制
  2635. /// </summary>
  2636. private async Task StartRecord()
  2637. {
  2638. await Task.Run
  2639. (
  2640. () =>
  2641. {
  2642. //电子版切换笔模式
  2643. _luoBoPenUtil.lb_device_hand();
  2644. _videoInfo = new ModelVideo { VideoType = (EnumVideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")), WkType = EnumWkVidetype.RecordingLessons };
  2645. FileToolsCommon.DeleteDirectory(App.WKData.WkPath + "temp/");
  2646. FileToolsCommon.CreateDirectory(App.WKData.WkPath);
  2647. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "." + _videoInfo.VideoType;
  2648. _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_temp.avi";
  2649. int num = 1;
  2650. while (FileToolsCommon.IsExistFile(_videoSavePathName))
  2651. {
  2652. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_" + num + "." + _videoInfo.VideoType;
  2653. _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_temp_" + num + ".avi";
  2654. num++;
  2655. }
  2656. _tempAudioPathName = _tempVideoPathName.Replace(".avi", ".mp3");
  2657. _gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
  2658. _gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
  2659. lock (this)
  2660. {
  2661. Console.WriteLine(@"临时视频存储路径:" + _tempVideoPathName);
  2662. _videoWriter.Open
  2663. (
  2664. _tempVideoPathName,
  2665. _gridActWidth,
  2666. _gridActHeight,
  2667. 5,
  2668. VideoCodec.MPEG4,
  2669. _gridActWidth * _gridActHeight * 10
  2670. );
  2671. _waveIn = new WaveInEvent();
  2672. _waveInRuning = true;
  2673. _writer = new WaveFileWriter(_tempAudioPathName, _waveIn.WaveFormat);
  2674. //开始录音,写数据
  2675. _waveIn.DataAvailable += (s, a) =>
  2676. {
  2677. if (_recordType == 1)
  2678. {
  2679. _writer.Write
  2680. (
  2681. a.Buffer,
  2682. 0,
  2683. a.BytesRecorded
  2684. );
  2685. }
  2686. };
  2687. //结束录音
  2688. _waveIn.RecordingStopped += (s, a) =>
  2689. {
  2690. _writer.Dispose();
  2691. _writer = null;
  2692. _waveIn.Dispose();
  2693. _waveInRuning = false;
  2694. };
  2695. _waveIn.StartRecording();
  2696. }
  2697. }
  2698. );
  2699. _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2700. //启动截图
  2701. _timer = new Timer
  2702. (
  2703. Timer_Elapsed,
  2704. null,
  2705. 0,
  2706. 200
  2707. );
  2708. }
  2709. /// <summary>
  2710. /// 录制保存图片计时器
  2711. /// </summary>
  2712. /// <param name="sender">
  2713. /// </param>
  2714. private void Timer_Elapsed(object sender)
  2715. {
  2716. if (_recordType == 1)
  2717. {
  2718. Dispatcher.Invoke
  2719. (
  2720. () =>
  2721. {
  2722. _srTime = _srTime.AddMilliseconds(200);
  2723. if (_srTime.Hour > 0)
  2724. {
  2725. TxbTime.Text = _srTime.ToString("HH:mm:ss");
  2726. }
  2727. else
  2728. {
  2729. TxbTime.Text = _srTime.ToString("mm:ss");
  2730. }
  2731. }
  2732. );
  2733. ThreadPool.QueueUserWorkItem
  2734. (
  2735. o =>
  2736. {
  2737. RecordSaveImage();
  2738. }
  2739. );
  2740. }
  2741. }
  2742. #endregion 录制窗口
  2743. #region 分页
  2744. private void ImgXy()
  2745. {
  2746. ImgCanvas.Width = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterX;
  2747. ImgCanvas.Height = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterY;
  2748. ImgCanvas.Margin = new Thickness
  2749. (
  2750. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
  2751. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
  2752. 0,
  2753. 0
  2754. );
  2755. }
  2756. /// <summary>
  2757. /// 跳转
  2758. /// </summary>
  2759. private void JumpPageClick()
  2760. {
  2761. myblackboard.Changepage(App.PageContextData.currpage - 1);
  2762. ScroMain.ScrollToVerticalOffset(0);
  2763. if (BtnImport.IsEnabled)
  2764. {
  2765. //截图可用
  2766. BtnScreenshot.IsEnabled = true;
  2767. }
  2768. if (App.PageContextData.currpage <= App.PageDrawList.Count)
  2769. {
  2770. if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null)
  2771. {
  2772. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = true;
  2773. }
  2774. if (!string.IsNullOrWhiteSpace(TxbCurrpage.Text) && App.PageContextData.currpage <= App.PageDrawList.Count && App.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  2775. {
  2776. if (App.PageDrawList[App.PageContextData.currpage - 1].ImgDocumentation)
  2777. {
  2778. if ("ppt".Equals(App.PageDrawList[App.PageContextData.currpage - 1].Type))
  2779. {
  2780. ImgCanvas.Source = null;
  2781. ImgDocumentation.Source = null;
  2782. ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2783. BtnScreenshot.IsEnabled = false;
  2784. }
  2785. else
  2786. {
  2787. ImgPpt.Source = null;
  2788. ImgCanvas.Source = null;
  2789. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2790. BtnScreenshot.IsEnabled = false;
  2791. }
  2792. }
  2793. else
  2794. {
  2795. ImgPpt.Source = null;
  2796. ImgDocumentation.Source = null;
  2797. ImgCanvas.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2798. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  2799. if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null && App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X > 0)
  2800. {
  2801. _mouseDown = false;
  2802. _imageOperationUtil.SetMouseDown(_mouseDown);
  2803. ImgXy();
  2804. }
  2805. }
  2806. }
  2807. else
  2808. {
  2809. ImgPpt.Source = null;
  2810. ImgCanvas.Source = null;
  2811. ImgDocumentation.Source = null;
  2812. }
  2813. }
  2814. }
  2815. // 上一页
  2816. private void last_button_Click(object sender, RoutedEventArgs e)
  2817. {
  2818. if (App.PageContextData.currpage > 1)
  2819. {
  2820. _mouseDown = false;
  2821. _imageOperationUtil.SetMouseDown(_mouseDown);
  2822. HideAngleBorder();
  2823. App.PageContextData.currpage -= 1;
  2824. JumpPageClick();
  2825. }
  2826. }
  2827. /// <summary>
  2828. /// 下一页
  2829. /// </summary>
  2830. /// <param name="sender">
  2831. /// </param>
  2832. /// <param name="e">
  2833. /// </param>
  2834. private void next_btn_Click(object sender, RoutedEventArgs e)
  2835. {
  2836. if (App.PageContextData.currpage < App.PageContextData.pagenum)
  2837. {
  2838. _mouseDown = false;
  2839. _imageOperationUtil.SetMouseDown(_mouseDown);
  2840. HideAngleBorder();
  2841. App.PageContextData.currpage += 1;
  2842. JumpPageClick();
  2843. }
  2844. }
  2845. #endregion 分页
  2846. #region 图像缩放,移动
  2847. private bool _mouseDown;
  2848. #endregion 图像缩放,移动
  2849. #region 更改设备连接状态
  2850. /// <summary>
  2851. /// 更新设备状态显示
  2852. /// </summary>
  2853. public void UpdateDevStatus()
  2854. {
  2855. if (App.BoardStatus && (App.PenStatus || App.TQLPenStatus))
  2856. {
  2857. Dispatcher.Invoke
  2858. (
  2859. () =>
  2860. {
  2861. TxbNotConnected.Text = "笔/板已连接";
  2862. TxbNotConnecteds.Text = "笔/板已连接";
  2863. }
  2864. );
  2865. }
  2866. else if (App.BoardStatus)
  2867. {
  2868. Dispatcher.Invoke
  2869. (
  2870. () =>
  2871. {
  2872. TxbNotConnected.Text = "手写板已连接";
  2873. TxbNotConnecteds.Text = "手写板已连接";
  2874. }
  2875. );
  2876. }
  2877. else if (App.PenStatus)
  2878. {
  2879. Dispatcher.Invoke
  2880. (
  2881. () =>
  2882. {
  2883. TxbNotConnected.Text = "智能笔已连接";
  2884. TxbNotConnecteds.Text = "智能笔已连接";
  2885. }
  2886. );
  2887. }
  2888. else if (App.TQLPenStatus)
  2889. {
  2890. Dispatcher.Invoke
  2891. (
  2892. () =>
  2893. {
  2894. TxbNotConnected.Text = "智能笔已连接";
  2895. TxbNotConnecteds.Text = "智能笔已连接";
  2896. }
  2897. );
  2898. }
  2899. else
  2900. {
  2901. Dispatcher.Invoke
  2902. (
  2903. () =>
  2904. {
  2905. TxbNotConnected.Text = "未连接";
  2906. TxbNotConnecteds.Text = "未连接";
  2907. }
  2908. );
  2909. }
  2910. }
  2911. #endregion 更改设备连接状态
  2912. #region 腾千里手写笔
  2913. private const float TQLA4_HEIGHT = 1.0f * 3509 / 300 * (float)25.4 / (float)1.524;
  2914. /// <summary>
  2915. /// TQL点阵笔宽高
  2916. /// </summary>
  2917. private const float TQLA4_WIDTH = 1.0f * 2480 / 300 * (float)25.4 / (float)1.524;
  2918. /// <summary>
  2919. /// 是否在书写
  2920. /// </summary>
  2921. private bool _isTqlPenDown;
  2922. //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  2923. //(float)1512 / (float)150 * (float)25.4 / (float)1.524;
  2924. /// <summary>
  2925. /// TQL初始化
  2926. /// </summary>
  2927. public void InitTqlpPen()
  2928. {
  2929. if (App.TQLPenevents == null)
  2930. {
  2931. App.TQLPenevents = new PenEvents(1);
  2932. }
  2933. else
  2934. {
  2935. App.TQLPenevents.InToType = 1;
  2936. }
  2937. }
  2938. /// <summary>
  2939. /// 笔落下
  2940. /// </summary>
  2941. public void TqlDown()
  2942. {
  2943. _isTqlPenDown = true;
  2944. if (App.PageContextData.currpage > 0)
  2945. {
  2946. Dispatcher.Invoke
  2947. (
  2948. () =>
  2949. {
  2950. myblackboard.Changepages(
  2951. 0,
  2952. 0,
  2953. true,
  2954. _color,
  2955. _penSize,
  2956. App.PageContextData.currpage - 1,
  2957. 0
  2958. );
  2959. }
  2960. );
  2961. }
  2962. }
  2963. /// <summary>
  2964. /// 笔书写
  2965. /// </summary>
  2966. /// <param name="cx">
  2967. /// </param>
  2968. /// <param name="cy">
  2969. /// </param>
  2970. /// <param name="force">
  2971. /// </param>
  2972. public void TqlPenWrite
  2973. (
  2974. double cx,
  2975. double cy,
  2976. int force
  2977. )
  2978. {
  2979. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  2980. if (!_isTqlPenDown)
  2981. {
  2982. return;
  2983. }
  2984. double propW = BlackboardCanvas.ActualWidth / TQLA4_WIDTH;
  2985. double propH = BlackboardCanvas.ActualHeight / TQLA4_HEIGHT;
  2986. //点
  2987. double tempX = cx * propW;
  2988. double tempY = cy * propH;
  2989. if (App.PageContextData.currpage > 0)
  2990. {
  2991. Dispatcher.Invoke
  2992. (
  2993. () =>
  2994. {
  2995. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  2996. float pressure = 1.0f * force / 1023f;
  2997. myblackboard.Changepages(
  2998. tempX,
  2999. tempY,
  3000. false,
  3001. _color,
  3002. _penSize,
  3003. App.PageContextData.currpage - 1,
  3004. pressure
  3005. );
  3006. #region 设置滚动条位置
  3007. //点在显示页面上方
  3008. if (tempY < ScroMain.VerticalOffset)
  3009. {
  3010. //滚动条当前位置
  3011. double rollCurrentLocation = ScroMain.VerticalOffset;
  3012. //向上滚动至以点为中心需要滚动的距离
  3013. double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3014. //如果小于0则等于0
  3015. double rollLocation = rollCurrentLocation - upRoll;
  3016. if (rollLocation < 0)
  3017. {
  3018. rollLocation = 0;
  3019. }
  3020. ////滚动条实际偏移量
  3021. //double RollOffset = RollCurrentLocation - RollLocation;
  3022. ScroMain.ScrollToVerticalOffset(rollLocation);
  3023. }
  3024. //点在显示页面下方
  3025. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3026. {
  3027. //滚动条当前位置
  3028. double rollCurrentLocation = ScroMain.VerticalOffset;
  3029. //向下滚动至以点为中心需要滚动的距离
  3030. double downRoll = (tempY - rollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3031. //如果小于0则等于0
  3032. double rollLocation = rollCurrentLocation + downRoll;
  3033. //滚动条最大滚动值
  3034. double scrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3035. if (rollLocation > scrollbarMaxNum)
  3036. {
  3037. rollLocation = scrollbarMaxNum;
  3038. }
  3039. ////滚动条实际偏移量
  3040. //double RollOffset = RollLocation-RollCurrentLocation;
  3041. ScroMain.ScrollToVerticalOffset(rollLocation);
  3042. }
  3043. #endregion 设置滚动条位置
  3044. if (tempX > 0 && tempY > 0)
  3045. {
  3046. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3047. SetCursorPos((int)getP.X, (int)getP.Y);
  3048. }
  3049. }
  3050. );
  3051. }
  3052. }
  3053. /// <summary>
  3054. /// 笔抬起
  3055. /// </summary>
  3056. public void TqlUp()
  3057. {
  3058. _isTqlPenDown = false;
  3059. //stroke.Clear();
  3060. if (App.PageContextData.currpage > 0)
  3061. {
  3062. Dispatcher.Invoke
  3063. (
  3064. () =>
  3065. {
  3066. myblackboard.Changepages(
  3067. 0,
  3068. 0,
  3069. true,
  3070. _color,
  3071. _penSize,
  3072. App.PageContextData.currpage - 1,
  3073. 0
  3074. );
  3075. }
  3076. );
  3077. }
  3078. }
  3079. #endregion 腾千里手写笔
  3080. #region 图片拉伸移动
  3081. /// <summary>
  3082. /// 隐藏图片四个点和线
  3083. /// </summary>
  3084. private void HideAngleBorder()
  3085. {
  3086. _imageOperationUtil.HideAngleBorder();
  3087. }
  3088. private void imgCanvas_MouseMove(object sender, MouseEventArgs e)
  3089. {
  3090. _imageOperationUtil.imgCanvas_MouseMove(sender, e);
  3091. }
  3092. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  3093. {
  3094. _imageOperationUtil.imgCanvas_MouseUp();
  3095. }
  3096. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  3097. {
  3098. _imageOperationUtil.PicEMap_MouseDown(sender, e);
  3099. }
  3100. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  3101. {
  3102. _imageOperationUtil.RectRightUp_DragCompleted();
  3103. }
  3104. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  3105. {
  3106. _imageOperationUtil.RectRightUp_DragDelta(sender, e);
  3107. }
  3108. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  3109. {
  3110. _imageOperationUtil.RectRightUp_DragStarted(sender, e);
  3111. }
  3112. /// <summary>
  3113. /// 鼠标左键点击事件
  3114. /// </summary>
  3115. /// <param name="sender">
  3116. /// </param>
  3117. /// <param name="e">
  3118. /// </param>
  3119. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  3120. {
  3121. _imageOperationUtil.Window_MouseLeftButtonDown_1();
  3122. }
  3123. #endregion 图片拉伸移动
  3124. #region 录屏 录制 截图 导入文档 增加 主页面显示
  3125. /// <summary>
  3126. /// 录屏 录制 截图 导入文档 增加 主页面显示
  3127. /// </summary>
  3128. private void PrepareRecord()
  3129. {
  3130. PageHide();
  3131. GridMain.Visibility = Visibility.Visible;
  3132. GridRecordingTitle.Visibility = Visibility.Visible;
  3133. if (App.PageContextData.pagenum > 0)
  3134. {
  3135. GridPage.Visibility = Visibility.Visible;
  3136. }
  3137. DataContext = App.PageContextData;
  3138. }
  3139. #endregion 录屏 录制 截图 导入文档 增加 主页面显示
  3140. #region 页码跳转
  3141. #endregion 页码跳转
  3142. #region TQL打印
  3143. public static string gPrintFileName;
  3144. private iTextSharp.text.Document _document;
  3145. private bool _gbInitDone;
  3146. /// <summary>
  3147. /// 授权码
  3148. /// </summary>
  3149. private string _gKeyStr;
  3150. private readonly TmatrixClass _tmc = new TmatrixClass();
  3151. /// <summary>
  3152. /// 授权文件位置
  3153. /// </summary>
  3154. private string _tqlAuthorizationPath;
  3155. /// <summary>
  3156. /// 铺码
  3157. /// </summary>
  3158. private bool GenerateCode(string pdfPath)
  3159. {
  3160. try
  3161. {
  3162. if (_gbInitDone == false)
  3163. {
  3164. MessageWindow.Show("打印功能无法使用,无效授权。");
  3165. return false;
  3166. }
  3167. try
  3168. {
  3169. string directoryPath = FileToolsCommon.GetDirectoryName(pdfPath);
  3170. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  3171. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  3172. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  3173. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  3174. }
  3175. catch (Exception)
  3176. {
  3177. // ignored
  3178. }
  3179. pdfPath = pdfPath.Replace("/", "\\");
  3180. //初始页
  3181. bool[] bPublishImageType = new bool[4];
  3182. bPublishImageType[0] = false;
  3183. bPublishImageType[1] = false;
  3184. bPublishImageType[2] = false;
  3185. bPublishImageType[3] = true;
  3186. int[] gPointType =
  3187. {
  3188. 0,
  3189. 0,
  3190. 0,
  3191. 0,
  3192. 1
  3193. };
  3194. int[] gPointDpi =
  3195. {
  3196. 0,
  3197. 0,
  3198. 0,
  3199. 0,
  3200. 1
  3201. };
  3202. string sGenerateResult = _tmc.GenerateTmatrixCode_OID4
  3203. (
  3204. _gKeyStr,
  3205. pdfPath,
  3206. 0,
  3207. gPointType,
  3208. bPublishImageType,
  3209. gPointDpi
  3210. );
  3211. if (sGenerateResult.Substring(0, 1) == "1")
  3212. {
  3213. Dispatcher.Invoke
  3214. (
  3215. () =>
  3216. {
  3217. MessageWindow.Show("打印功能无法使用,无效授权。");
  3218. }
  3219. );
  3220. return false;
  3221. }
  3222. return true;
  3223. }
  3224. catch (Exception ex)
  3225. {
  3226. Dispatcher.Invoke
  3227. (
  3228. () =>
  3229. {
  3230. MessageWindow.Show("打印失败:" + ex.Message);
  3231. }
  3232. );
  3233. return false;
  3234. }
  3235. }
  3236. /// <summary>
  3237. /// TQL初始化打印
  3238. /// </summary>
  3239. private void TqlPrintInit()
  3240. {
  3241. //初始化
  3242. if (_tmc.TmatrixInitialize() == false)
  3243. {
  3244. }
  3245. else
  3246. {
  3247. _gbInitDone = true;
  3248. }
  3249. _document = new iTextSharp.text.Document
  3250. (
  3251. iTextSharp.text.PageSize.A4,
  3252. 0,
  3253. 0,
  3254. 0,
  3255. 0
  3256. );
  3257. try
  3258. {
  3259. _tqlAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255_20240705.tmx");
  3260. StreamReader gsr = new StreamReader(_tqlAuthorizationPath);
  3261. _gKeyStr = gsr.ReadLine();
  3262. gsr.Close();
  3263. string keyCheckResult = _tmc.TmatrixKeyCheck_OID4(_gKeyStr);
  3264. if (keyCheckResult.Substring(0, 1) == "1")
  3265. {
  3266. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  3267. LogHelper.Logerror.Error("打印服务授权过期:" + keyCheckResult, null);
  3268. _gbInitDone = false;
  3269. }
  3270. }
  3271. catch (Exception ex)
  3272. {
  3273. LogHelper.Logerror.Error("打印服务授权失败:" + ex.Message, ex);
  3274. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  3275. _gbInitDone = false;
  3276. }
  3277. }
  3278. #endregion TQL打印
  3279. #region 打印界面
  3280. private double _hei;
  3281. private int _msgnum;
  3282. private int _num;
  3283. /// <summary>
  3284. /// 打印状态消息
  3285. /// </summary>
  3286. private string _printMsg = "打印中";
  3287. /// <summary>
  3288. /// 打印进度
  3289. /// </summary>
  3290. private System.Timers.Timer _timesPrint;
  3291. /// <summary>
  3292. /// 打印消息
  3293. /// </summary>
  3294. private System.Timers.Timer _timesPrintMsg;
  3295. private double _wit;
  3296. /// <summary>
  3297. /// 初始化页面
  3298. /// </summary>
  3299. /// <param name="imgPath">
  3300. /// </param>
  3301. /// <param name="wit">
  3302. /// </param>
  3303. /// <param name="hei">
  3304. /// </param>
  3305. public void InitializePrint
  3306. (
  3307. string imgPath,
  3308. double wit,
  3309. double hei
  3310. )
  3311. {
  3312. this._wit = wit;
  3313. this._hei = hei;
  3314. if (!string.IsNullOrWhiteSpace(imgPath))
  3315. {
  3316. ImgPri.Source = new BitmapImage(new Uri(imgPath));
  3317. }
  3318. else
  3319. {
  3320. ImgPri.Source = null;
  3321. }
  3322. GridPrintMask.Visibility = Visibility.Collapsed;
  3323. }
  3324. /// <summary>
  3325. /// 打印初始化
  3326. /// </summary>
  3327. public void InitPrint()
  3328. {
  3329. ResizeMode = ResizeMode.NoResize;
  3330. TqlPrintInit();
  3331. }
  3332. /// <summary>
  3333. /// 生成图片
  3334. /// </summary>
  3335. /// <param name="path">
  3336. /// 图片地址
  3337. /// </param>
  3338. /// <param name="saveimg">
  3339. /// 保存位置
  3340. /// </param>
  3341. /// <param name="rectangle">
  3342. /// 图片位置
  3343. /// </param>
  3344. /// <returns>
  3345. /// </returns>
  3346. private bool MergerPrintImg
  3347. (
  3348. string path,
  3349. string saveimg,
  3350. RectangleF rectangle
  3351. )
  3352. {
  3353. try
  3354. {
  3355. Bitmap bitmap = null;
  3356. //创建要显示的图片对象,根据参数的个数设置宽度
  3357. Bitmap backgroudImg = new Bitmap((int) /*GridM.ActualWidth*/_wit, (int) /*GridM.ActualHeight*/_hei);
  3358. Graphics g = Graphics.FromImage(backgroudImg);
  3359. //清除画布,背景设置为白色
  3360. g.Clear(System.Drawing.Color.White);
  3361. if (!string.IsNullOrWhiteSpace(path))
  3362. {
  3363. bitmap = ImageHelper.ReadBitmapFile(path);
  3364. g.DrawImage(bitmap, rectangle);
  3365. }
  3366. #region 添加箭头
  3367. string str = "↑";
  3368. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  3369. Font myfont = new Font("黑体", 14); //设置默认字体格式
  3370. g.DrawString
  3371. (
  3372. str,
  3373. myfont,
  3374. mybrush,
  3375. new Rectangle
  3376. (
  3377. (int)_wit - 50,
  3378. 20,
  3379. 50,
  3380. 50
  3381. )
  3382. );
  3383. #endregion 添加箭头
  3384. backgroudImg.Save(saveimg);
  3385. g.Dispose();
  3386. backgroudImg.Dispose();
  3387. if (bitmap != null)
  3388. {
  3389. bitmap.Dispose();
  3390. }
  3391. GC.Collect();
  3392. return true;
  3393. }
  3394. catch (Exception ex)
  3395. {
  3396. LogHelper.Logerror.Error("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3397. return false;
  3398. }
  3399. }
  3400. /// <summary>
  3401. /// 开始打印
  3402. /// </summary>
  3403. private void StartPrint(PrintModel printModel)
  3404. {
  3405. try
  3406. {
  3407. _document = new iTextSharp.text.Document
  3408. (
  3409. iTextSharp.text.PageSize.A4,
  3410. 0f,
  3411. 0f,
  3412. 0f,
  3413. 0f
  3414. );
  3415. _printMsg = "生成文件";
  3416. _msgnum = 0;
  3417. string sourcePath1 = printModel.filepath;
  3418. try
  3419. {
  3420. sourcePath1 = sourcePath1.Replace("/", "\\");
  3421. FileStream fs = new FileStream
  3422. (
  3423. sourcePath1,
  3424. FileMode.Create,
  3425. FileAccess.ReadWrite
  3426. );
  3427. _document.AddAuthor("星火微课"); //作者
  3428. _document.AddCreationDate(); //创建时候
  3429. _document.AddCreator("星火微课"); //创建者
  3430. _document.AddSubject("点阵文件"); //主题
  3431. _document.AddTitle("PrintTmatrixCode"); //标题
  3432. _document.AddKeywords("Print");
  3433. _document.AddHeader("TmatrixCode", "0");
  3434. iTextSharp.text.pdf.PdfWriter.GetInstance(_document, fs);
  3435. }
  3436. catch (Exception)
  3437. {
  3438. // ignored
  3439. }
  3440. _document.Open();
  3441. iTextSharp.text.Image image;
  3442. for (int i = 0; i < App.PageDrawList.Count; i++)
  3443. {
  3444. long ii = Timestamp();
  3445. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3446. string filePathOutPut = Path.Combine
  3447. (
  3448. directoryPath,
  3449. string.Format
  3450. (
  3451. "print{0}{1}.jpg",
  3452. ii,
  3453. i
  3454. )
  3455. );
  3456. RectangleF rectangleFs = new RectangleF();
  3457. MergerPrintImg
  3458. (
  3459. "",
  3460. filePathOutPut,
  3461. rectangleFs
  3462. );
  3463. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3464. if (string.IsNullOrEmpty(App.PageDrawList[i].PageImagePath)) //没有图片
  3465. {
  3466. }
  3467. else if (App.PageDrawList[i].ImgDocumentation && !App.PageDrawList[i].Type.Equals("ppt"))
  3468. {
  3469. image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
  3470. }
  3471. else
  3472. {
  3473. RectangleF rectangleF = new RectangleF
  3474. (
  3475. 0,
  3476. 0,
  3477. 0,
  3478. 0
  3479. );
  3480. var i1 = i;
  3481. Dispatcher.Invoke
  3482. (
  3483. () =>
  3484. {
  3485. rectangleF = new RectangleF
  3486. {
  3487. Width = (float)App.PageDrawList[i1].ImageSizes.CenterX,
  3488. Height = (float)App.PageDrawList[i1].ImageSizes.CenterY,
  3489. X = (float)App.PageDrawList[i1].ImageLocation.X,
  3490. Y = (float)App.PageDrawList[i1].ImageLocation.Y
  3491. };
  3492. }
  3493. );
  3494. bool isImg = MergerPrintImg
  3495. (
  3496. App.PageDrawList[i].PageImagePath,
  3497. filePathOutPut,
  3498. rectangleF
  3499. );
  3500. if (isImg)
  3501. {
  3502. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3503. }
  3504. else
  3505. {
  3506. image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
  3507. }
  3508. }
  3509. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3510. {
  3511. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3512. }
  3513. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3514. {
  3515. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3516. }
  3517. image.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE;
  3518. _document.NewPage();
  3519. _document.Add(image);
  3520. }
  3521. _document.Close();
  3522. }
  3523. catch (Exception ex)
  3524. {
  3525. Dispatcher.Invoke
  3526. (
  3527. () =>
  3528. {
  3529. BtnPrint.IsEnabled = true;
  3530. _timesPrint.Stop();
  3531. _timesPrintMsg.Stop();
  3532. GridPrintMask.Visibility = Visibility.Collapsed;
  3533. MessageWindow.Show(ex.Message);
  3534. }
  3535. );
  3536. LogHelper.Logerror.Error("打印转换PDF失败,原因:" + ex.Message, ex);
  3537. }
  3538. //PDF位置
  3539. string sourcePath = printModel.filepath;
  3540. if (_isHasCode)
  3541. {
  3542. _printMsg = "铺码中";
  3543. _msgnum = 0;
  3544. Thread.Sleep(500);
  3545. //腾千里生成点阵文件
  3546. if (GenerateCode(sourcePath))
  3547. {
  3548. //打印机名称
  3549. string directoryPath = FileToolsCommon.GetDirectoryName(sourcePath) + "Bg with Images/";
  3550. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  3551. try
  3552. {
  3553. // 腾千里会根据原PDF的页数生成多个PDF文件
  3554. for (int i = 0; i < strs.Count(); i++)
  3555. {
  3556. _timesPrint.Stop();
  3557. _printMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  3558. _msgnum = 0;
  3559. _num = 0;
  3560. _timesPrint.Interval = 100;
  3561. _timesPrint.Start();
  3562. string fileName = strs[i];
  3563. //打印文件
  3564. ZPrintUtils.Print2(fileName);
  3565. }
  3566. Dispatcher.Invoke
  3567. (
  3568. () =>
  3569. {
  3570. BtnPrint.IsEnabled = true;
  3571. _num = 99;
  3572. _timesPrint.Stop();
  3573. PgbProcess.Value = 100;
  3574. LbProcess.Content = "100%";
  3575. GridPrintMask.Visibility = Visibility.Collapsed;
  3576. //MessageWindow.Show("已加入打印机队列,打印中。");
  3577. }
  3578. );
  3579. }
  3580. catch (Exception ex)
  3581. {
  3582. Dispatcher.Invoke
  3583. (
  3584. () =>
  3585. {
  3586. MessageWindow.Show("打印失败:" + ex.Message);
  3587. BtnPrint.IsEnabled = true;
  3588. _timesPrint.Stop();
  3589. GridPrintMask.Visibility = Visibility.Collapsed;
  3590. }
  3591. );
  3592. }
  3593. }
  3594. else
  3595. {
  3596. Dispatcher.Invoke
  3597. (
  3598. () =>
  3599. {
  3600. BtnPrint.IsEnabled = true;
  3601. _timesPrint.Stop();
  3602. _timesPrintMsg.Stop();
  3603. GridPrintMask.Visibility = Visibility.Collapsed;
  3604. }
  3605. );
  3606. }
  3607. }
  3608. else
  3609. {
  3610. //打印文件
  3611. ZPrintUtils.Print2(sourcePath);
  3612. Dispatcher.Invoke
  3613. (
  3614. () =>
  3615. {
  3616. BtnPrint.IsEnabled = true;
  3617. _num = 99;
  3618. _timesPrint.Stop();
  3619. PgbProcess.Value = 100;
  3620. LbProcess.Content = "100%";
  3621. GridPrintMask.Visibility = Visibility.Collapsed;
  3622. //MessageWindow.Show("已加入打印机队列,打印中。");
  3623. }
  3624. );
  3625. }
  3626. }
  3627. /// <summary>
  3628. /// 计时器
  3629. /// </summary>
  3630. /// <param name="sender">
  3631. /// </param>
  3632. /// <param name="e">
  3633. /// </param>
  3634. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  3635. {
  3636. Dispatcher.Invoke
  3637. (
  3638. () =>
  3639. {
  3640. PgbProcess.Value = _num;
  3641. LbProcess.Content = _num + "%";
  3642. if (_num < 99)
  3643. {
  3644. _num++;
  3645. _timesPrint.Interval += 1.0 * _num / 2;
  3646. }
  3647. else
  3648. {
  3649. _timesPrint.Stop();
  3650. }
  3651. }
  3652. );
  3653. }
  3654. /// <summary>
  3655. /// 消息
  3656. /// </summary>
  3657. /// <param name="sender">
  3658. /// </param>
  3659. /// <param name="e">
  3660. /// </param>
  3661. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  3662. {
  3663. if (_msgnum > 5)
  3664. _msgnum = 0;
  3665. else
  3666. _msgnum++;
  3667. string point = "";
  3668. point = point.PadRight(_msgnum, '.');
  3669. Dispatcher.Invoke
  3670. (
  3671. () =>
  3672. {
  3673. LabPrintMessage.Content = _printMsg + point;
  3674. }
  3675. );
  3676. }
  3677. #endregion 打印界面
  3678. #region 笔事件回调
  3679. public void penPointEvent
  3680. (
  3681. byte bIndex,
  3682. byte bPenStatus,
  3683. short bx,
  3684. short by,
  3685. short bPress,
  3686. int mNDeviceW,
  3687. int mNDeviceH
  3688. )
  3689. {
  3690. //17是按下,16是抬起
  3691. if (bPenStatus == 16 || bPenStatus == 0)
  3692. {
  3693. //stroke.Clear();
  3694. if (App.PageContextData.currpage > 0)
  3695. {
  3696. Dispatcher.Invoke
  3697. (
  3698. () =>
  3699. {
  3700. myblackboard.Changepages(
  3701. 0,
  3702. 0,
  3703. true,
  3704. _color,
  3705. _penSize,
  3706. App.PageContextData.currpage - 1,
  3707. 0
  3708. );
  3709. }
  3710. );
  3711. }
  3712. }
  3713. double propW = BlackboardCanvas.ActualWidth / mNDeviceH;
  3714. double propH = BlackboardCanvas.ActualHeight / mNDeviceW;
  3715. //点
  3716. double tempY = (mNDeviceW - bx) * propH;
  3717. double tempX = by * propW;
  3718. //pageSerial //点阵IP地址 与打印的页面关联
  3719. if (App.PageContextData.currpage > 0)
  3720. {
  3721. Dispatcher.Invoke
  3722. (
  3723. () =>
  3724. {
  3725. float pressure = bPress / 100f;
  3726. if (bPress > 0)
  3727. {
  3728. myblackboard.Changepages(
  3729. tempX,
  3730. tempY,
  3731. false,
  3732. _color,
  3733. _penSize,
  3734. App.PageContextData.currpage - 1,
  3735. pressure
  3736. );
  3737. }
  3738. #region 设置滚动条位置
  3739. //点在显示页面上方
  3740. if (tempY < ScroMain.VerticalOffset)
  3741. {
  3742. //滚动条当前位置
  3743. double rollCurrentLocation = ScroMain.VerticalOffset;
  3744. //向上滚动至以点为中心需要滚动的距离
  3745. double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3746. //如果小于0则等于0
  3747. double rollLocation = rollCurrentLocation - upRoll;
  3748. if (rollLocation < 0)
  3749. {
  3750. rollLocation = 0;
  3751. }
  3752. ////滚动条实际偏移量
  3753. //double RollOffset = RollCurrentLocation - RollLocation;
  3754. ScroMain.ScrollToVerticalOffset(rollLocation);
  3755. }
  3756. //点在显示页面下方
  3757. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3758. {
  3759. //滚动条当前位置
  3760. double rollCurrentLocation = ScroMain.VerticalOffset;
  3761. //向下滚动至以点为中心需要滚动的距离
  3762. double downRoll = (tempY - rollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3763. //如果小于0则等于0
  3764. double rollLocation = rollCurrentLocation + downRoll;
  3765. //滚动条最大滚动值
  3766. double scrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3767. if (rollLocation > scrollbarMaxNum)
  3768. {
  3769. rollLocation = scrollbarMaxNum;
  3770. }
  3771. ////滚动条实际偏移量
  3772. //double RollOffset = RollLocation-RollCurrentLocation;
  3773. ScroMain.ScrollToVerticalOffset(rollLocation);
  3774. }
  3775. #endregion 设置滚动条位置
  3776. if (tempX > 0 && tempY > 0)
  3777. {
  3778. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3779. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3780. SetCursorPos((int)getP.X, (int)getP.Y);
  3781. }
  3782. }
  3783. );
  3784. }
  3785. }
  3786. public void penStatusEvent()
  3787. {
  3788. UpdateDevStatus();
  3789. }
  3790. #endregion 笔事件回调
  3791. private void Window_Closed(object sender, EventArgs e)
  3792. {
  3793. Application.Current.Shutdown();
  3794. }
  3795. }
  3796. }