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

XHMicroLessonSystemWindow.xaml.cs 210KB

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