星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

XHMicroLessonSystemWindow.xaml.cs 224KB

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