星火微课系统客户端
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 210KB

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