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

MainWindow.xaml.cs 153KB

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