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

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