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

MainWindow.xaml.cs 148KB

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