星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MainWindow.xaml.cs 172KB

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