星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

XHMicroLessonSystemWindow.xaml.cs 169KB

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