星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

XHMicroLessonSystemWindow.xaml.cs 209KB

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