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

XHMicroLessonSystemWindow.xaml.cs 163KB

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