星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

XHMicroLessonSystemWindow.xaml.cs 186KB

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