星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 207KB

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