|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737 |
- using Aspose.Slides;
- using Aspose.Words;
- using Aspose.Words.Saving;
-
- using ComeCapture;
-
- using Common.system;
-
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Forms;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- using TStudyDigitalPen.HID;
-
- using XHWK.Model;
- using XHWK.WKTool.DAL;
- using XHWK.WKTool.UControl;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 主页面
- /// </summary>
- public partial class XHMicroLessonSystemWindow : Window
- {
- #region 字段
- private FolderBrowserDialog Ofd;
- private DialogResult Result;
- public BlackboardNew myblackboard;
- private System.Windows.Forms.DialogResult result;
- private System.Windows.Forms.OpenFileDialog ofd;
-
- //声明一个 DrawingAttributes 类型的变量
- private DrawingAttributes drawingAttributes;
- private Model_Video VideoInfo = null;
- ////定义事件
- //public event ChangeTextHandler ChangeTextEvent;
- //定义委托
- public delegate void ChangeTextHandler(string text);
- //定义委托
- public delegate void ChangeTextHandlers(string text, int i);
-
- /// <summary>
- /// 图片
- /// </summary>
- private string[] ImgPDFPath = new string[300];
- /// <summary>
- /// 当前颜色
- /// </summary>
- private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
- /// <summary>
- /// 笔迹粗细
- /// </summary>
- private int PenSize = 2;
- private DispatcherTimer t = null;
- /// <summary>
- /// 计时器状态
- /// </summary>
- private enum State
- {
- Start,
- Pause,
- End
- }
- /// <summary>
- /// 状态
- /// </summary>
- private State _state = State.End;
- /// <summary>
- /// 计时用
- /// </summary>
- private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
-
- #region 上传
- /// <summary>
- /// 视频模型
- /// </summary>
- private List<Model_Video> model_VideoList = null;
- /// <summary>
- /// 数据列表
- /// </summary>
- internal FileDirectoryData pageData = new FileDirectoryData();
- /// <summary>
- /// 下标
- /// </summary>
- private int Subscript = 0;
- /// <summary>
- /// 是否是修改状态
- /// </summary>
- private bool IsModify = false;
- #endregion
- private double screeHeight = SystemParameters.FullPrimaryScreenHeight;
- private double screeWidth = SystemParameters.FullPrimaryScreenWidth;
- #endregion
-
- #region 初始化
- /// <summary>
- /// 主页面
- /// </summary>
- public XHMicroLessonSystemWindow()
- {
- 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=")));
- 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=")));
- InitializeComponent();
- double proportion = 1036.0 / 1290.0;
- Width = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
- Height = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
- GridContent.Width = Width - 14;
- GridContent.Height = Height;
-
-
- #region 读取本地配置
- if (File.Exists(APP.dataPath + "interfaceAddress.txt")) //若不为空
- {
- APP.apiUrl = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default);
- }
- if (File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若不为空
- {
- APP.uploadUrl = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default);
- }
- if (File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若不为空
- {
- APP.showImageUrl = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default);
- }
- #endregion
-
- //GridMain.Height= PrimaryScreen.ScaleScreenSize().Height - 40;
-
- //this.Top = (screeHeight - this.Height) / 2;
-
- //this.Left = (screeWidth - this.Width) / 2;
- ResizeMode = System.Windows.ResizeMode.CanMinimize;
- btnPrint.IsEnabled = false;
-
- myblackboard = new BlackboardNew(blackboard_canvas);
- APP.pageData.pagenum = 0;
- APP.pageData.currpage = 0;
- DataContext = APP.pageData;
-
- //APP.SaveDraw();//画板模型第一页初始化
- APP.PageDrawList = new List<Model_DrawData>();
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageNum = APP.pageData.currpage
- };
- APP.PageDrawList.Add(model_DrawData);
- txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
- txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
- if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
- {
- rbnY.IsChecked = true;
- }
- else
- {
- rbnN.IsChecked = true;
- }
- txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
- Initialize();
- InitPen();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- #region 数据初始化
- APP.pageData.pagenum = 0;
- APP.pageData.currpage = APP.pageData.pagenum;
- btnStop.IsEnabled = false;//停止录制按钮不可点击
- #endregion
-
-
-
- APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- //创建 DrawingAttributes 类的一个实例
- drawingAttributes = new DrawingAttributes();
- //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- blackboard_canvas.UseCustomCursor = true;
- drawingAttributes.FitToCurve = true;
- drawingAttributes.IgnorePressure = false;
- drawingAttributes.Width = PenSize;
- drawingAttributes.Height = PenSize;
- drawingAttributes.Color = Color;
- blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
- //wfhCamera.Visibility = Visibility.Hidden;
- ImgPDFPath = null;
- ImgPDFPath = new string[300];
-
- }
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Stack()
- {
- _state = State.Start;
- }
- /// <summary>
- /// 暂停
- /// </summary>
- private void TimeOut()
- {
- _state = State.Pause;
- }
- /// <summary>
- /// 结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void End()
- {
- _state = State.End;
- }
- /// <summary>
- /// 时钟回调
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnTimer(object sender, EventArgs e)
- {
- switch (_state)
- {
- case State.Start:
- {
- _timeSpan += new TimeSpan(0, 0, 0, 1);
- }
- break;
-
- case State.Pause:
- {
- }
- break;
-
- case State.End:
- {
- _timeSpan = new TimeSpan();
- //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
- }
- break;
- }
-
- string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
- txbTime.Text = time;
- //txbTime.Text = time;
- }
- /// <summary>
- /// 修改布局
- /// </summary>
- public void SetUpLayout()
- {
- //宽高比1276,1040
- //double AspectRatio = 1276.0 / 1040.0;
- ////System.Drawing.Size des = PrimaryScreen.DESKTOP;
- //System.Drawing.Size workingArea = PrimaryScreen.WorkingArea;
- //this.Height = workingArea.Height;
-
- }
- #endregion
-
- #region 事件
- /// <summary>
- /// 窗体移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
-
- #region 摄像头
- private System.Timers.Timer times;
- private List<string> RbnOpen;
- private bool IsRbnOpen = false;
- /// <summary>
- /// 摄像头打开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnOpen_Click(object sender, RoutedEventArgs e)
- {
- //UCCamera win = new UCCamera();
- ////win.Topmost = true;
- //win.ShowDialog();
-
-
-
- //wfhCamera.Visibility = Visibility.Visible;
- //CameraHelper.IsDisplay = true;
- //CameraHelper.SourcePlayer = player;
- CameraHelper.UpdateCameraDevices();
- if (CameraHelper.CameraDevices.Count > 0)
- {
- CameraHelper.SetCameraDevice(0);
- RbnOpen = new List<string>();
- times = new System.Timers.Timer(100)//初始值为300
- {
- AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
- };//设置执行一次(false)还是一直执行(true)
- times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
- times.Enabled = true; //启动计时器
-
- IsRbnOpen = true;
-
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- FileToolsCommon.CreateDirectory(imgPath);
- }
- }
-
- private int I = 9999;
- private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (IsRbnOpen)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- if (I > 10010)
- {
- long time = Timestamp();
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- //string FilePathName = ImgPath + RsImgName.Count + ".png";
- string path = CameraHelper.CaptureImage(imgPath, time.ToString());
- if (!string.IsNullOrWhiteSpace(path))
- {
- RbnOpen.Add(path);
- imgPlayerRight.Visibility = Visibility.Visible;
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if ("1".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Visible;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRight.Source = new BitmapImage(new Uri(path));
- }
- else if ("2".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Visible;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Source = new BitmapImage(new Uri(path));
- }
- else if ("3".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Visible;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
- }
- else if ("4".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Visible;
- imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
- }
- else
- {
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRight.Source = new BitmapImage(new Uri(path));
- }
- }
- }
- I++;
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
- }
- /// <summary>
- /// 摄像头关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
- {
- IsRbnOpen = false;
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- CameraHelper.CloseDevice();
- I = 9999;
- }
- #endregion
- #endregion
-
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDown_Click(object sender, RoutedEventArgs e)
- {
- if (IsFirstR)
- {
- MessageBoxResult br= MessageWindow.Show("确定退出系统?","退出",MessageBoxButton.OKCancel);
- if (br == MessageBoxResult.OK)
- {
- APP.Killffmpeg();
- APP.SaveWkData();
- APP.SaveDraw();
- Thread.Sleep(100);
- System.Environment.Exit(0);
- }
- }
- else
- {
- MessageWindow.Show("当前正在录制,请先停止录制。");
- return;
- //MessageBoxResult dr = MessageWindow.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
- //if (dr == MessageBoxResult.OK)
- //{
- // APP.SaveWkData();
- // APP.SaveDraw();
- // BtnStop_Click(null, null);
- // while (!IsFirstR)
- // {
- // Thread.Sleep(100);
- // }
- // System.Environment.Exit(0);
- //}
- //else
- //{
- // return;
- //}
- }
- }
-
- #region 设置
- /// <summary>
- /// 设置事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnSetUp_Click(object sender, RoutedEventArgs e)
- {
- if (!TxbRecordingWord.Text.Equals("暂停"))
- {
- if(gridSetUp.Visibility==Visibility.Collapsed)
- {
- GridMain.Visibility = Visibility.Collapsed;
- gridSetUp.Visibility = Visibility.Visible;
- //gridUpload.Visibility = Visibility.Collapsed;
- GridMyVideo.Visibility = Visibility.Collapsed;
- txbStoragePath.Content = APP.WKData.WkPath;
- GridMyVideo.Visibility = Visibility.Collapsed;
- #region 读取用户配置
- //接口地址
- if (!File.Exists(APP.dataPath + "interfaceAddress.txt")) //若为空
- {
- txbInterfaceAddress.Text = APP.apiUrl.Replace("http://", "").Trim();
- }
- else
- {
- txbInterfaceAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default).Replace("http://", "").Trim();
- }
- //上传地址
- if (!File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若为空
- {
- txbImageUploadAddress.Text = APP.uploadUrl.Replace("http://", "").Replace("/", "").Trim();
- }
- else
- {
- txbImageUploadAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Trim();
- }
- //下载地址
- if (!File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若为空
- {
- txbPictureShowsAddress.Text = APP.showImageUrl.Replace("http://", "").Replace("/", "").Replace("static", "").Trim();
- }
- else
- {
- txbPictureShowsAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Replace("static", "").Trim();
- }
-
-
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if ("1".Equals(APP.CameraPosition))
- {
- rbnRight.IsChecked = true;
- }
- else if ("2".Equals(APP.CameraPosition))
- {
- rbnLeft.IsChecked = true;
- }
- else if ("3".Equals(APP.CameraPosition))
- {
- rbnRightUnder.IsChecked = true;
- }
- else if ("4".Equals(APP.CameraPosition))
- {
- rbnLeftUnder.IsChecked = true;
- }
- string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
- if ("1".Equals(type))
- {
- rbnMP4.IsChecked = true;
- }
- else if ("2".Equals(type))
- {
- rbnFLV.IsChecked = true;
- }
- else if ("3".Equals(type))
- {
- rbnAVI.IsChecked = true;
- }
- string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
- if (isSound == "true")
- {
- rbnY.IsChecked = true;
- }
- else
- {
- rbnN.IsChecked = true;
- }
- #endregion
- }
- else
- {
- GridMain.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- //gridUpload.Visibility = Visibility.Collapsed;
- GridMyVideo.Visibility = Visibility.Collapsed;
- if (APP.pageData.pagenum > 0)
- {
- gridPage.Visibility = Visibility.Visible;
- }
- DataContext = APP.pageData;
- }
- }
- }
- /// <summary>
- /// 设置 保存事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnSave_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- ImgRecord.Visibility = Visibility.Visible;//设置结束时可录制
- ImgRecordTwo.Visibility = Visibility.Collapsed;//设置结束时可录制
- BtnRecord.IsEnabled = true;//设置结束时可录制
-
- if (!string.IsNullOrWhiteSpace(txbInterfaceAddress.Text))
- {
- string ApplicationData = APP.dataPath + "interfaceAddress.txt";
- string temp = "http://" + txbInterfaceAddress.Text;
- System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- }
- else
- {
- MessageWindow.Show("接口地址未输入");
- return;
- }
- if (!string.IsNullOrWhiteSpace(txbImageUploadAddress.Text))//图片上传地址
- {
- string ApplicationData = APP.dataPath + "imageUploadAddress.txt";
- string temp = "http://" + txbImageUploadAddress.Text + "/";
- System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- }
- else
- {
- MessageWindow.Show("上传地址未输入");
- return;
- }
- if (!string.IsNullOrWhiteSpace(txbPictureShowsAddress.Text))
- {
- string ApplicationData = APP.dataPath + "pictureShowsAddress.txt";
- string temp = "http://" + txbPictureShowsAddress.Text + "/static/";
- System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- }
- else
- {
- MessageWindow.Show("下载地址未输入");
- return;
- }
- if (!APP.apiUrl.Equals("http://" + txbInterfaceAddress.Text))
- {
- APP.apiUrl = "http://" + txbInterfaceAddress.Text;
-
- if (!txbLoginType.Text.Equals("未登录"))
- {
- LoginType();
- MessageWindow.Show("接口地址已修改,请重新登陆!");
- }
- }
- if (!APP.uploadUrl.Equals(txbImageUploadAddress.Text))
- {
- APP.uploadUrl = "http://" + txbImageUploadAddress.Text + "/";
- }
- if (!APP.showImageUrl.Equals(txbPictureShowsAddress.Text))
- {
- APP.showImageUrl = "http://" + txbPictureShowsAddress.Text + "/static/";
- }
- if (rbnMP4.IsChecked == true)
- {
- //存储文件
- FileToolsCommon.SetConfigValue("VideoType", "1");
- }
- else if (rbnFLV.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "2");
- }
- else
- {
- FileToolsCommon.SetConfigValue("VideoType", "3");
- }
- if (rbnY.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("IsSound", "true");
- }
- else
- {
- FileToolsCommon.SetConfigValue("IsSound", "false");
- }
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if (rbnRight.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "1");
- }
- else if (rbnLeft.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "2");
- }
- else if (rbnRightUnder.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "3");
- }
- else if (rbnLeftUnder.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "4");
- }
-
- if (rbnMP4.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "1");
- }
- else if (rbnFLV.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "2");
- }
- else if (rbnAVI.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "3");
- }
- APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- GridMain.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
- {
- //存储文件
- FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
- MessageWindow.Show("路径已变更,下次创建微课时自动生效!!!");
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message,ex);
- }
- }
- /// <summary>
- /// 设置 浏览事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBrowse_Click(object sender, RoutedEventArgs e)
- {
- //System.Diagnostics.Process.Start(APP.WKData.WkPath);
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- Ofd = new System.Windows.Forms.FolderBrowserDialog();
-
- Result = Ofd.ShowDialog();
- if (Result == System.Windows.Forms.DialogResult.OK)
- {
- if (Ofd.SelectedPath != "")
- {
-
-
- txbStoragePath.Content = Ofd.SelectedPath;
- //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
- //string temp = ofd.SelectedPath;
- //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- }
- }
- }
- #endregion
-
- #region 画笔
- /// <summary>
- /// 画笔颜色事件 白色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnWhite_Click(object sender, RoutedEventArgs e)
- {
- ////创建 DrawingAttributes 类的一个实例
- //drawingAttributes = new DrawingAttributes();
- ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- ////设置 DrawingAttributes 的 Color 属性设置颜色
- drawingAttributes.Color = Colors.White;
- Color = Colors.White;
- }
- /// <summary>
- /// 画笔颜色事件 红色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRed_Click(object sender, RoutedEventArgs e)
- {
- //设置 DrawingAttributes 的 Color 属性设置颜色
- drawingAttributes.Color = Colors.Red;
- Color = Colors.Red;
- imgRed.Visibility = Visibility.Visible;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 黑色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnGray_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Black;
- Color = Colors.Black;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Visible;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 青色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.LimeGreen;
- Color = Colors.LimeGreen;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Visible;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 黄色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnYellow_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Gold;
- Color = Colors.Gold;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Visible;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 蓝色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.DeepSkyBlue;
- Color = Colors.DeepSkyBlue;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Visible;
- }
- /// <summary>
- /// 画笔粗细事件 细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnFine_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 1;
- drawingAttributes.Height = 1;
- PenSize = 1;
- }
- /// <summary>
- /// 画笔粗细事件 中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnIn_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 3;
- drawingAttributes.Height = 3;
- PenSize = 3;
- }
- /// <summary>
- /// 画笔粗细事件 粗
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnCrude_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 5;
- drawingAttributes.Height = 5;
- PenSize = 5;
- }
- #endregion
-
- #region 导入截图
- /// <summary>
- /// 截图事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
- {
- Record();
- HideAngleBorder();
- imgCanvas.Margin = new Thickness(0, 0, 0, 0);
- APP.ImgPath = string.Empty;
- string time = GetTimeStamp();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
- APP.ImgPath = desktopPath;
- ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
- if (WindowState == WindowState.Normal)//截图隐藏窗口
- {
- WindowState = WindowState.Minimized;
- }
- if (APP.W_JieTuWindow != null)
- {
- APP.W_JieTuWindow.initialization();
- APP.W_JieTuWindow.Screenshot();
- APP.W_JieTuWindow.WindowState = WindowState.Maximized;
- APP.W_JieTuWindow.Visibility = Visibility.Visible;
- }
- else
- {
- APP.W_JieTuWindow = new JieTuWindow();
- // 订阅事件
- APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
- APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
- APP.W_JieTuWindow.Show();
- }
-
- //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
- }
- /// <summary>
- /// 截图关闭窗口
- /// </summary>
- /// <param name="text"></param>
- private void frm_ChangeTextEvent(string text)
- {
- if ("关闭窗口".Equals(text))
- {
- if (WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- Topmost = true;
- WindowState = WindowState.Normal;
- }
- if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
- {
- if (APP.pageData.currpage == 0)
- {
- APP.pageData.pagenum += 1;
- APP.pageData.currpage = APP.pageData.pagenum;
- myblackboard.changepage(APP.pageData.currpage - 1);
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageDrawList.Count >= APP.pageData.currpage)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
- APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = APP.ImgPath,
- PdfImagePath = APP.ImgPath
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- {
-
- imgDocumentation.Source = null;
- BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- mouseDown = false;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = 475,
- CenterY = 538
- };
-
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- imgCanvas.Source = bitImg;
- imgCanvas.Width = bitImg.Width;
- imgCanvas.Height = bitImg.Height;
- ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
-
-
- }
- }
- Topmost = false;
- }
- }
- /// <summary>
- /// 截图关闭 非正常关闭截图时,截图清空
- /// </summary>
- private void JietuWindow_click_closeJietuWindowClick()
- {
- if (WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- WindowState = WindowState.Normal;
- }
- APP.W_JieTuWindow = null;
- }
- /// 截图的图片鼠标右键事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- imgCanvas.Source = null;
- }
- /// <summary>
- /// 导入事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnImport_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- Record();
- HideAngleBorder();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- ofd = new System.Windows.Forms.OpenFileDialog
- {
- //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
- Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
- InitialDirectory = desktopPath,
- Multiselect = false,
- AddExtension = true,
- DereferenceLinks = true
- };
-
-
- //APP.myloading.Show();
- APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
-
-
- //new Thread(
- // o =>
- // {
- // Thread.Sleep(400);
-
- // Dispatcher.Invoke(new Action(() =>
- // {
- // OpenDialog();
- // }
- // ));
- // })
- //{
- // IsBackground = true
- //}.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 导入-开始
- /// </summary>
- /// <returns></returns>
- private object InvokeServering()
- {
- Dispatcher.Invoke(new Action(() =>
- {
- result = ofd.ShowDialog();
- }));
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- if (ofd.FileName != "")
- {
- Dispatcher.Invoke(new Action(() =>
- {
- APP.myloading.Show();
- myblackboard.changepage(APP.pageData.pagenum);
- }));
- #region PPT转PDF
- string filepath = ofd.FileName;
- string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
- string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
- if (type.Contains("typezsygppt"))//ppt
- {
- try
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- path = pathTemp + path + ".pdf";
- FileToolsCommon.CreateDirectory(pathTemp);
-
- //PPT转PDF
- Presentation ppt = new Presentation(filepath);
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
- #endregion
-
- #region PDF转图片
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
- #endregion
-
- Dispatcher.Invoke(new Action(() =>
- {
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.pageData.pagenum],
- PdfImagePath = page[i - APP.pageData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
-
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
-
- }));
- }
- catch (Exception ex)
- {
- MessageWindow.Show("文件无效或者文件被加密!");
- LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else if (type.Contains("typepdf"))
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- #region PDF转图片
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
- #endregion
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.pageData.pagenum],
- PdfImagePath = page[i - APP.pageData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- else//word
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
- int num = 0;
- Dispatcher.Invoke(new Action(() =>
- {
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.pageData.pagenum],
- PdfImagePath = page[i - APP.pageData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
-
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Visibility = Visibility.Visible;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
-
- }));
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
- }
- }
- }
- }
- //OpenDialog();
- return "";
- }
- /// <summary>
- /// 导入-结束
- /// </summary>
- /// <returns></returns>
- public void InvokeServerCompate(object obj)
- {
- //APP.myloading.Hide();
- APP.myloading.Hide();
- }
- /// <summary>
- /// 导入文档
- /// </summary>
- private void OpenDialog()
- {
-
- Dispatcher.Invoke(new Action(() =>
- {
- result = ofd.ShowDialog();
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- if (ofd.FileName != "")
- {
- APP.myloading.Show();
-
- myblackboard.changepage(APP.pageData.pagenum);
- #region PPT转PDF
- string filepath = ofd.FileName;
- string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
- string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
- if (type.Contains("typezsygppt"))//ppt
- {
- try
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- path = pathTemp + path + ".pdf";
- FileToolsCommon.CreateDirectory(pathTemp);
-
- //PPT转PDF
- Presentation ppt = new Presentation(filepath);
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
- #endregion
-
- #region PDF转图片
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
- #endregion
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.pageData.pagenum],
- PdfImagePath = page[i - APP.pageData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- MessageWindow.Show("文件无效或者文件被加密!");
- LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else if (type.Contains("typepdf"))
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- #region PDF转图片
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
- Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
- #endregion
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.pageData.pagenum],
- PdfImagePath = page[i - APP.pageData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- else//word
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageImagePath = page[i - APP.pageData.pagenum],
- PdfImagePath = page[i - APP.pageData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true
- };
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
-
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Visibility = Visibility.Visible;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
- }
- }
- }
- }
- }
- ));
-
- }
- #endregion
-
- #region 上传 列表
- /// <summary>
- /// 上传事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- //if (gridUpload.Visibility == Visibility.Visible)
- //{
- // gridUpload.Visibility = Visibility.Collapsed;
- // GridMain.Visibility = Visibility.Visible;
- // //ImgRecord.Visibility = Visibility.Visible;//上传结束时可录制
- // //ImgRecordTwo.Visibility = Visibility.Collapsed;//上传结束时可录制
- // //BtnRecord.IsEnabled = true;//设置结束时可录制
- // if (APP.pageData.pagenum > 0)
- // {
- // gridPage.Visibility = Visibility.Visible;
- // }
- // DataContext = APP.pageData;
- //}
- //else
- //{
- // gridPage.Visibility = Visibility.Collapsed;
- // gridUpload.Visibility = Visibility.Visible;
- // GridMain.Visibility = Visibility.Collapsed;
- // //ImgRecord.Visibility = Visibility.Collapsed;//上传时不可录制
- // //ImgRecordTwo.Visibility = Visibility.Visible;//上传时不可录制
- // //BtnRecord.IsEnabled = false;//上传时不可录制
- // InitializeUpload();
- //}
-
- if (GridMyVideo.Visibility == Visibility.Visible)
- {
- GridMyVideo.Visibility = Visibility.Collapsed;
- GridMain.Visibility = Visibility.Visible;
- if (APP.pageData.pagenum > 0)
- {
- gridPage.Visibility = Visibility.Visible;
- }
- DataContext = APP.pageData;
- }
- else
- {
- gridSetUp.Visibility = Visibility.Collapsed;
- gridPage.Visibility = Visibility.Collapsed;
- GridMyVideo.Visibility = Visibility.Visible;
- GridMain.Visibility = Visibility.Collapsed;
- LoadUploadInitData();
- }
- //btnStop.IsEnabled = true;//停止录制按钮可点击
- }
- /// <summary>
- /// 初始化上传
- /// </summary>
- public void InitializeUpload()
- {
- APP.myloading.Show();
-
- MouseNumber = 0;
- IsModify = false;
- //加载视频列表
- LoadingVideoList();
- int i = 1;
- bool isColour = true;
- pageData.menuList.Clear();
- //显示视频
- foreach (Model_Video videoinfo in model_VideoList)
- {
- //是否已上传
- //videoinfo.IsUpload;
- //录制时间
- //videoinfo.RSTime;
- //文件大小
- //videoinfo.VideoSize;
- //文件缩略图路径
- //videoinfo.ThumbnailPath;
- //文件唯一标示 上传事件筛选需要上传的视频
- //videoinfo.FileGuid;
- //文件存储路径
- //videoinfo.VidePath;
-
- string colour = "#FFFFFF";
- if (isColour == true)
- {
- colour = "#FFFFFF";
- isColour = false;
- }
- else
- {
- colour = "#E6F1FF";
- isColour = true;
- }
- string vis = "Visible";
- string cos = "Collapsed";
- if (!videoinfo.IsUpload)
- {
- vis = "Collapsed";
- cos = "Visible";
- }
- //if(i==1)//ceshi
- //{
- // vis = "Visible";
- // cos = "Collapsed";
- //}
- if (i <= 16)
- {
- pageData.menuList.Add(new FileDirectoryModel()
- {
- SerialNumber = i,
- VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
- VideoDuration = 0,
- VideoSize = videoinfo.VideoSize,
- VideoTime = videoinfo.RSTime,
- IsEnabled = false,
- Path = videoinfo.VideoPath,
- Colour = colour,
- Visi = vis,
- Coll = cos,
- FileGuid = videoinfo.FileGuid,
- VideoType = videoinfo.VideoType.ToString(),
- VideoSizes= videoinfo.VideoSizebyte
- }); ;
- }
- i++;
- }
- Currpage = 0;
- PageNum = 0;
- if (pageData.menuList.Count > 0)
- {
- Currpage = 1;
- txbCurrpageTwo.Text = Currpage.ToString();
- stpUp.Visibility = Visibility.Visible;
- }
- else
- {
- stpUp.Visibility = Visibility.Hidden;
- }
- PageNum = model_VideoList.Count;
- if (PageNum > 0)
- {
- int t = 1;
- while (PageNum > 16 * t)
- {
- t++;
- }
- PageNum = t;
- }
- else
- {
- PageNum = 0;
- }
- txbPageNumTwo.Text = PageNum.ToString();
- APP.myloading.Hide();
- DataContext = pageData;
- }
-
- /// <summary>
- /// 当前页
- /// </summary>
- private int Currpage = 0;
-
- /// <summary>
- /// 总页码
- /// </summary>
- private int PageNum = 0;
- /// <summary>
- /// 加载视频列表
- /// </summary>
- public void LoadingVideoList()
- {
- try
- {
- model_VideoList = new List<Model_Video>();
- foreach (Model_WKData Vdata in APP.WKDataList)
- {
- #region 计时器初始化
- if (Vdata.VideoList == null)
- {
- continue;
- }
-
- foreach (Model_Video videoinfo in Vdata.VideoList)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
- {
- continue;
- }
- if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
- {
- videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
- videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
- }
- model_VideoList.Add(videoinfo);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
- #endregion
- }
- //翻转
- if(model_VideoList.Count>1)
- {
- model_VideoList.Reverse();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
- ////定义事件
- //public event ChangeTextHandler ChangeTextEvents;
- /// <summary>
- /// 上传
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnUploads_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- pageData.menuList[Subscript].IsEnabled = false;
- List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnUpload");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- DAL_Upload dAL_Upload = new DAL_Upload();
-
- if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
- {
-
- //MessageWindow.Show("视频上传服务器成功!");
- if (APP.W_UploadWindow == null)
- {
- APP.W_UploadWindow = new UploadWindow
- {
- Owner = this
- };
- APP.W_UploadWindow.ChangeTextEvents += new ChangeTextHandlers(frm_ChangeTextEvents);
- }
-
- //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
- APP.W_UploadWindow.Initialize(pageData.menuList[i].VideoName, pageData.menuList[i].VideoSizes, pageData.menuList[i].VideoType, pageData.menuList[i].FileGuid,i);
- APP.W_UploadWindow.ShowDialog();
- }
- else
- {
- MessageWindow.Show(ErrMessage);
- }
- }
- }
- }
- /// <summary>
- /// 上传返回事件
- /// </summary>
- /// <param name="text"></param>
- private void frm_ChangeTextEvents(string text,int i)
- {
- if ("上传成功".Equals(text))
- {
- pageData.menuList[i].Visi = "Visible";
- pageData.menuList[i].Coll = "Collapsed";
-
- DataContext = pageData;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDelete_Click(object sender, RoutedEventArgs e)
- {
- MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- pageData.menuList[Subscript].IsEnabled = false;
- List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnDelete");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
-
- //if (APP.W_PromptWindow == null)
- //{
- // APP.W_PromptWindow = new PromptWindow();
- // APP.W_PromptWindow.Owner = this;
- //}
- //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
- //APP.W_PromptWindow.ShowDialog();
-
- foreach (Model_WKData wKData in APP.WKDataList)
- {
- if (wKData.VideoList == null)
- {
- continue;
- }
-
- if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
- {
- try
- {
- FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
- FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
- wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
- InitializeUpload();
- return;
- }
- catch (Exception ex)
- {
- MessageWindow.Show("无法删除视频!" + ex.Message);
- return;
- }
- }
- }
- }
- }
- }
- }
- /// <summary>
- /// 播放
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPlay_Click(object sender, RoutedEventArgs e)
- {
- pageData.menuList[Subscript].IsEnabled = false;
- List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnPlay");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- try
- {
- ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
- Process pro = new Process
- {
- StartInfo = psi
- };
- pro.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
- System.Windows.MessageBox.Show(ex.Message);
- return;
- }
- }
- }
- }
- /// <summary>
- /// 搜索集合匹配的索引
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="parent"></param>
- /// <param name="childName"></param>
- /// <returns></returns>
- public static List<T> FindChilds<T>(DependencyObject parent, string childName)
- where T : DependencyObject
- {
- List<T> list = new List<T>();
- if (parent == null)
- {
- return list;
- }
-
- int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
- for (int i = 0; i < childrenCount; i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(parent, i);
- // 如果子控件不是需查找的控件类型
- T childType = child as T;
- if (childType == null)
- {
- // 在下一级控件中递归查找
- List<T> findChildList = FindChilds<T>(child, childName);
- for (int j = 0; j < findChildList.Count; j++)
- {
- }
- list.AddRange(FindChilds<T>(child, childName));
- }
- else if (!string.IsNullOrEmpty(childName))
- {
- FrameworkElement frameworkElement = child as FrameworkElement;
- // 如果控件名称符合参数条件
- if (frameworkElement != null && frameworkElement.Name == childName)
- {
- list.Add((T)child);
- }
- }
- else
- {
- // 查找到了控件
- list.Add((T)child);
- }
- }
-
- return list;
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnModify_Click(object sender, RoutedEventArgs e)
- {
- if (IsModify)
- {
- try
- {
- string newName = pageData.menuList[Subscript].VideoName +"."+ pageData.menuList[Subscript].VideoType;
- bool isName = ModifyPathName(pageData.menuList[Subscript].FileGuid, newName, out string Errmessage);
- if (!isName)
- {
- MessageWindow.Show(Errmessage);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("XHMicroLessonSystemWindow(BtnModify_Click)" + ex.Message, ex);
- }
- IsModify = false;
- pageData.menuList[Subscript].IsEnabled = false;
- listView1.DataContext = pageData;
- }
- else
- {
- List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnModify");
- for (int i = 0; i < buttons.Count; i++)
- {
- if (buttons[i] == sender)
- {
- pageData.menuList[i].IsEnabled = true;
- Subscript = i;
- IsModify = true;
- }
- }
- }
-
- }
-
- private int MouseNumber = 0;
- /// <summary>
- /// 上传 上页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnLastPage_Click(object sender, RoutedEventArgs e)
- {
- if (Currpage > 1)
- {
- Currpage -= 1;
- txbCurrpageTwo.Text = Currpage.ToString();
- int i = 1;
- bool isColour = true;
- pageData.menuList.Clear();
- //显示视频
- foreach (Model_Video videoinfo in model_VideoList)
- {
- //是否已上传
- //videoinfo.IsUpload;
- //录制时间
- //videoinfo.RSTime;
- //文件大小
- //videoinfo.VideoSize;
- //文件缩略图路径
- //videoinfo.ThumbnailPath;
- //文件唯一标示 上传事件筛选需要上传的视频
- //videoinfo.FileGuid;
- //文件存储路径
- //videoinfo.VidePath;
-
- string colour = "#FFFFFF";
- if (isColour == true)
- {
- colour = "#FFFFFF";
- isColour = false;
- }
- else
- {
- colour = "#E6F1FF";
- isColour = true;
- }
- string vis = "Visible";
- string cos = "Collapsed";
- if (!videoinfo.IsUpload)
- {
- vis = "Collapsed";
- cos = "Visible";
- }
- if (i <= Currpage * 16 && i >= (Currpage - 1) * 16)
- {
- pageData.menuList.Add(new FileDirectoryModel()
- {
- SerialNumber = i,
- VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
- VideoDuration = 0,
- VideoSize = videoinfo.VideoSize,
- VideoTime = videoinfo.RSTime,
- IsEnabled = false,
- Path = videoinfo.VideoPath,
- Colour = colour,
- Visi = vis,
- Coll = cos,
- FileGuid = videoinfo.FileGuid,
- VideoType = videoinfo.VideoType.ToString()
- }); ;
- }
- i++;
- }
- APP.myloading.Hide();
- }
- }
- /// <summary>
- /// 上传 下页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnNextPage_Click(object sender, RoutedEventArgs e)
- {
- if (Currpage < PageNum)
- {
- Currpage += 1;
- txbCurrpageTwo.Text = Currpage.ToString();
- int i = 1;
- bool isColour = true;
- pageData.menuList.Clear();
- //显示视频
- foreach (Model_Video videoinfo in model_VideoList)
- {
- //是否已上传
- //videoinfo.IsUpload;
- //录制时间
- //videoinfo.RSTime;
- //文件大小
- //videoinfo.VideoSize;
- //文件缩略图路径
- //videoinfo.ThumbnailPath;
- //文件唯一标示 上传事件筛选需要上传的视频
- //videoinfo.FileGuid;
- //文件存储路径
- //videoinfo.VidePath;
-
- string colour = "#FFFFFF";
- if (isColour == true)
- {
- colour = "#FFFFFF";
- isColour = false;
- }
- else
- {
- colour = "#E6F1FF";
- isColour = true;
- }
- string vis = "Visible";
- string cos = "Collapsed";
- if (!videoinfo.IsUpload)
- {
- vis = "Collapsed";
- cos = "Visible";
- }
- if (i <= Currpage * 16 && i > (Currpage - 1) * 16)
- {
- pageData.menuList.Add(new FileDirectoryModel()
- {
- SerialNumber = i,
- VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
- FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
- VideoDuration = 0,
- VideoSize = videoinfo.VideoSize,
- VideoTime = videoinfo.RSTime,
- IsEnabled = false,
- Path = videoinfo.VideoPath,
- Colour = colour,
- Visi = vis,
- Coll = cos,
- FileGuid = videoinfo.FileGuid,
- VideoType = videoinfo.VideoType.ToString()
- }); ;
- }
- i++;
- }
- APP.myloading.Hide();
- }
- }
-
- /// <summary>
- /// 修改文件名
- /// </summary>
- /// <param name="Guid">唯一编号</param>
- /// <param name="NewName">新文件名带后缀 不带路径</param>
- /// <param name="Errmessage">错误信息</param>
- /// <returns></returns>
- private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
- {
- Errmessage = "";
- foreach(Model_WKData WKData in APP.WKDataList)
- {
- if (WKData.VideoList.Exists(x => x.FileGuid == FileGuid))
- {
-
- Model_Video model_Video = WKData.VideoList.Find(x => x.FileGuid == FileGuid);
-
- string filePathName = model_Video.VideoPath;
- string filePath = FileToolsCommon.GetDirectoryName(filePathName);
- string newFilePathName = filePath + NewName;
- //缩略图
- string ThumbnailPath = filePath + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
- if (FileToolsCommon.IsExistFile(newFilePathName))
- {
- Errmessage = "文件已存在,请重新修改文件名!";
- return false;
- }
- else
- {
- //修改文件名
- FileToolsCommon.Copy(filePathName, newFilePathName);
- model_Video.VideoPath = newFilePathName;
- //修改缩略图名
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
- model_Video.ThumbnailPath = ThumbnailPathName;
- APP.SaveWkData();
- return true;
- }
- }
- else
- {
- continue;
- }
- }
- Errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
- return false;
- }
-
- #endregion
- #region 新上传 显示缩略图
- #region 初始值
- /// <summary>
- /// 总页数
- /// </summary>
- int TotalPage=0;
- /// <summary>
- /// 当前页
- /// </summary>
- int CurrentPage = 1;
- /// <summary>
- /// 每页显示的视频数
- /// </summary>
- int PageShowNum = 0;
- /// <summary>
- /// 视频信息列表
- /// </summary>
- List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
- /// <summary>
- /// 横向间隔
- /// </summary>
- double IntervalX = 0;
- /// <summary>
- /// 纵向间隔
- /// </summary>
- double IntervalY = 0;
- #endregion
- /// <summary>
- /// 初始化加载上传页面数据
- /// </summary>
- void LoadUploadInitData()
- {
- APP.myloading.Show();
- //加载视频列表
- LoadingVideoList();
- if (model_VideoList.Count > 0)
- {
- lblVideoMess.Visibility = Visibility.Hidden;
- BtnVideoUpPage.Visibility = Visibility.Visible;
- lblVideoPageNum.Visibility = Visibility.Visible;
- BtnVideoDownPage.Visibility = Visibility.Visible;
- //根据页面大小获取每页显示的数量 H300W250
- int videoRow = (int)((GridMyVideo.ActualHeight - 50) / 300);
- int videColumn = (int)(GridMyVideo.ActualWidth / 250);
- PageShowNum = videoRow * videColumn;
- //获取总页数
- TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
- //如果当前页大于总页数 总页数为当前页
- if (TotalPage < CurrentPage)
- {
- CurrentPage = TotalPage;
- }
- //横向间隔
- IntervalX = (GridMyVideo.ActualWidth - (videColumn * 250)) / (videColumn + 1);
- IntervalY = (GridMyVideo.ActualHeight - 50 - (videoRow * 300)) / (videoRow + 1);
- LoadCurrentPageData();
- }
- else
- {
- lblVideoMess.Visibility = Visibility.Visible;
- BtnVideoUpPage.Visibility = Visibility.Hidden;
- lblVideoPageNum.Visibility = Visibility.Hidden;
- BtnVideoDownPage.Visibility = Visibility.Hidden;
- }
- APP.myloading.Hide();
- }
- /// <summary>
- /// 加载当前页数据
- /// </summary>
- private void LoadCurrentPageData()
- {
- lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
- //隐藏显示的控件
- if(VideoControlList.Count>0)
- {
- foreach(Uc_VideoItem item in VideoControlList)
- {
- if (item.Visibility != Visibility.Hidden)
- {
- item.Visibility = Visibility.Hidden;
- }
- }
- }
- double W = IntervalX;//每次增加250
- double H = IntervalY;//每次增加300
- //加载控件
- for(int i=0;i< PageShowNum;i++)
- {
- int DataIndex = (CurrentPage - 1) * PageShowNum + i;
- if(DataIndex== model_VideoList.Count)
- {
- return;
- }
- Uc_VideoItem videoItem;
- if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
- {
- videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
- }
- else
- {
- videoItem = new Uc_VideoItem(model_VideoList[DataIndex]);
- videoItem.Tag = model_VideoList[DataIndex].FileGuid;
- videoItem.Click_refreshVideoList += LoadUploadInitData;
- videoItem.Click_UploadLogin += Login;
- videoItem.Width = 250;
- videoItem.Height = 300;
- videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
- videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
- GridMyVideo.Children.Add(videoItem);
- VideoControlList.Add(videoItem);
- }
- videoItem.Margin = new Thickness(W, H, 0, 0);
- videoItem.Visibility = Visibility.Visible;
- if (W + 250+250>GridMyVideo.ActualWidth)
- {
- W = IntervalX;
- H += 300+ IntervalY;
- }
- else
- {
- W += 250+ IntervalX;
- }
- //Uc_VideoItem videoItem = new Uc_VideoItem();
- //return;
- }
- }
-
- #region 分页
- /// <summary>
- /// 上一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
- {
- if(CurrentPage>1)
- {
- CurrentPage--;
- LoadCurrentPageData();
- }
- }
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
- {
- if (CurrentPage < TotalPage)
- {
- CurrentPage++;
- LoadCurrentPageData();
- }
- }
- #endregion
- #endregion
- #region 录制窗口
- #region 变量
- /// <summary>
- /// 视频保存路径
- /// </summary>
- //string RecordingPath;
- /// <summary>
- /// 图片保存路径
- /// </summary>
- private string ImgPath;
-
- /// <summary>
- /// 音频保存路径名
- /// </summary>
- private string AudioPathName;
-
- /// <summary>
- /// 视频保存路径名
- /// </summary>
- private string VideoSavePathName;
-
- /// <summary>
- /// 视频合成路径名
- /// </summary>
- private string VideoSynthesisPathName;
-
- /// <summary>
- /// 暂停录制
- /// </summary>
- private bool IsSuspendR = true;
-
- /// <summary>
- /// 录制是否已停止
- /// </summary>
- private bool IsFirstR = true;
-
- /// <summary>
- /// 图片
- /// </summary>
- private List<string> RsImgName = null;
-
- /// <summary>
- /// 是否开始截图计数
- /// </summary>
- private bool IsStartCount = false;
-
- /// <summary>
- /// 是否录制了音频
- /// </summary>
- private bool IsRecordAudio = false;
-
- /// <summary>
- /// 截图定时器
- /// </summary>
- private System.Threading.Timer timer;
- /// <summary>
- /// 录制计时
- /// </summary>
- private DateTime SRTime = DateTime.Now;
- #endregion
-
- #region 录屏
- /// <summary>
- /// 录屏事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
- {
- Record();
- if (!APP.CheckScreenCapturerRecorder())
- {
- MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
- APP.InstallScreenCapturerRecorder();
- return;
- }
- #region 限制只允许录制一个录屏 废弃
- //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
- //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
- //{
- // MessageBoxResult dr = MessageWindow.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
- // if (dr == MessageBoxResult.OK)
- // {
- // try
- // {
- // FileToolsCommon.DeleteFile(RecordScreenPathName);
- // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
- // }
- // catch (Exception ex)
- // {
- // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
- // }
- // }
- // else
- // {
- // return;
- // }
- //}
- #endregion
- if (APP.W_ScreenRecordingToolbarWindow == null)
- {
- APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
- {
- Topmost = true
- };
- APP.W_ScreenRecordingToolbarWindow.Initialize();
-
- }
- else
- {
- APP.W_ScreenRecordingToolbarWindow.Initialize();
- }
- APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
- //显示在右下角
- APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
- Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
- float DIP = graphics.DpiX;
- float DIPY = graphics.DpiY;
- APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width - 60;
- APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 30;
- APP.W_ScreenRecordingToolbarWindow.Topmost = true;
- APP.W_ScreenRecordingToolbarWindow.Show();
- Hide();
- }
- /// <summary>
- /// 保存录屏中
- /// </summary>
- private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
- {
- txbType.Visibility = Visibility.Visible;
- txbType.Text = "保存中";
- btnScreenRecording.IsEnabled = false;
-
- new Thread(new ThreadStart(new Action(() =>
- {
- while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
- {
- Thread.Sleep(100);
- }
- Thread.Sleep(100);
- Dispatcher.Invoke(() =>
- {
- btnScreenRecording.IsEnabled = true;
- txbType.Visibility = Visibility.Hidden;
- //TxbRecordScreenWord.Text = "录屏";
- });
- }))).Start();
-
- }
- #endregion
-
- /// <summary>
- /// 录制窗口内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRecord_Click(object sender, RoutedEventArgs e)
- {
- Record();
- if (!APP.CheckScreenCapturerRecorder())
- {
- MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
- APP.InstallScreenCapturerRecorder();
- return;
- }
- if (APP.pageData.currpage > 0)
- {
- blackboard_canvas.Visibility = Visibility.Visible;
- }
- else
- {
- MessageWindow.Show("请先导入文档或截图!");
- return;
- }
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- }
- //btnStop.IsEnabled = true;//停止录制按钮可点击
- StartRecord();
- }
- /// <summary>
- /// 停止录制窗口内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnStop_Click(object sender, RoutedEventArgs e)
- {
- blackboard_canvas.Visibility = Visibility.Collapsed;
- EndRecord();
- }
-
- /// <summary>
- /// 设置录屏文件地址
- /// </summary>
- private void SetUpVideoPathName()
- {
- }
-
- /// <summary>
- /// 开始录制和暂停录制
- /// </summary>
- private void StartRecord()
- {
- if (IsSuspendR)
- {
- if (IsFirstR)//是否第一次录制 初始化录制
- {
- #region 检测麦克风扬声器是否可用
- string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
- string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
- try
- {
- FileToolsCommon.DeleteFile(audioSpeakerPath);
- FileToolsCommon.DeleteFile(audioMicrophonePath);
- }
- catch (Exception)
- {
-
- }
- //扬声器
- if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
- {
- APP.FFmpeg.StopRecordAudio(2);
- //Thread.Sleep(500);
- //麦克风
- if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
- {
- }
- else
- {
- //无法录制麦克风
- MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
- if (Res == MessageBoxResult.Cancel)
- {
- return;
- }
- }
- APP.FFmpeg.StopRecordAudio(1);
- }
- else
- {
- //无法录制扬声器音频
- MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
- if (Res == MessageBoxResult.Cancel)
- {
- return;
- }
- }
- #endregion
-
- #region 计时器初始化
-
- //if (t == null)
- //{
- // t = new DispatcherTimer();
- // t.Tick += OnTimer;
- // t.Interval = new TimeSpan(0, 0, 0, 1);
- // t.IsEnabled = true;
- // t.Start();
- //}
- //t.Interval = new TimeSpan(0, 0, 0, 1);
- txbTime.Visibility = Visibility.Visible;
- #endregion
-
- VideoInfo = new Model_Video
- {
- VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
- WkType = Enum_WKVidetype.RecordingLessons
- };
-
- ImgPath = APP.WKData.WkPath + "temp/Image/";
- AudioPathName = APP.WKData.WkPath + "temp/audio/";
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
- FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
- FileToolsCommon.CreateDirectory(ImgPath);
- FileToolsCommon.CreateDirectory(AudioPathName);
- AudioPathName += APP.WKData.WkName + ".MP3";
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
- VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
- int num = 1;
- while (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
- VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
- num++;
- }
-
- #region 设置录屏唯一 废弃
- //if (FileToolsCommon.IsExistFile(VideoSavePathName))
- //{
- // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
- // if (dr == MessageBoxResult.OK)
- // {
- // try
- // {
- // FileToolsCommon.DeleteFile(VideoSavePathName);
- // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
- // }
- // catch (Exception ex)
- // {
- // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
- // }
- // }
- // else
- // {
- // return;
- // }
- //}
- #endregion
-
- #region 禁用按钮
- ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
- ImgPrintTwo.Visibility = Visibility.Visible;
- btnPrint.IsEnabled = false;
-
- ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
-
- ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
- ImgImportTwo.Visibility = Visibility.Visible;
- btnImport.IsEnabled = false;
-
- ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
- ImgScreenRecordingTwo.Visibility = Visibility.Visible;
- btnScreenRecording.IsEnabled = false;
-
- ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
- ImgUploadTwo.Visibility = Visibility.Visible;
- btnUpload.IsEnabled = false;
-
- ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
- ImgSetUpTwo.Visibility = Visibility.Visible;
- btnSetUp.IsEnabled = false;
-
- btnLoginType.IsEnabled = false;
- blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
-
-
- //myblackboard = new BlackboardNew(blackboard_canvas);
- //DataContext = APP.pageData;
- //drawingAttributes = new DrawingAttributes();
- ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- //blackboard_canvas.UseCustomCursor = true;
- //drawingAttributes.FitToCurve = true;
- //drawingAttributes.IgnorePressure = false;
- //drawingAttributes.Width = PenSize;
- //drawingAttributes.Height = PenSize;
- //drawingAttributes.Color = Color;
- //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
- #endregion
-
- #region 录像倒计时
- if (APP.W_CountdownWindow == null)
- {
- APP.W_CountdownWindow = new CountdownWindow();
- APP.W_CountdownWindow.Initialize();
- //APP.W_CountdownWindow.Topmost = true;
- }
- else
- {
- APP.W_CountdownWindow.Initialize();
- //APP.W_CountdownWindow.Topmost = true;
- }
- APP.W_CountdownWindow.Show();
- #endregion
- IsFirstR = false;
- RsImgName = new List<string>();
- SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
- txbTime.Visibility = Visibility.Visible;
- ///启动截图
- timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
- //{
- // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
- //};//设置执行一次(false)还是一直执行(true)
- //timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
- //timer.Enabled = true; //启动计时器
- }
-
- //继续录制
- IsSuspendR = false;
- //BtnRecording.Content = "暂停录制";
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
- TxbRecordingWord.Text = "暂停";
- #region 4秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- btnStop.IsEnabled = false;
- ImgStop.Visibility = Visibility.Visible;
- ImgStopTwo.Visibility = Visibility.Collapsed;
- });
- }))).Start();
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(4000);
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- ImgStop.Visibility = Visibility.Collapsed;
- ImgStopTwo.Visibility = Visibility.Visible;
- });
- }))).Start();
- #endregion
- try
- {
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(1000);
- IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName);
- Thread.Sleep(1000);
- Dispatcher.Invoke(() =>
- {
- Recorddt = DateTime.Now;
- IsStartCount = true;
- //Stack();
- //timer.Start();
- });
- }))).Start();
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- else
- {
- //暂停
- IsSuspendR = true;
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
- ImgStop.Visibility = Visibility.Collapsed;
- ImgStopTwo.Visibility = Visibility.Visible;
- TxbRecordingWord.Text = "继续";
- //TimeOut();
- #region 2秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- btnStop.IsEnabled = false;
- });
- Thread.Sleep(2000);
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- });
- }))).Start();
- #endregion
- try
- {
- APP.FFmpeg.SuspendFFmpeg();
- new Thread(new ThreadStart(new Action(() =>
- {
- while (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- IsStartCount = false;
- }))).Start();
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- }
- /// <summary>
- /// 记录上次截图时间
- /// </summary>
- DateTime Recorddt = DateTime.Now;
- /// <summary>
- /// 录制保存图片计时器
- /// </summary>
- /// <param name="sender"></param>
- private void Timer_Elapsed(object sender)
- {
- if (IsStartCount)
- {
- DateTime dt = DateTime.Now;
- TimeSpan ts = dt.Subtract(Recorddt);//时间差
- double tsmi = ts.TotalMilliseconds;
- if (tsmi > 200.0)
- {
- Recorddt = Recorddt.AddMilliseconds(200);
- Thread thread = new Thread(RecordSaveImage);
- //开启线程
- thread.Start();
- }
- }
- }
- /// <summary>
- /// 录制保存图片
- /// </summary>
- void RecordSaveImage()
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- if (IsStartCount)
- {
- string FilePathName = ImgPath + RsImgName.Count + ".png";
- RsImgName.Add(FilePathName);
- ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)));
- SRTime = SRTime.AddMilliseconds(200);
- if (txbTime.Visibility == Visibility.Hidden)
- {
- txbTime.Visibility = Visibility.Visible;
- }
- if (SRTime.Hour > 0)
- {
- //Dispatcher.Invoke(() =>
- //{
- txbTime.Text = SRTime.ToString("HH:mm:ss");
- //});
- }
- else
- {
- //Dispatcher.Invoke(() =>
- //{
- txbTime.Text = SRTime.ToString("mm:ss");
- //});
- }
- }
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
- /// <summary>
- /// 停止录制并生成录制文件
- /// </summary>
- private void EndRecord()
- {
- if (!IsFirstR)
- {
- #region 恢复被禁用的按钮
- ImgPrint.Visibility = Visibility.Visible;
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
-
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
-
- ImgImport.Visibility = Visibility.Visible;
- ImgImportTwo.Visibility = Visibility.Collapsed;
- btnImport.IsEnabled = true;
-
- ImgScreenRecording.Visibility = Visibility.Visible;
- ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
- btnScreenRecording.IsEnabled = true;
-
- ImgUpload.Visibility = Visibility.Visible;
- ImgUploadTwo.Visibility = Visibility.Collapsed;
- btnUpload.IsEnabled = true;
-
- ImgSetUp.Visibility = Visibility.Visible;
- ImgSetUpTwo.Visibility = Visibility.Collapsed;
- btnSetUp.IsEnabled = true;
-
- btnLoginType.IsEnabled = true;
-
-
- //btnStop.IsEnabled = false;//停止录制按钮不可点击
-
- #endregion
-
- IsSuspendR = true;
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
- ImgStop.Visibility = Visibility.Visible;
- ImgStopTwo.Visibility = Visibility.Collapsed;
- //TimeOut();
- txbType.Visibility = Visibility.Visible;
- txbType.Text = "保存中";
- #region 2秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- btnStop.IsEnabled = false;
- });
- }))).Start();
- #endregion
- try
- {
- #region 清空画板数据
- APP.pageData.currpage = 0;
- APP.pageData.pagenum = 0;
- myblackboard.clear();
-
- //myblackboard = new BlackboardNew(blackboard_canvas);
- //DataContext = APP.pageData;
- //drawingAttributes = new DrawingAttributes();
- ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- //blackboard_canvas.UseCustomCursor = true;
- //drawingAttributes.FitToCurve = true;
- //drawingAttributes.IgnorePressure = false;
- //drawingAttributes.Width = PenSize;
- //drawingAttributes.Height = PenSize;
- //drawingAttributes.Color = Color;
- //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
-
- APP.PageDrawList.Clear();
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- gridPage.Visibility = Visibility.Collapsed;
- #endregion
-
- //缩略图
- string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
- int gridActWidth = (int)GridMain.ActualWidth;
- int gridActHeight = (int)GridMain.ActualHeight;
- APP.FFmpeg.StopFFmpeg(AudioPathName);
- new Thread(new ThreadStart(new Action(() =>
- {
- IsStartCount = false;
- //停止截图
- while (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- Dispatcher.Invoke(() =>
- {
- timer.Change(-1, 0);
- timer.Dispose();
- //End();
- txbTime.Text = "";
- txbTime.Visibility = Visibility.Hidden;
- });
- //}))).Start();
- //new Thread(new ThreadStart(new Action(() =>
- //{
- //判断音频是否存在 判断音频临时文件夹是否存在
- if (IsRecordAudio)
- {
- if (!FileToolsCommon.IsExistFile(AudioPathName))
- {
- Thread.Sleep(100);
- }
- if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
- {
- Thread.Sleep(100);
- }
- }
- else
- {
- //没有录制音频
- AudioPathName = null;
- }
- //合成视频
- bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight);
- //}))).Start();
- //new Thread(new ThreadStart(new Action(() =>
- //{
- if (!SynRes)
- {
- Dispatcher.Invoke(() =>
- {
- MessageWindow.Show("视频录制失败,无法保存此视频!");
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- TxbRecordingWord.Text = "录制";
- txbType.Text = "";
- });
- return;
- }
- Dispatcher.Invoke(() =>
- {
- txbType.Text = "转码中";
- });
- while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
- {
- Thread.Sleep(100);
- }
- while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
- {
- Thread.Sleep(100);
- }
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- Thread.Sleep(500);
- //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
- VideoInfo.VideoPath = VideoSavePathName;
- VideoInfo.ThumbnailPath = ThumbnailPathName;
- //生成缩略图
- bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName,200,130);
- Thread.Sleep(500);
- int imgW = (int)GridMain.ActualWidth + (GridMain.ActualWidth % 2 > 0 ? 1 : 0);
- int imgH = (int)GridMain.ActualHeight + (GridMain.ActualHeight % 2 > 0 ? 1 : 0);
- //if (ThuRes)
- //{
- // Bitmap bmp = ImageHelper.ReadBitmapFile(ThumbnailPathName);
- // if (bmp != null)
- // {
- // imgW = bmp.Width + (bmp.Width % 2 > 0 ? 1 : 0);
- // imgH = bmp.Height + (bmp.Height % 2 > 0 ? 1 : 0);
- // }
- //}
-
- APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, imgW, imgH);
- VideoInfo.FileGuid = Guid.NewGuid().ToString();
- VideoInfo.IsUpload = false;
- VideoInfo.Uploaded = 0;
- VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
- APP.VideoList.Add(VideoInfo);
- //保存数据
- APP.SaveWkData();
- IsFirstR = true;
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- TxbRecordingWord.Text = "录制";
- txbType.Text = "";
- });
- }))).Start();
- //List<Model_Video> VideoList
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- }
- #endregion
-
- /// <summary>
- /// 登陆事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnLoginType_Click(object sender, RoutedEventArgs e)
- {
- Login();
- }
- /// <summary>
- /// 登陆
- /// </summary>
- private void Login()
- {
- if (APP.W_LoginWindow == null)
- {
- APP.W_LoginWindow = new LoginWindow
- {
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- Owner = this
- };
-
- }
- else
- {
- APP.W_LoginWindow.Initialize();
- }
- APP.W_LoginWindow.ShowDialog();
- if (APP.IsLoginType)
- {
- txbLoginType.Text = APP.UserInfo.Username;
-
- //ImgUpload.Visibility = Visibility.Visible;
- //ImgUploadTwo.Visibility = Visibility.Collapsed;
- }
- else
- {
- txbLoginType.Text = "未登录";
-
- //ImgUpload.Visibility = Visibility.Collapsed;
- //ImgUploadTwo.Visibility = Visibility.Visible;
- }
- }
- /// <summary>
- /// 状态更改为未登陆
- /// </summary>
- private void LoginType()
- {
- APP.IsLoginType = false;
- txbLoginType.Text = "未登录";
- APP.UserInfo = new Model_UserInfo();
- ImgUpload.Visibility = Visibility.Collapsed;
- ImgUploadTwo.Visibility = Visibility.Visible;
- }
- /// <summary>
- /// 获取时间戳
- /// </summary>
- /// <returns></returns>
- public string GetTimeStamp()
- {
- TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- return Convert.ToInt64(ts.TotalSeconds).ToString();
- }
- /// <summary>
- /// 返回一个时间戳到毫秒
- /// </summary>
- /// <returns></returns>
- public static long Timestamp()
- {
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- long timestr = Convert.ToInt64(ts.TotalMilliseconds);
- return timestr;
- }
-
- /// <summary>
- /// 增加事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- Record();
- if (APP.pageData.currpage > 0)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- }
- if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
- {
- blackboard_canvas.Visibility = Visibility.Visible;
- }
- APP.pageData.pagenum += 1;
- HideAngleBorder();
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- APP.pageData.currpage = APP.pageData.pagenum;
- myblackboard.changepage(APP.pageData.currpage - 1);
- ///清空页面图片UI
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- ///画板模型增加一页
- Model_DrawData model_DrawData = new Model_DrawData
- {
- PageNum = APP.pageData.currpage
- };
- APP.PageDrawList.Add(model_DrawData);
- ImgPrint.Visibility = Visibility.Visible;//可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- //APP.SaveDraw();
- if (btnImport.IsEnabled == true)
- {
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- }
- /// <summary>
- /// 打印事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPrint_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //3种情况 1.文档图片 2.截图图片 3.没有图片
- if(APP.PageDrawList.Count==0)
- {
- MessageWindow.Show("没有可打印的页,您可以新增、截图或导入来增加页!");
- return;
- }
-
-
- iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
- //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
- ////设置纸张横向
- //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
-
- string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
- FileToolsCommon.CreateDirectory(imgPath);
- imgPath += "101.pdf";
- iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
- document.Open();
- iTextSharp.text.Image image;
- for (int i = 0; i < APP.PageDrawList.Count; i++)
- {
- long ii = Timestamp();
- string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
- RectangleF rectangleFs = new RectangleF();
- MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
- {
-
- }
- else if (APP.PageDrawList[i].ImgDocumentation == true)
- {
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
- }
- else
- {
- RectangleF rectangleF = new RectangleF
- {
- Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
- Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
- X = (float)APP.PageDrawList[i].ImageLocation.X,
- Y = (float)APP.PageDrawList[i].ImageLocation.Y
- };
-
-
- string msg = string.Empty;
- bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
- if (isImg)
- {
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- }
- else
- {
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
- }
- }
-
-
-
-
- if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
- }
- else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
- }
- image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
- document.NewPage();
- document.Add(image);
- //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
- //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
- //p1.Leading = 150; //行间距
- //document.Add(p1);
- }
- Console.WriteLine("转换成功!");
- document.Close();
- }
- catch (Exception ex)
- {
- Console.WriteLine("转换失败,原因:" + ex.Message);
- }
- //document.Close();
- ////Console.ReadKey();
- if (APP.W_PrintWindow == null)
- {
- APP.W_PrintWindow = new PrintWindow
- {
- //APP.W_PrintWindow.Topmost = true;
- Owner = this
- };
- }
- if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
- {
- APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath);
- }
- else
- {
- APP.W_PrintWindow.Initialize("");
- }
- APP.W_PrintWindow.ShowDialog();
- //int pr = 1;
- //string msg = string.Empty;
- //string outPut = string.Empty;
- //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
- //if(pr==0)
- //{
- // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
- // APP.OutPut = outPut.Split(',');
- // string defa = string.Empty;
- // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
-
- // int printResult = 1;
- // string standardError = string.Empty;
- // string standardOutput = string.Empty;
- // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
-
- //}
- }
- /// 上一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void last_button_Click(object sender, RoutedEventArgs e)
- {
- if (APP.pageData.currpage > 1)
- {
- mouseDown = false;
- HideAngleBorder();
- //if(!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
- //{
- // ImgWG();
- //}
- APP.pageData.currpage -= 1;
- myblackboard.changepage(APP.pageData.currpage - 1);
- if (btnImport.IsEnabled == true)
- {
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- if (APP.pageData.currpage <= APP.PageDrawList.Count)
- {
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- {
- //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
-
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
- {
- mouseDown = false;
- ImgXY();
-
- }
- }
- }
- else
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- }
- }
- }
- }
- private void ImgXY()
- {
- imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
- imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
-
- imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
- //imgCanvas.Margin.Left= APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
- //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
- }
- private void ImgWG()
- {
- mouseDown = false;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = imgCanvas.Margin.Left,
- Y = imgCanvas.Margin.Top
- };
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
- }
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void next_btn_Click(object sender, RoutedEventArgs e)
- {
- if (APP.pageData.currpage < APP.pageData.pagenum)
- {
- mouseDown = false;
- HideAngleBorder();
- //if (!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
- //{
- // ImgWG();
- //}
- APP.pageData.currpage += 1;
- myblackboard.changepage(APP.pageData.currpage - 1);
- if (btnImport.IsEnabled == true)
- {
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- if (APP.pageData.currpage <= APP.PageDrawList.Count)
- {
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- {
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
- {
- //var group = IMG.FindResource("Imageview") as TransformGroup;
- //#region 高低 缩放比例
- //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
- //{
- // var transform1 = group.Children[0] as ScaleTransform;
- // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
- // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
- // imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
- // imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
- //}
- //#endregion
- //#region 坐标XY轴
- //var transform = group.Children[1] as TranslateTransform;
- //transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
- //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
- //#endregion
- mouseDown = false;
- ImgXY();
-
- }
- }
- }
- else
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- }
- }
- }
- }
- /// <summary>
- /// 生成图片
- /// </summary>
- /// <param name="_path">图片地址</param>
- /// <param name="_saveimg">保存位置</param>
- /// <param name="_rectangle">图片位置</param>
- /// <param name="errmsg">错误消息</param>
- /// <returns></returns>
- private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
- {
- errmsg = null;
- try
- {
- Bitmap bitmap = null;
-
- //创建要显示的图片对象,根据参数的个数设置宽度
- Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
- Graphics g = Graphics.FromImage(backgroudImg);
- //清除画布,背景设置为白色
- g.Clear(System.Drawing.Color.White);
-
- if (!string.IsNullOrWhiteSpace(_path))
- {
- bitmap = ImageHelper.ReadBitmapFile(_path);
- g.DrawImage(bitmap, _rectangle);
- }
-
-
- backgroudImg.Save(_saveimg);
-
- g.Dispose();
- backgroudImg.Dispose();
- if (bitmap != null)
- {
- bitmap.Dispose();
- }
-
- GC.Collect();
- return true;
- }
- catch (Exception ex)
- {
- errmsg = ex.Message;
- LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
- return false;
- }
-
- }
- /// <summary>
- /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
- /// "ImageFile", 1, 20, ImageFormat.Png, 256);
- /// </summary>
- /// <param name="pdfInputPath">Word文件路径</param>
- /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
- /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
- /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
- /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
- /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
- /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
- public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
- string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
- {
- // 返回的图片绝对路径集合
- List<string> images = new List<string>();
- try
- {
- // open word file
- Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
-
- // validate parameter
- if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
- if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
- if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
- if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
- if (startPageNum <= 0) { startPageNum = 1; }
- if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
- if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
- if (imageFormat == null) { imageFormat = ImageFormat.Png; }
- if (resolution <= 0) { resolution = 128; }
-
- ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
- {
- Resolution = resolution
- };
-
- // start to convert each page
- for (int i = startPageNum; i <= endPageNum; i++)
- {
- imageSaveOptions.PageIndex = i - 1;
- doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
- images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
- APP.num++;
- }
- imageSaveOptions = null;
- doc = null;
- }
- catch (Exception ex)
- {
- //if(ex.Message.ToString().Equals("{\"The document appears to be corrupted and cannot be loaded.\"}"))
- //{
- // MessageWindow.Show("Word文件无效或者Word文件被加密!");
- //}
- //else
- //{
- MessageWindow.Show("该文件无法使用!");
- //}
- LogHelper.WriteErrLog("【导入方法(ConvertWordToImage)】错误日志:" + ex.Message, ex);
- }
- return images;
- }
- private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
- {
- SaveFormat sf;// = SaveFormat.Unknown;
- if (imageFormat.Equals(ImageFormat.Png))
- {
- sf = SaveFormat.Png;
- }
- else if (imageFormat.Equals(ImageFormat.Jpeg))
- {
- sf = SaveFormat.Jpeg;
- }
- else if (imageFormat.Equals(ImageFormat.Tiff))
- {
- sf = SaveFormat.Tiff;
- }
- else if (imageFormat.Equals(ImageFormat.Bmp))
- {
- sf = SaveFormat.Bmp;
- }
- else
- {
- sf = SaveFormat.Unknown;
- }
-
- return sf;
- }
-
- #region 图像缩放,移动
- private bool mouseDown;
- private System.Windows.Point mouseXY;
- private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- img.CaptureMouse();
- mouseDown = true;
- mouseXY = e.GetPosition(img);
- Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
-
- }
- private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- img.ReleaseMouseCapture();
- mouseDown = false;
- }
- private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- if (mouseDown)
- {
- Domousemove(img, e);
- }
- }
- /// <summary>
- /// x y轴
- /// </summary>
- /// <param name="img"></param>
- /// <param name="e"></param>
- private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton != MouseButtonState.Pressed)
- {
- return;
- }
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
- {
- return;
- }
- TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
- TranslateTransform transform = group.Children[1] as TranslateTransform;
- System.Windows.Point position = e.GetPosition(img);
- transform.X -= mouseXY.X - position.X;
- transform.Y -= mouseXY.Y - position.Y;
- mouseXY = position;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = transform.X,
- Y = transform.Y
- };
- //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- }
- private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
- {
- ContentControl img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- System.Windows.Point point = e.GetPosition(img);
- Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
- System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
- Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
-
-
- TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
- double delta = e.Delta * 0.001;
- DowheelZoom(group, point, delta);
- }
- private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
- {
- System.Windows.Point pointToContent = group.Inverse.Transform(point);
- ScaleTransform transform = group.Children[0] as ScaleTransform;
- if (transform.ScaleX + delta < 0.1)
- {
- return;
- }
-
- transform.ScaleX += delta;
- transform.ScaleY += delta;
- TranslateTransform transform1 = group.Children[1] as TranslateTransform;
- transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
- transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
- LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
- + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
- );
-
- //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
-
- //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
- //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
- //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = transform1.X,
- Y = transform1.Y
- };
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- }
- #endregion
-
- #region 点阵笔相关
-
- #region 值初始化
- // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
-
- /// <summary>
- /// A4点阵纸点阵宽度
- /// </summary>
- private const int A4_WIDTH = 5600;
-
- /// <summary>
- /// A4点阵纸点阵高度
- /// </summary>
- private const int A4_HEIGHT = 7920;
-
- ///// <summary>
- ///// 画板
- ///// </summary>
- //private Graphics graphics;
-
- /// <summary>
- /// 笔画坐标数组
- /// </summary>
- private List<System.Drawing.Point> stroke;
-
- /// <summary>
- /// 笔序列号
- /// </summary>
- private string penSerial;
-
- /// <summary>
- /// 笔是否在点
- /// </summary>
- private bool isPenDown;
-
- //当前点阵地址
- private string currentPageSerial = string.Empty;
-
- //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
- //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
- private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
- #endregion
- public void InitPen()
- {
- stroke = new List<System.Drawing.Point>();
- //获取点阵笔实例,并绑定点阵笔事件
- //将授权文件内容传入,获取点阵笔对象实例
- APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
- //绑定笔连接事件
- APP.digitalPen.PenConnected += OnPenConnect;
- //绑定笔断开事件
- APP.digitalPen.PenDisconnect += OnPenDisconnect;
- //绑定笔书写输出坐标事件
- APP.digitalPen.PenCoordinate += OnPenCoordinate;
- //绑定抬笔事件
- APP.digitalPen.PenUp += OnPenUp;
- //绑定落笔事件
- APP.digitalPen.PenDown += OnPenDown;
- APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
- APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
- //完成初始化点阵笔,开始与点阵笔通信
- ERROR_CODE ER = APP.digitalPen.Start();
-
- ////绑定笔在新的点阵地址页面书写事件
- //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
- ////绑定笔信息事件
- //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
- //启动接收笔数据,完成初始化工作
- ERROR_CODE rc = APP.digitalPen.Start();
- //判断是否成功
- if (ER != ERROR_CODE.ERROR_OK)
- {
- MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
- }
- }
-
-
- /// <summary>
- /// 落笔
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenDown(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- //labPenSerial.Text = penSerial;
- //labPenStatus.Text = "PenDown";
- isPenDown = true;
-
- //Dispatcher.Invoke(new Action(() =>
- //{
- // for (int i = 0; i < APP.PageDrawList.Count; i++)
- // {
- // if (APP.PageDrawList[i].PageCode == penSerial)
- // {
- // if (i < APP.pageData.pagenum)
- // {
- // if (i < APP.pageData.currpage)
- // {
- // int num = APP.pageData.currpage - i;
- // APP.pageData.currpage -= num;
- // myblackboard.changepage(APP.pageData.currpage - 1);
- // if (APP.PageDrawList.Count > 0)
- // {
- // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- // {
- // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
-
- // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- // }
- // else
- // {
- // imgCanvas.Source = null;
- // }
- // }
- // }
- // else
- // {
- // int num = i - APP.pageData.currpage;
- // APP.pageData.currpage += num;
- // myblackboard.changepage(APP.pageData.currpage - 1);
- // if (APP.PageDrawList.Count > 0)
- // {
-
- // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- // {
- // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
- // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- // }
- // else
- // {
- // imgCanvas.Source = null;
- // }
- // }
- // }
- // }
- // return;
- // }
- // }
- // //myblackboard.changepages(0, 0, true);
- // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
- //}));
- }
- //myblackboard.changepages(0, 0, true);
- }
-
- /// <summary>
- /// 抬笔
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenUp(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- isPenDown = false;
- APP.PenSerial = penSerial;
- //int leftPoints = stroke.Count % 3;
- //if (0 != leftPoints)
- //{
- // int from = stroke.Count - leftPoints - 1;
- // if (from < 0)
- // from = 0;
- // int to = stroke.Count - 1;
- // DrawCoordinates(from, to);
- //}
- stroke.Clear();
- }
- if (APP.pageData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
- }));
- }
-
-
- }
-
- /// <summary>
- /// 笔断开
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenDisconnect(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- APP.PenSerial = penSerial;
- APP.PenStatus = false;
-
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "未连接";
- txbNotConnecteds.Text = "未连接";
- }));
- }
- }
-
- /// <summary>
- /// 笔连接
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenConnect(ulong time, string penSerial, int penType)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- APP.PenSerial = penSerial;
- APP.PenStatus = true;
- this.penSerial = penSerial;
- //连接后,在获取笔数据前,可以清除笔内的历史数据
- //APP.digitalPen.ClearMemory(penSerial);
-
- //开始接收笔数据
- APP.digitalPen.GetPenData(penSerial);
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "已连接";
- txbNotConnecteds.Text = "已连接";
- }));
-
- }
- }
- /// <summary>
- /// 电池电量
- /// </summary>
- /// <param name="time"></param>
- /// <param name="penSerial"></param>
- /// <param name="penType"></param>
- /// <param name="capacity"></param>
- private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
- }
- else
- {
- //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
- }
- }
-
- /// <summary>
- /// 已用存储
- /// </summary>
- /// <param name="time"></param>
- /// <param name="penSerial"></param>
- /// <param name="penType"></param>
- /// <param name="fillLevel"></param>
- private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
- Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
- }
- else
- {
- //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
- }
- }
-
- /// <summary>
- /// 笔书写,收到坐标
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- /// <param name="pageSerial">点阵地址</param>
- /// <param name="cx">x坐标</param>
- /// <param name="cy">y坐标</param>
- /// <param name="force">压力值</param>
- private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
- {
- if (CheckAccess())
- {
- Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
- Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
- }
- else
- {
- //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
- if (!isPenDown)
- {
- return;
- }
- stroke.Add(new System.Drawing.Point(cx, cy));
-
- double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
- double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
- //点
- double testX = cx * PropW;
- double testY = cy * PropH;
- //pageSerial //点阵IP地址 与打印的页面关联
- if (APP.pageData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- //myblackboard.changepages(testX, testY,false);
- myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (testY < scroMain.VerticalOffset)
- {
- //滚动条当前位置
- double RollCurrentLocation = scroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation - UpRoll;
- if (RollLocation < 0)
- {
- RollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- scroMain.ScrollToVerticalOffset(RollLocation);
- }
- //点在显示页面下方
- if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
- {
- //滚动条当前位置
- double RollCurrentLocation = scroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation + DownRoll;
- //滚动条最大滚动值
- double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
- if (RollLocation > ScrollbarMaxNum)
- {
- RollLocation = ScrollbarMaxNum;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollLocation-RollCurrentLocation;
- scroMain.ScrollToVerticalOffset(RollLocation);
- }
- #endregion
- //gridM.Height //A4高度
- //scroMain.VerticalOffset;//获取滚动条位置
- //scroMain.ActualHeight//A4纸显示高度
- //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
-
- //Mouse.GetPosition(this)
- if (testX > 0 && testY > 0)
- {
- //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
- System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }));
- }
-
-
-
- ////每3个点画一条曲线
- //if (stroke.Count % 3 == 0)
- //{
- // int from = stroke.Count - 3 - 1;
- // if (from < 0)
- // from = 0;
- // int to = stroke.Count - 1;
- // DrawCoordinates(from, to);
- //}
- }
- }
-
- /// <summary>
- /// 停止笔
- /// </summary>
- public void StopDigitalPen()
- {
- //停止,释放资源
- APP.digitalPen.Stop();
- }
- /// <summary>
- /// 清空笔内存储
- /// </summary>
- public void ClearPenStorage()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.ClearMemory(penSerial);
- }
- }
- /// <summary>
- /// 获取剩余电量
- /// </summary>
- public void GetPenElectricityQuantity()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.GetBatteryCapacity(penSerial);
- }
- }
-
- /// <summary>
- /// 获取存储空间
- /// </summary>
- public void GetUsedStorage()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.GetMemoryFillLevel(penSerial);
- }
- }
-
- /// <summary>
- /// 开启悬浮
- /// </summary>
- public void 开启悬浮()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.SetPenHoverMode(true, penSerial);
- }
- }
-
- /// <summary>
- /// 关闭悬浮
- /// </summary>
- public void 关闭悬浮()
- {
- if (!string.IsNullOrEmpty(penSerial))
- {
- APP.digitalPen.SetPenHoverMode(false, penSerial);
- }
- }
- #endregion
- /// <summary>
- /// 最小化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnShrink_Click(object sender, RoutedEventArgs e)
- {
- if (WindowState == WindowState.Minimized)
- {
- WindowState = WindowState.Normal;
- }
- else
- {
- WindowState = WindowState.Minimized;
- }
- }
- /// <summary>
- /// 位置确定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnOk_Click(object sender, RoutedEventArgs e)
- {
- //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- //btnOk.Visibility = Visibility.Collapsed;
- //blackboard_canvas.Visibility = Visibility.Visible;
- }
- /// <summary>
- /// 引用user32.dll动态链接库(windows api),
- /// 使用库中定义 API:SetCursorPos
- /// 设置光标位置
- /// </summary>
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern int SetCursorPos(int x, int y);
-
- #region 图片拉伸移动
- private System.Windows.Point initialPoint;
-
- /// <summary>
- /// 隐藏图片四个点和线
- /// </summary>
- private void HideAngleBorder()
- {
- RectLeftUp.Visibility = Visibility.Hidden;
- RectRightUp.Visibility = Visibility.Hidden;
- RectLeftDown.Visibility = Visibility.Hidden;
- RectRightDown.Visibility = Visibility.Hidden;
- RectImgBorder.Visibility = Visibility.Hidden;
- }
-
- private void ShowAngleBorder()
- {
- PointLocation();
- RectLeftUp.Visibility = Visibility.Visible;
- RectRightUp.Visibility = Visibility.Visible;
- RectLeftDown.Visibility = Visibility.Visible;
- RectRightDown.Visibility = Visibility.Visible;
- RectImgBorder.Visibility = Visibility.Visible;
- }
-
- /// <summary>
- /// 确定四个点和边框的位置大小
- /// </summary>
- private void PointLocation()
- {
- RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
- RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
- RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
-
- Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
- Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
-
- Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
- Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
-
- Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
- Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
-
- Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
- Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
-
- }
- private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
- {
- System.Windows.Point point = e.GetPosition(imgCanvas);
- initialPoint = point;
- //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
- //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
- //{
- // Console.WriteLine("在范围内");
- //}
- HideAngleBorder();
- }
- private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
- {
- System.Windows.Point point = e.GetPosition(imgCanvas);
- imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = imgCanvas.Margin.Left,
- Y = imgCanvas.Margin.Top
- };
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
-
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- }
- }
-
- private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
- {
- if (mouseDown)
- {
- ShowAngleBorder();
- }
- }
-
- private System.Drawing.PointF imgRightDown;
- /// <summary>
- /// 设置控件最上层
- /// </summary>
- /// <param name="element"></param>
- public void BringToFront(Thumb element)//图片置于最顶层显示
- {
- if (element == null)
- {
- return;
- }
-
- Canvas parent = element.Parent as Canvas;
- if (parent == null)
- {
- return;
- }
-
- int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
- .Where(x => x != element)
- .Select(x => Canvas.GetZIndex(x))
- .Max();
- Canvas.SetZIndex(element, maxZ + 1);
- }
- private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
- {
- try
- {
-
- Thumb thu = (Thumb)sender;
- BringToFront(thu);
-
- imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
- HideAngleBorder();
- switch (thu.Name)
- {
- case "RectLeftUp":
- RectLeftUp.Visibility = Visibility.Visible;
- break;
- case "RectRightUp":
- RectRightUp.Visibility = Visibility.Visible;
- break;
- case "RectLeftDown":
- RectLeftDown.Visibility = Visibility.Visible;
- break;
- case "RectRightDown":
- RectRightDown.Visibility = Visibility.Visible;
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
- {
- try
- {
- if (mouseDown)
- {
- Thumb thu = (Thumb)sender;
- #region 判断是否超出 暂无
- double plul = Canvas.GetLeft(RectLeftUp);
- double plut = Canvas.GetTop(RectLeftUp);
- double prdl = Canvas.GetLeft(RectRightDown);
- double prdt = Canvas.GetTop(RectRightDown);
- #endregion
-
- //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- double imgW = 0;
- double imgH = 0;
- double imgX = 0;
- double imgY = 0;
- switch (thu.Name)
- {
- case "RectLeftUp":
- #region 左上
- imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
- imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
- imgX = 0;
- imgY = 0;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- imgX = Mouse.GetPosition(gridM).X;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- imgY = Mouse.GetPosition(gridM).Y;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
- #endregion
- //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
- //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
- //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
- break;
- case "RectRightUp":
- #region 右上
- imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
- imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
- imgX = 0;
- imgY = 0;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- imgY = Mouse.GetPosition(gridM).Y;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
- //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
- //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
- //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
- #endregion
- break;
- case "RectLeftDown":
- #region 左下
- imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
- imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
- imgX = 0;
- imgY = 0;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- imgX = imgCanvas.Margin.Left;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- imgX = Mouse.GetPosition(gridM).X;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- imgY = imgCanvas.Margin.Top;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
- //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
- //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
- //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
- #endregion
- break;
- case "RectRightDown":
- #region 右下
- imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
- imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
- if (imgW < 50)
- {
- imgCanvas.Width = 50;
- Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Width = imgW;
- Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
- }
- if (imgH < 50)
- {
- imgCanvas.Height = 50;
- Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
- }
- else
- {
- imgCanvas.Height = imgH;
- Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
- }
- //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
- //imgCanvas.Width += e.HorizontalChange;
- //imgCanvas.Height += e.VerticalChange;
- #endregion
- break;
- default:
- break;
- }
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = imgCanvas.Margin.Left,
- Y = imgCanvas.Margin.Top
- };
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = imgCanvas.ActualWidth,
- CenterY = imgCanvas.ActualHeight
- };
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
-
- }
- //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
- //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
- //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
- //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
- }
- catch (Exception)
- {
- MessageWindow.Show("图片过小!");
- }
- }
-
- private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
- {
- ShowAngleBorder();
- }
- #endregion
-
- #region 方法
- /// <summary>
- /// 录屏 录制 截图 导入文档 增加 主页面显示
- /// </summary>
- private void Record()
- {
- GridMain.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- //gridUpload.Visibility = Visibility.Collapsed;
- GridMyVideo.Visibility = Visibility.Collapsed;
- if (APP.pageData.pagenum > 0)
- {
- gridPage.Visibility = Visibility.Visible;
- }
- DataContext = APP.pageData;
- }
- /// <summary>
- /// 设置页面显示
- /// </summary>
- private void SetUp()
- {
-
- }
- #endregion
-
- private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- mouseDown = true;
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- System.Drawing.Size a = PrimaryScreen.DESKTOP;
- System.Drawing.Size b = PrimaryScreen.WorkingArea;
- int c = PrimaryScreen.DpiX;
- int d = PrimaryScreen.DpiY;
- float x = PrimaryScreen.ScaleX;
- float y = PrimaryScreen.ScaleY;
- }
- /// <summary>
- /// 点击标题栏 隐藏截图的四个点和线
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- HideAngleBorder();
- }
- /// <summary>
- /// 鼠标左键点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- }
- }
- }
- }
|