星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XHMicroLessonSystemWindow.xaml.cs 226KB

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