星火微课系统客户端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

XHMicroLessonSystemWindow.xaml.cs 163KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883
  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. VideoSizes= videoinfo.VideoSizebyte
  1159. }); ;
  1160. }
  1161. i++;
  1162. }
  1163. Currpage = 0;
  1164. PageNum = 0;
  1165. if (pageData.menuList.Count > 0)
  1166. {
  1167. Currpage = 1;
  1168. txbCurrpageTwo.Text = Currpage.ToString();
  1169. stpUp.Visibility = Visibility.Visible;
  1170. }
  1171. else
  1172. {
  1173. stpUp.Visibility = Visibility.Hidden;
  1174. }
  1175. PageNum = model_VideoList.Count;
  1176. if (PageNum > 0)
  1177. {
  1178. int t = 1;
  1179. while (PageNum > 16 * t)
  1180. {
  1181. t++;
  1182. }
  1183. PageNum = t;
  1184. }
  1185. else
  1186. {
  1187. PageNum = 0;
  1188. }
  1189. txbPageNumTwo.Text = PageNum.ToString();
  1190. APP.myloading.Hide();
  1191. DataContext = pageData;
  1192. }
  1193. /// <summary>
  1194. /// 当前页
  1195. /// </summary>
  1196. private int Currpage = 0;
  1197. /// <summary>
  1198. /// 总页码
  1199. /// </summary>
  1200. private int PageNum = 0;
  1201. /// <summary>
  1202. /// 加载视频列表
  1203. /// </summary>
  1204. public void LoadingVideoList()
  1205. {
  1206. try
  1207. {
  1208. model_VideoList = new List<Model_Video>();
  1209. foreach (Model_WKData Vdata in APP.WKDataList)
  1210. {
  1211. #region 计时器初始化
  1212. if (Vdata.VideoList == null)
  1213. {
  1214. continue;
  1215. }
  1216. foreach (Model_Video videoinfo in Vdata.VideoList)
  1217. {
  1218. try
  1219. {
  1220. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  1221. {
  1222. continue;
  1223. }
  1224. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  1225. {
  1226. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  1227. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  1228. }
  1229. model_VideoList.Add(videoinfo);
  1230. }
  1231. catch (Exception ex)
  1232. {
  1233. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1234. }
  1235. }
  1236. #endregion
  1237. }
  1238. }
  1239. catch (Exception ex)
  1240. {
  1241. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1242. }
  1243. }
  1244. /// <summary>
  1245. /// 上传
  1246. /// </summary>
  1247. /// <param name="sender"></param>
  1248. /// <param name="e"></param>
  1249. private void BtnUploads_Click(object sender, RoutedEventArgs e)
  1250. {
  1251. pageData.menuList[Subscript].IsEnabled = false;
  1252. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnUpload");
  1253. for (int i = 0; i < buttons.Count; i++)
  1254. {
  1255. if (buttons[i] == sender)
  1256. {
  1257. DAL_Upload dAL_Upload = new DAL_Upload();
  1258. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  1259. {
  1260. pageData.menuList[i].Visi = "Collapsed";
  1261. pageData.menuList[i].Coll = "Visible";
  1262. DataContext = pageData;
  1263. //MessageWindow.Show("视频上传服务器成功!");
  1264. if (APP.W_UploadWindow == null)
  1265. {
  1266. APP.W_UploadWindow = new UploadWindow
  1267. {
  1268. Owner = this
  1269. };
  1270. }
  1271. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  1272. APP.W_UploadWindow.Initialize(pageData.menuList[i].VideoName, pageData.menuList[i].VideoSizes, pageData.menuList[i].VideoType, pageData.menuList[i].FileGuid);
  1273. APP.W_UploadWindow.ShowDialog();
  1274. }
  1275. else
  1276. {
  1277. MessageWindow.Show(ErrMessage);
  1278. }
  1279. }
  1280. }
  1281. }
  1282. /// <summary>
  1283. /// 删除
  1284. /// </summary>
  1285. /// <param name="sender"></param>
  1286. /// <param name="e"></param>
  1287. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  1288. {
  1289. pageData.menuList[Subscript].IsEnabled = false;
  1290. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnDelete");
  1291. for (int i = 0; i < buttons.Count; i++)
  1292. {
  1293. if (buttons[i] == sender)
  1294. {
  1295. //if (APP.W_PromptWindow == null)
  1296. //{
  1297. // APP.W_PromptWindow = new PromptWindow();
  1298. // APP.W_PromptWindow.Owner = this;
  1299. //}
  1300. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  1301. //APP.W_PromptWindow.ShowDialog();
  1302. foreach (Model_WKData wKData in APP.WKDataList)
  1303. {
  1304. if (wKData.VideoList == null)
  1305. {
  1306. continue;
  1307. }
  1308. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  1309. {
  1310. try
  1311. {
  1312. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  1313. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  1314. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  1315. InitializeUpload();
  1316. return;
  1317. }
  1318. catch (Exception ex)
  1319. {
  1320. System.Windows.MessageBox.Show("无法删除视频!" + ex.Message);
  1321. return;
  1322. }
  1323. }
  1324. }
  1325. }
  1326. }
  1327. }
  1328. /// <summary>
  1329. /// 播放
  1330. /// </summary>
  1331. /// <param name="sender"></param>
  1332. /// <param name="e"></param>
  1333. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  1334. {
  1335. pageData.menuList[Subscript].IsEnabled = false;
  1336. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnPlay");
  1337. for (int i = 0; i < buttons.Count; i++)
  1338. {
  1339. if (buttons[i] == sender)
  1340. {
  1341. try
  1342. {
  1343. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  1344. Process pro = new Process
  1345. {
  1346. StartInfo = psi
  1347. };
  1348. pro.Start();
  1349. }
  1350. catch (Exception ex)
  1351. {
  1352. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  1353. System.Windows.MessageBox.Show(ex.Message);
  1354. return;
  1355. }
  1356. }
  1357. }
  1358. }
  1359. /// <summary>
  1360. /// 搜索集合匹配的索引
  1361. /// </summary>
  1362. /// <typeparam name="T"></typeparam>
  1363. /// <param name="parent"></param>
  1364. /// <param name="childName"></param>
  1365. /// <returns></returns>
  1366. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  1367. where T : DependencyObject
  1368. {
  1369. List<T> list = new List<T>();
  1370. if (parent == null)
  1371. {
  1372. return list;
  1373. }
  1374. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  1375. for (int i = 0; i < childrenCount; i++)
  1376. {
  1377. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  1378. // 如果子控件不是需查找的控件类型
  1379. T childType = child as T;
  1380. if (childType == null)
  1381. {
  1382. // 在下一级控件中递归查找
  1383. List<T> findChildList = FindChilds<T>(child, childName);
  1384. for (int j = 0; j < findChildList.Count; j++)
  1385. {
  1386. }
  1387. list.AddRange(FindChilds<T>(child, childName));
  1388. }
  1389. else if (!string.IsNullOrEmpty(childName))
  1390. {
  1391. FrameworkElement frameworkElement = child as FrameworkElement;
  1392. // 如果控件名称符合参数条件
  1393. if (frameworkElement != null && frameworkElement.Name == childName)
  1394. {
  1395. list.Add((T)child);
  1396. }
  1397. }
  1398. else
  1399. {
  1400. // 查找到了控件
  1401. list.Add((T)child);
  1402. }
  1403. }
  1404. return list;
  1405. }
  1406. /// <summary>
  1407. /// 修改
  1408. /// </summary>
  1409. /// <param name="sender"></param>
  1410. /// <param name="e"></param>
  1411. private void BtnModify_Click(object sender, RoutedEventArgs e)
  1412. {
  1413. if (IsModify)
  1414. {
  1415. pageData.menuList[Subscript].IsEnabled = false;
  1416. }
  1417. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnModify");
  1418. for (int i = 0; i < buttons.Count; i++)
  1419. {
  1420. if (buttons[i] == sender)
  1421. {
  1422. pageData.menuList[i].IsEnabled = true;
  1423. Subscript = i;
  1424. IsModify = true;
  1425. }
  1426. }
  1427. }
  1428. private int MouseNumber = 0;
  1429. /// <summary>
  1430. /// 上传 上页
  1431. /// </summary>
  1432. /// <param name="sender"></param>
  1433. /// <param name="e"></param>
  1434. private void BtnLastPage_Click(object sender, RoutedEventArgs e)
  1435. {
  1436. if (Currpage > 1)
  1437. {
  1438. Currpage -= 1;
  1439. txbCurrpageTwo.Text = Currpage.ToString();
  1440. int i = 1;
  1441. bool isColour = true;
  1442. pageData.menuList.Clear();
  1443. //显示视频
  1444. foreach (Model_Video videoinfo in model_VideoList)
  1445. {
  1446. //是否已上传
  1447. //videoinfo.IsUpload;
  1448. //录制时间
  1449. //videoinfo.RSTime;
  1450. //文件大小
  1451. //videoinfo.VideoSize;
  1452. //文件缩略图路径
  1453. //videoinfo.ThumbnailPath;
  1454. //文件唯一标示 上传事件筛选需要上传的视频
  1455. //videoinfo.FileGuid;
  1456. //文件存储路径
  1457. //videoinfo.VidePath;
  1458. string colour = "#FFFFFF";
  1459. if (isColour == true)
  1460. {
  1461. colour = "#FFFFFF";
  1462. isColour = false;
  1463. }
  1464. else
  1465. {
  1466. colour = "#E6F1FF";
  1467. isColour = true;
  1468. }
  1469. string vis = "Visible";
  1470. string cos = "Collapsed";
  1471. if (!videoinfo.IsUpload)
  1472. {
  1473. vis = "Collapsed";
  1474. cos = "Visible";
  1475. }
  1476. if (i <= Currpage * 16 && i >= (Currpage - 1) * 16)
  1477. {
  1478. pageData.menuList.Add(new FileDirectoryModel()
  1479. {
  1480. SerialNumber = i,
  1481. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1482. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1483. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  1484. VideoDuration = 0,
  1485. VideoSize = videoinfo.VideoSize,
  1486. VideoTime = videoinfo.RSTime,
  1487. IsEnabled = false,
  1488. Path = videoinfo.VideoPath,
  1489. Colour = colour,
  1490. Visi = vis,
  1491. Coll = cos,
  1492. FileGuid = videoinfo.FileGuid,
  1493. VideoType = videoinfo.VideoType.ToString()
  1494. }); ;
  1495. }
  1496. i++;
  1497. }
  1498. APP.myloading.Hide();
  1499. }
  1500. }
  1501. /// <summary>
  1502. /// 上传 下页
  1503. /// </summary>
  1504. /// <param name="sender"></param>
  1505. /// <param name="e"></param>
  1506. private void BtnNextPage_Click(object sender, RoutedEventArgs e)
  1507. {
  1508. if (Currpage < PageNum)
  1509. {
  1510. Currpage += 1;
  1511. txbCurrpageTwo.Text = Currpage.ToString();
  1512. int i = 1;
  1513. bool isColour = true;
  1514. pageData.menuList.Clear();
  1515. //显示视频
  1516. foreach (Model_Video videoinfo in model_VideoList)
  1517. {
  1518. //是否已上传
  1519. //videoinfo.IsUpload;
  1520. //录制时间
  1521. //videoinfo.RSTime;
  1522. //文件大小
  1523. //videoinfo.VideoSize;
  1524. //文件缩略图路径
  1525. //videoinfo.ThumbnailPath;
  1526. //文件唯一标示 上传事件筛选需要上传的视频
  1527. //videoinfo.FileGuid;
  1528. //文件存储路径
  1529. //videoinfo.VidePath;
  1530. string colour = "#FFFFFF";
  1531. if (isColour == true)
  1532. {
  1533. colour = "#FFFFFF";
  1534. isColour = false;
  1535. }
  1536. else
  1537. {
  1538. colour = "#E6F1FF";
  1539. isColour = true;
  1540. }
  1541. string vis = "Visible";
  1542. string cos = "Collapsed";
  1543. if (!videoinfo.IsUpload)
  1544. {
  1545. vis = "Collapsed";
  1546. cos = "Visible";
  1547. }
  1548. if (i <= Currpage * 16 && i > (Currpage - 1) * 16)
  1549. {
  1550. pageData.menuList.Add(new FileDirectoryModel()
  1551. {
  1552. SerialNumber = i,
  1553. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1554. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1555. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  1556. VideoDuration = 0,
  1557. VideoSize = videoinfo.VideoSize,
  1558. VideoTime = videoinfo.RSTime,
  1559. IsEnabled = false,
  1560. Path = videoinfo.VideoPath,
  1561. Colour = colour,
  1562. Visi = vis,
  1563. Coll = cos,
  1564. FileGuid = videoinfo.FileGuid,
  1565. VideoType = videoinfo.VideoType.ToString()
  1566. }); ;
  1567. }
  1568. i++;
  1569. }
  1570. APP.myloading.Hide();
  1571. }
  1572. }
  1573. /// <summary>
  1574. /// 修改文件名
  1575. /// </summary>
  1576. /// <param name="Guid">唯一编号</param>
  1577. /// <param name="NewName">新文件名带后缀 不带路径</param>
  1578. /// <param name="Errmessage">错误信息</param>
  1579. /// <returns></returns>
  1580. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  1581. {
  1582. Errmessage = "";
  1583. Model_Video model_Video = APP.VideoList.Find(x => x.FileGuid == FileGuid);
  1584. string filePathName = model_Video.VideoPath;
  1585. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  1586. string newFilePathName = filePath + NewName;
  1587. //缩略图
  1588. string ThumbnailPath = filePath + "ThumbnailPath/";
  1589. FileToolsCommon.CreateDirectory(ThumbnailPath);
  1590. //缩略图存储位置
  1591. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  1592. if (FileToolsCommon.IsExistFile(newFilePathName))
  1593. {
  1594. Errmessage = "文件已存在,请重新修改文件名!";
  1595. return false;
  1596. }
  1597. else
  1598. {
  1599. //修改文件名
  1600. FileToolsCommon.Copy(filePathName, newFilePathName);
  1601. model_Video.VideoPath = newFilePathName;
  1602. //修改缩略图名
  1603. FileToolsCommon.DeleteFile(ThumbnailPathName);
  1604. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  1605. model_Video.ThumbnailPath = ThumbnailPathName;
  1606. APP.SaveWkData();
  1607. return true;
  1608. }
  1609. }
  1610. #endregion
  1611. #region 录制窗口
  1612. #region 变量
  1613. /// <summary>
  1614. /// 视频保存路径
  1615. /// </summary>
  1616. //string RecordingPath;
  1617. /// <summary>
  1618. /// 图片保存路径
  1619. /// </summary>
  1620. private string ImgPath;
  1621. /// <summary>
  1622. /// 音频保存路径名
  1623. /// </summary>
  1624. private string AudioPathName;
  1625. /// <summary>
  1626. /// 视频保存路径名
  1627. /// </summary>
  1628. private string VideoSavePathName;
  1629. /// <summary>
  1630. /// 视频合成路径名
  1631. /// </summary>
  1632. private string VideoSynthesisPathName;
  1633. /// <summary>
  1634. /// 暂停录制
  1635. /// </summary>
  1636. private bool IsSuspendR = true;
  1637. /// <summary>
  1638. /// 录制是否已停止
  1639. /// </summary>
  1640. private bool IsFirstR = true;
  1641. /// <summary>
  1642. /// 图片
  1643. /// </summary>
  1644. private List<string> RsImgName = null;
  1645. /// <summary>
  1646. /// 是否开始截图计数
  1647. /// </summary>
  1648. private bool IsStartCount = false;
  1649. /// <summary>
  1650. /// 是否录制了音频
  1651. /// </summary>
  1652. private bool IsRecordAudio = false;
  1653. #endregion
  1654. #region 录屏
  1655. /// <summary>
  1656. /// 录屏事件
  1657. /// </summary>
  1658. /// <param name="sender"></param>
  1659. /// <param name="e"></param>
  1660. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  1661. {
  1662. Record();
  1663. if (!APP.CheckScreenCapturerRecorder())
  1664. {
  1665. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  1666. APP.InstallScreenCapturerRecorder();
  1667. return;
  1668. }
  1669. #region 限制只允许录制一个录屏 废弃
  1670. //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  1671. //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  1672. //{
  1673. // MessageBoxResult dr = MessageWindow.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1674. // if (dr == MessageBoxResult.OK)
  1675. // {
  1676. // try
  1677. // {
  1678. // FileToolsCommon.DeleteFile(RecordScreenPathName);
  1679. // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  1680. // }
  1681. // catch (Exception ex)
  1682. // {
  1683. // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  1684. // }
  1685. // }
  1686. // else
  1687. // {
  1688. // return;
  1689. // }
  1690. //}
  1691. #endregion
  1692. if (APP.W_ScreenRecordingToolbarWindow == null)
  1693. {
  1694. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  1695. {
  1696. Topmost = true
  1697. };
  1698. APP.W_ScreenRecordingToolbarWindow.Initialize();
  1699. }
  1700. else
  1701. {
  1702. APP.W_ScreenRecordingToolbarWindow.Initialize();
  1703. }
  1704. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  1705. //显示在右下角
  1706. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  1707. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  1708. float DIP = graphics.DpiX;
  1709. float DIPY = graphics.DpiY;
  1710. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  1711. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  1712. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  1713. APP.W_ScreenRecordingToolbarWindow.Show();
  1714. Hide();
  1715. }
  1716. /// <summary>
  1717. /// 保存录屏中
  1718. /// </summary>
  1719. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  1720. {
  1721. txbType.Visibility = Visibility.Visible;
  1722. txbType.Text = "保存中";
  1723. btnScreenRecording.IsEnabled = false;
  1724. new Thread(new ThreadStart(new Action(() =>
  1725. {
  1726. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  1727. {
  1728. Thread.Sleep(100);
  1729. }
  1730. Dispatcher.Invoke(() =>
  1731. {
  1732. btnScreenRecording.IsEnabled = true;
  1733. txbType.Visibility = Visibility.Hidden;
  1734. //TxbRecordScreenWord.Text = "录屏";
  1735. });
  1736. }))).Start();
  1737. }
  1738. #endregion
  1739. /// <summary>
  1740. /// 录制窗口内容
  1741. /// </summary>
  1742. /// <param name="sender"></param>
  1743. /// <param name="e"></param>
  1744. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  1745. {
  1746. Record();
  1747. if (!APP.CheckScreenCapturerRecorder())
  1748. {
  1749. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  1750. APP.InstallScreenCapturerRecorder();
  1751. return;
  1752. }
  1753. if (APP.pageData.currpage > 0)
  1754. {
  1755. blackboard_canvas.Visibility = Visibility.Visible;
  1756. }
  1757. else
  1758. {
  1759. MessageWindow.Show("请先导入文档或截图!");
  1760. return;
  1761. }
  1762. if (RectImgBorder.Visibility != Visibility.Hidden)
  1763. {
  1764. HideAngleBorder();
  1765. }
  1766. //btnStop.IsEnabled = true;//停止录制按钮可点击
  1767. StartRecord();
  1768. }
  1769. /// <summary>
  1770. /// 停止录制窗口内容
  1771. /// </summary>
  1772. /// <param name="sender"></param>
  1773. /// <param name="e"></param>
  1774. private void BtnStop_Click(object sender, RoutedEventArgs e)
  1775. {
  1776. blackboard_canvas.Visibility = Visibility.Collapsed;
  1777. EndRecord();
  1778. }
  1779. private System.Timers.Timer timer;
  1780. /// <summary>
  1781. /// 设置录屏文件地址
  1782. /// </summary>
  1783. private void SetUpVideoPathName()
  1784. {
  1785. }
  1786. /// <summary>
  1787. /// 开始录制和暂停录制
  1788. /// </summary>
  1789. private void StartRecord()
  1790. {
  1791. if (IsSuspendR)
  1792. {
  1793. if (IsFirstR)//是否第一次录制 初始化录制
  1794. {
  1795. #region 检测麦克风扬声器是否可用
  1796. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  1797. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  1798. try
  1799. {
  1800. FileToolsCommon.DeleteFile(audioSpeakerPath);
  1801. FileToolsCommon.DeleteFile(audioMicrophonePath);
  1802. }
  1803. catch (Exception)
  1804. {
  1805. }
  1806. //扬声器
  1807. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  1808. {
  1809. APP.FFmpeg.StopRecordAudio();
  1810. //Thread.Sleep(500);
  1811. //麦克风
  1812. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  1813. {
  1814. }
  1815. else
  1816. {
  1817. //无法录制麦克风
  1818. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  1819. if (Res == MessageBoxResult.Cancel)
  1820. {
  1821. return;
  1822. }
  1823. }
  1824. APP.FFmpeg.StopRecordAudio();
  1825. }
  1826. else
  1827. {
  1828. //无法录制扬声器音频
  1829. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  1830. if (Res == MessageBoxResult.Cancel)
  1831. {
  1832. return;
  1833. }
  1834. }
  1835. #endregion
  1836. #region 计时器初始化
  1837. if (t == null)
  1838. {
  1839. t = new DispatcherTimer();
  1840. t.Tick += OnTimer;
  1841. t.Interval = new TimeSpan(0, 0, 0, 1);
  1842. t.IsEnabled = true;
  1843. t.Start();
  1844. }
  1845. t.Interval = new TimeSpan(0, 0, 0, 1);
  1846. txbTime.Visibility = Visibility.Visible;
  1847. #endregion
  1848. VideoInfo = new Model_Video
  1849. {
  1850. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  1851. WkType = Enum_WKVidetype.RecordingLessons
  1852. };
  1853. ImgPath = APP.WKData.WkPath + "temp/Image/";
  1854. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  1855. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  1856. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  1857. FileToolsCommon.CreateDirectory(ImgPath);
  1858. FileToolsCommon.CreateDirectory(AudioPathName);
  1859. AudioPathName += APP.WKData.WkName + ".MP3";
  1860. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  1861. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
  1862. int num = 1;
  1863. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  1864. {
  1865. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  1866. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
  1867. num++;
  1868. }
  1869. #region 设置录屏唯一 废弃
  1870. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  1871. //{
  1872. // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  1873. // if (dr == MessageBoxResult.OK)
  1874. // {
  1875. // try
  1876. // {
  1877. // FileToolsCommon.DeleteFile(VideoSavePathName);
  1878. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  1879. // }
  1880. // catch (Exception ex)
  1881. // {
  1882. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  1883. // }
  1884. // }
  1885. // else
  1886. // {
  1887. // return;
  1888. // }
  1889. //}
  1890. #endregion
  1891. #region 禁用按钮
  1892. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  1893. ImgPrintTwo.Visibility = Visibility.Visible;
  1894. btnPrint.IsEnabled = false;
  1895. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  1896. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1897. btnScreenshot.IsEnabled = false;
  1898. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  1899. ImgImportTwo.Visibility = Visibility.Visible;
  1900. btnImport.IsEnabled = false;
  1901. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  1902. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  1903. btnScreenRecording.IsEnabled = false;
  1904. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  1905. ImgUploadTwo.Visibility = Visibility.Visible;
  1906. btnUpload.IsEnabled = false;
  1907. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  1908. ImgSetUpTwo.Visibility = Visibility.Visible;
  1909. btnSetUp.IsEnabled = false;
  1910. btnLoginType.IsEnabled = false;
  1911. blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
  1912. //myblackboard = new BlackboardNew(blackboard_canvas);
  1913. //DataContext = APP.pageData;
  1914. //drawingAttributes = new DrawingAttributes();
  1915. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  1916. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  1917. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  1918. //blackboard_canvas.UseCustomCursor = true;
  1919. //drawingAttributes.FitToCurve = true;
  1920. //drawingAttributes.IgnorePressure = false;
  1921. //drawingAttributes.Width = PenSize;
  1922. //drawingAttributes.Height = PenSize;
  1923. //drawingAttributes.Color = Color;
  1924. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  1925. #endregion
  1926. #region 录像倒计时
  1927. if (APP.W_CountdownWindow == null)
  1928. {
  1929. APP.W_CountdownWindow = new CountdownWindow();
  1930. APP.W_CountdownWindow.Initialize();
  1931. //APP.W_CountdownWindow.Topmost = true;
  1932. }
  1933. else
  1934. {
  1935. APP.W_CountdownWindow.Initialize();
  1936. //APP.W_CountdownWindow.Topmost = true;
  1937. }
  1938. APP.W_CountdownWindow.Show();
  1939. #endregion
  1940. IsFirstR = false;
  1941. RsImgName = new List<string>();
  1942. timer = new System.Timers.Timer(200)
  1943. {
  1944. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  1945. };//设置执行一次(false)还是一直执行(true)
  1946. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  1947. timer.Enabled = true; //启动计时器
  1948. }
  1949. //继续录制
  1950. IsSuspendR = false;
  1951. //BtnRecording.Content = "暂停录制";
  1952. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  1953. ImgStop.Visibility = Visibility.Collapsed;
  1954. ImgStopTwo.Visibility = Visibility.Visible;
  1955. TxbRecordingWord.Text = "暂停";
  1956. #region 2秒内不可点击
  1957. new Thread(new ThreadStart(new Action(() =>
  1958. {
  1959. Dispatcher.Invoke(() =>
  1960. {
  1961. BtnRecord.IsEnabled = false;
  1962. btnStop.IsEnabled = false;
  1963. });
  1964. Thread.Sleep(2000);
  1965. Dispatcher.Invoke(() =>
  1966. {
  1967. BtnRecord.IsEnabled = true;
  1968. btnStop.IsEnabled = true;
  1969. });
  1970. }))).Start();
  1971. #endregion
  1972. try
  1973. {
  1974. new Thread(new ThreadStart(new Action(() =>
  1975. {
  1976. Thread.Sleep(1000);
  1977. IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName);
  1978. Thread.Sleep(1000);
  1979. Dispatcher.Invoke(() =>
  1980. {
  1981. IsStartCount = true;
  1982. Stack();
  1983. //timer.Start();
  1984. });
  1985. }))).Start();
  1986. }
  1987. catch (Exception ex)
  1988. {
  1989. MessageWindow.Show(ex.Message);
  1990. }
  1991. }
  1992. else
  1993. {
  1994. //暂停
  1995. IsSuspendR = true;
  1996. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  1997. ImgStop.Visibility = Visibility.Visible;
  1998. ImgStopTwo.Visibility = Visibility.Collapsed;
  1999. TxbRecordingWord.Text = "继续";
  2000. TimeOut();
  2001. #region 2秒内不可点击
  2002. new Thread(new ThreadStart(new Action(() =>
  2003. {
  2004. Dispatcher.Invoke(() =>
  2005. {
  2006. BtnRecord.IsEnabled = false;
  2007. btnStop.IsEnabled = false;
  2008. });
  2009. Thread.Sleep(2000);
  2010. Dispatcher.Invoke(() =>
  2011. {
  2012. BtnRecord.IsEnabled = true;
  2013. btnStop.IsEnabled = true;
  2014. });
  2015. }))).Start();
  2016. #endregion
  2017. try
  2018. {
  2019. APP.FFmpeg.SuspendFFmpeg();
  2020. new Thread(new ThreadStart(new Action(() =>
  2021. {
  2022. while (APP.FFmpeg.myProcess != null)
  2023. {
  2024. Thread.Sleep(100);
  2025. }
  2026. IsStartCount = false;
  2027. }))).Start();
  2028. }
  2029. catch (Exception ex)
  2030. {
  2031. MessageWindow.Show(ex.Message);
  2032. }
  2033. }
  2034. }
  2035. /// <summary>
  2036. /// 录制保存图片
  2037. /// </summary>
  2038. /// <param name="sender"></param>
  2039. /// <param name="e"></param>
  2040. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  2041. {
  2042. if (IsStartCount)
  2043. {
  2044. try
  2045. {
  2046. Dispatcher.Invoke(() =>
  2047. {
  2048. string FilePathName = ImgPath + RsImgName.Count + ".png";
  2049. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)ActualWidth, (int)ActualHeight);
  2050. RsImgName.Add(FilePathName);
  2051. });
  2052. }
  2053. catch (Exception ex)
  2054. {
  2055. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2056. }
  2057. }
  2058. }
  2059. /// <summary>
  2060. /// 停止录制并生成录制文件
  2061. /// </summary>
  2062. private void EndRecord()
  2063. {
  2064. if (!IsFirstR)
  2065. {
  2066. #region 恢复被禁用的按钮
  2067. ImgPrint.Visibility = Visibility.Visible;
  2068. ImgPrintTwo.Visibility = Visibility.Collapsed;
  2069. btnPrint.IsEnabled = true;
  2070. ImgScreenshot.Visibility = Visibility.Visible;
  2071. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  2072. btnScreenshot.IsEnabled = true;
  2073. ImgImport.Visibility = Visibility.Visible;
  2074. ImgImportTwo.Visibility = Visibility.Collapsed;
  2075. btnImport.IsEnabled = true;
  2076. ImgScreenRecording.Visibility = Visibility.Visible;
  2077. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  2078. btnScreenRecording.IsEnabled = true;
  2079. ImgUpload.Visibility = Visibility.Visible;
  2080. ImgUploadTwo.Visibility = Visibility.Collapsed;
  2081. btnUpload.IsEnabled = true;
  2082. ImgSetUp.Visibility = Visibility.Visible;
  2083. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  2084. btnSetUp.IsEnabled = true;
  2085. btnLoginType.IsEnabled = true;
  2086. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  2087. #endregion
  2088. IsSuspendR = true;
  2089. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  2090. ImgStop.Visibility = Visibility.Visible;
  2091. ImgStopTwo.Visibility = Visibility.Collapsed;
  2092. TimeOut();
  2093. txbType.Text = "保存中";
  2094. #region 2秒内不可点击
  2095. new Thread(new ThreadStart(new Action(() =>
  2096. {
  2097. Dispatcher.Invoke(() =>
  2098. {
  2099. BtnRecord.IsEnabled = false;
  2100. btnStop.IsEnabled = false;
  2101. });
  2102. }))).Start();
  2103. #endregion
  2104. try
  2105. {
  2106. #region 清空画板数据
  2107. APP.pageData.currpage = 0;
  2108. APP.pageData.pagenum = 0;
  2109. myblackboard.clear();
  2110. //myblackboard = new BlackboardNew(blackboard_canvas);
  2111. //DataContext = APP.pageData;
  2112. //drawingAttributes = new DrawingAttributes();
  2113. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  2114. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  2115. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  2116. //blackboard_canvas.UseCustomCursor = true;
  2117. //drawingAttributes.FitToCurve = true;
  2118. //drawingAttributes.IgnorePressure = false;
  2119. //drawingAttributes.Width = PenSize;
  2120. //drawingAttributes.Height = PenSize;
  2121. //drawingAttributes.Color = Color;
  2122. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  2123. APP.PageDrawList.Clear();
  2124. imgCanvas.Source = null;
  2125. imgDocumentation.Source = null;
  2126. gridPage.Visibility = Visibility.Collapsed;
  2127. #endregion
  2128. //缩略图
  2129. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  2130. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2131. //缩略图存储位置
  2132. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  2133. int gridActWidth = (int)GridMain.ActualWidth;
  2134. int gridActHeight = (int)GridMain.ActualHeight;
  2135. APP.FFmpeg.StopFFmpeg(AudioPathName);
  2136. new Thread(new ThreadStart(new Action(() =>
  2137. {
  2138. //停止截图
  2139. while (APP.FFmpeg.myProcess != null)
  2140. {
  2141. Thread.Sleep(100);
  2142. }
  2143. Dispatcher.Invoke(() =>
  2144. {
  2145. IsStartCount = false;
  2146. timer.Stop();
  2147. End();
  2148. txbTime.Text = "";
  2149. txbTime.Visibility = Visibility.Hidden;
  2150. });
  2151. //}))).Start();
  2152. //new Thread(new ThreadStart(new Action(() =>
  2153. //{
  2154. //判断音频是否存在 判断音频临时文件夹是否存在
  2155. if (IsRecordAudio)
  2156. {
  2157. if (!FileToolsCommon.IsExistFile(AudioPathName))
  2158. {
  2159. Thread.Sleep(100);
  2160. }
  2161. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  2162. {
  2163. Thread.Sleep(100);
  2164. }
  2165. }
  2166. else
  2167. {
  2168. //没有录制音频
  2169. AudioPathName = null;
  2170. }
  2171. //合成视频
  2172. bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight);
  2173. //}))).Start();
  2174. //new Thread(new ThreadStart(new Action(() =>
  2175. //{
  2176. if (!SynRes)
  2177. {
  2178. Dispatcher.Invoke(() =>
  2179. {
  2180. MessageWindow.Show("视频录制失败,无法保存此视频!");
  2181. BtnRecord.IsEnabled = true;
  2182. btnStop.IsEnabled = true;
  2183. TxbRecordingWord.Text = "录制";
  2184. txbType.Text = "";
  2185. });
  2186. return;
  2187. }
  2188. Dispatcher.Invoke(() =>
  2189. {
  2190. txbType.Text = "转码中";
  2191. });
  2192. while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
  2193. {
  2194. Thread.Sleep(100);
  2195. }
  2196. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
  2197. {
  2198. Thread.Sleep(100);
  2199. }
  2200. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2201. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2202. Thread.Sleep(500);
  2203. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  2204. VideoInfo.VideoPath = VideoSavePathName;
  2205. VideoInfo.ThumbnailPath = ThumbnailPathName;
  2206. //生成缩略图
  2207. bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName);
  2208. Thread.Sleep(500);
  2209. int imgW = (int)GridMain.ActualWidth + (GridMain.ActualWidth % 2 > 0 ? 1 : 0);
  2210. int imgH = (int)GridMain.ActualHeight + (GridMain.ActualHeight % 2 > 0 ? 1 : 0);
  2211. if (ThuRes)
  2212. {
  2213. Bitmap bmp = ImageHelper.ReadBitmapFile(ThumbnailPathName);
  2214. imgW = bmp.Width + (bmp.Width % 2 > 0 ? 1 : 0);
  2215. imgH = bmp.Height + (bmp.Height % 2 > 0 ? 1 : 0);
  2216. }
  2217. APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, imgW, imgH);
  2218. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  2219. VideoInfo.IsUpload = false;
  2220. VideoInfo.Uploaded = 0;
  2221. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  2222. APP.VideoList.Add(VideoInfo);
  2223. //保存数据
  2224. APP.SaveWkData();
  2225. IsFirstR = true;
  2226. Dispatcher.Invoke(() =>
  2227. {
  2228. BtnRecord.IsEnabled = true;
  2229. btnStop.IsEnabled = true;
  2230. TxbRecordingWord.Text = "录制";
  2231. txbType.Text = "";
  2232. });
  2233. }))).Start();
  2234. //List<Model_Video> VideoList
  2235. }
  2236. catch (Exception ex)
  2237. {
  2238. MessageWindow.Show(ex.Message);
  2239. }
  2240. }
  2241. }
  2242. #endregion
  2243. /// <summary>
  2244. /// 登陆事件
  2245. /// </summary>
  2246. /// <param name="sender"></param>
  2247. /// <param name="e"></param>
  2248. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  2249. {
  2250. Login();
  2251. }
  2252. /// <summary>
  2253. /// 登陆
  2254. /// </summary>
  2255. private void Login()
  2256. {
  2257. if (APP.W_LoginWindow == null)
  2258. {
  2259. APP.W_LoginWindow = new LoginWindow
  2260. {
  2261. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  2262. Owner = this
  2263. };
  2264. }
  2265. else
  2266. {
  2267. APP.W_LoginWindow.Initialize();
  2268. }
  2269. APP.W_LoginWindow.ShowDialog();
  2270. if (APP.IsLoginType)
  2271. {
  2272. txbLoginType.Text = APP.UserInfo.Username;
  2273. ImgUpload.Visibility = Visibility.Visible;
  2274. ImgUploadTwo.Visibility = Visibility.Collapsed;
  2275. }
  2276. else
  2277. {
  2278. txbLoginType.Text = "未登录";
  2279. ImgUpload.Visibility = Visibility.Collapsed;
  2280. ImgUploadTwo.Visibility = Visibility.Visible;
  2281. }
  2282. }
  2283. /// <summary>
  2284. /// 获取时间戳
  2285. /// </summary>
  2286. /// <returns></returns>
  2287. public string GetTimeStamp()
  2288. {
  2289. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  2290. return Convert.ToInt64(ts.TotalSeconds).ToString();
  2291. }
  2292. /// <summary>
  2293. /// 返回一个时间戳到毫秒
  2294. /// </summary>
  2295. /// <returns></returns>
  2296. public static long Timestamp()
  2297. {
  2298. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  2299. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  2300. return timestr;
  2301. }
  2302. /// <summary>
  2303. /// 增加事件
  2304. /// </summary>
  2305. /// <param name="sender"></param>
  2306. /// <param name="e"></param>
  2307. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  2308. {
  2309. Record();
  2310. if (APP.pageData.currpage > 0)
  2311. {
  2312. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2313. }
  2314. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  2315. {
  2316. blackboard_canvas.Visibility = Visibility.Visible;
  2317. }
  2318. APP.pageData.pagenum += 1;
  2319. HideAngleBorder();
  2320. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  2321. APP.pageData.currpage = APP.pageData.pagenum;
  2322. myblackboard.changepage(APP.pageData.currpage - 1);
  2323. ///清空页面图片UI
  2324. imgCanvas.Source = null;
  2325. imgDocumentation.Source = null;
  2326. ///画板模型增加一页
  2327. Model_DrawData model_DrawData = new Model_DrawData
  2328. {
  2329. PageNum = APP.pageData.currpage
  2330. };
  2331. APP.PageDrawList.Add(model_DrawData);
  2332. //APP.SaveDraw();
  2333. if (btnImport.IsEnabled == true)
  2334. {
  2335. ///截图可用
  2336. ImgScreenshot.Visibility = Visibility.Visible;
  2337. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  2338. btnScreenshot.IsEnabled = true;
  2339. }
  2340. }
  2341. /// <summary>
  2342. /// 打印事件
  2343. /// </summary>
  2344. /// <param name="sender"></param>
  2345. /// <param name="e"></param>
  2346. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  2347. {
  2348. try
  2349. {
  2350. //3种情况 1.文档图片 2.截图图片 3.没有图片
  2351. iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
  2352. //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  2353. ////设置纸张横向
  2354. //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  2355. string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
  2356. FileToolsCommon.CreateFile(imgPath);
  2357. imgPath += "\\101.pdf";
  2358. iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  2359. document.Open();
  2360. iTextSharp.text.Image image;
  2361. for (int i = 0; i < APP.PageDrawList.Count; i++)
  2362. {
  2363. long ii = Timestamp();
  2364. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  2365. string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  2366. RectangleF rectangleFs = new RectangleF();
  2367. MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  2368. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  2369. if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  2370. {
  2371. }
  2372. else if (APP.PageDrawList[i].ImgDocumentation == true)
  2373. {
  2374. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  2375. }
  2376. else
  2377. {
  2378. RectangleF rectangleF = new RectangleF
  2379. {
  2380. Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  2381. Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  2382. X = (float)APP.PageDrawList[i].ImageLocation.X,
  2383. Y = (float)APP.PageDrawList[i].ImageLocation.Y
  2384. };
  2385. string msg = string.Empty;
  2386. bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
  2387. if (isImg)
  2388. {
  2389. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  2390. }
  2391. else
  2392. {
  2393. image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  2394. }
  2395. }
  2396. if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
  2397. {
  2398. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  2399. }
  2400. else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
  2401. {
  2402. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
  2403. }
  2404. image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  2405. document.NewPage();
  2406. document.Add(image);
  2407. //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  2408. //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  2409. //p1.Leading = 150; //行间距
  2410. //document.Add(p1);
  2411. }
  2412. Console.WriteLine("转换成功!");
  2413. document.Close();
  2414. }
  2415. catch (Exception ex)
  2416. {
  2417. Console.WriteLine("转换失败,原因:" + ex.Message);
  2418. }
  2419. //document.Close();
  2420. ////Console.ReadKey();
  2421. if (APP.W_PrintWindow == null)
  2422. {
  2423. APP.W_PrintWindow = new PrintWindow
  2424. {
  2425. //APP.W_PrintWindow.Topmost = true;
  2426. Owner = this
  2427. };
  2428. }
  2429. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  2430. {
  2431. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath);
  2432. }
  2433. else
  2434. {
  2435. APP.W_PrintWindow.Initialize("");
  2436. }
  2437. APP.W_PrintWindow.ShowDialog();
  2438. //int pr = 1;
  2439. //string msg = string.Empty;
  2440. //string outPut = string.Empty;
  2441. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  2442. //if(pr==0)
  2443. //{
  2444. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  2445. // APP.OutPut = outPut.Split(',');
  2446. // string defa = string.Empty;
  2447. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  2448. // int printResult = 1;
  2449. // string standardError = string.Empty;
  2450. // string standardOutput = string.Empty;
  2451. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  2452. //}
  2453. }
  2454. /// 上一页
  2455. /// </summary>
  2456. /// <param name="sender"></param>
  2457. /// <param name="e"></param>
  2458. private void last_button_Click(object sender, RoutedEventArgs e)
  2459. {
  2460. if (APP.pageData.currpage > 1)
  2461. {
  2462. mouseDown = false;
  2463. HideAngleBorder();
  2464. //if(!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  2465. //{
  2466. // ImgWG();
  2467. //}
  2468. APP.pageData.currpage -= 1;
  2469. myblackboard.changepage(APP.pageData.currpage - 1);
  2470. if (btnImport.IsEnabled == true)
  2471. {
  2472. ///截图可用
  2473. ImgScreenshot.Visibility = Visibility.Visible;
  2474. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  2475. btnScreenshot.IsEnabled = true;
  2476. }
  2477. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  2478. {
  2479. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  2480. {
  2481. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2482. }
  2483. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2484. {
  2485. //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  2486. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  2487. {
  2488. imgCanvas.Source = null;
  2489. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2490. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  2491. ImgScreenshotTwo.Visibility = Visibility.Visible;
  2492. btnScreenshot.IsEnabled = false;
  2493. }
  2494. else
  2495. {
  2496. imgDocumentation.Source = null;
  2497. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2498. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2499. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  2500. {
  2501. mouseDown = false;
  2502. ImgXY();
  2503. }
  2504. }
  2505. }
  2506. else
  2507. {
  2508. imgCanvas.Source = null;
  2509. imgDocumentation.Source = null;
  2510. }
  2511. }
  2512. }
  2513. }
  2514. private void ImgXY()
  2515. {
  2516. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  2517. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  2518. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  2519. //imgCanvas.Margin.Left= APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  2520. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  2521. }
  2522. private void ImgWG()
  2523. {
  2524. mouseDown = false;
  2525. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  2526. {
  2527. X = imgCanvas.Margin.Left,
  2528. Y = imgCanvas.Margin.Top
  2529. };
  2530. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  2531. {
  2532. CenterX = imgCanvas.ActualWidth,
  2533. CenterY = imgCanvas.ActualHeight
  2534. };
  2535. }
  2536. /// <summary>
  2537. /// 下一页
  2538. /// </summary>
  2539. /// <param name="sender"></param>
  2540. /// <param name="e"></param>
  2541. private void next_btn_Click(object sender, RoutedEventArgs e)
  2542. {
  2543. if (APP.pageData.currpage < APP.pageData.pagenum)
  2544. {
  2545. mouseDown = false;
  2546. HideAngleBorder();
  2547. //if (!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  2548. //{
  2549. // ImgWG();
  2550. //}
  2551. APP.pageData.currpage += 1;
  2552. myblackboard.changepage(APP.pageData.currpage - 1);
  2553. if (btnImport.IsEnabled == true)
  2554. {
  2555. ///截图可用
  2556. ImgScreenshot.Visibility = Visibility.Visible;
  2557. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  2558. btnScreenshot.IsEnabled = true;
  2559. }
  2560. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  2561. {
  2562. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  2563. {
  2564. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  2565. }
  2566. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2567. {
  2568. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  2569. {
  2570. imgCanvas.Source = null;
  2571. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2572. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  2573. ImgScreenshotTwo.Visibility = Visibility.Visible;
  2574. btnScreenshot.IsEnabled = false;
  2575. }
  2576. else
  2577. {
  2578. imgDocumentation.Source = null;
  2579. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2580. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2581. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  2582. {
  2583. //var group = IMG.FindResource("Imageview") as TransformGroup;
  2584. //#region 高低 缩放比例
  2585. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  2586. //{
  2587. // var transform1 = group.Children[0] as ScaleTransform;
  2588. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  2589. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  2590. // imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  2591. // imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  2592. //}
  2593. //#endregion
  2594. //#region 坐标XY轴
  2595. //var transform = group.Children[1] as TranslateTransform;
  2596. //transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  2597. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  2598. //#endregion
  2599. mouseDown = false;
  2600. ImgXY();
  2601. }
  2602. }
  2603. }
  2604. else
  2605. {
  2606. imgCanvas.Source = null;
  2607. imgDocumentation.Source = null;
  2608. }
  2609. }
  2610. }
  2611. }
  2612. /// <summary>
  2613. /// 生成图片
  2614. /// </summary>
  2615. /// <param name="_path">图片地址</param>
  2616. /// <param name="_saveimg">保存位置</param>
  2617. /// <param name="_rectangle">图片位置</param>
  2618. /// <param name="errmsg">错误消息</param>
  2619. /// <returns></returns>
  2620. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  2621. {
  2622. errmsg = null;
  2623. try
  2624. {
  2625. Bitmap bitmap = null;
  2626. //创建要显示的图片对象,根据参数的个数设置宽度
  2627. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  2628. Graphics g = Graphics.FromImage(backgroudImg);
  2629. //清除画布,背景设置为白色
  2630. g.Clear(System.Drawing.Color.White);
  2631. if (!string.IsNullOrWhiteSpace(_path))
  2632. {
  2633. bitmap = ImageHelper.ReadBitmapFile(_path);
  2634. g.DrawImage(bitmap, _rectangle);
  2635. }
  2636. backgroudImg.Save(_saveimg);
  2637. g.Dispose();
  2638. backgroudImg.Dispose();
  2639. if (bitmap != null)
  2640. {
  2641. bitmap.Dispose();
  2642. }
  2643. GC.Collect();
  2644. return true;
  2645. }
  2646. catch (Exception ex)
  2647. {
  2648. errmsg = ex.Message;
  2649. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  2650. return false;
  2651. }
  2652. }
  2653. /// <summary>
  2654. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  2655. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  2656. /// </summary>
  2657. /// <param name="pdfInputPath">Word文件路径</param>
  2658. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  2659. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  2660. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  2661. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  2662. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  2663. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  2664. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  2665. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  2666. {
  2667. // 返回的图片绝对路径集合
  2668. List<string> images = new List<string>();
  2669. try
  2670. {
  2671. // open word file
  2672. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  2673. // validate parameter
  2674. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  2675. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  2676. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  2677. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  2678. if (startPageNum <= 0) { startPageNum = 1; }
  2679. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  2680. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  2681. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  2682. if (resolution <= 0) { resolution = 128; }
  2683. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  2684. {
  2685. Resolution = resolution
  2686. };
  2687. // start to convert each page
  2688. for (int i = startPageNum; i <= endPageNum; i++)
  2689. {
  2690. imageSaveOptions.PageIndex = i - 1;
  2691. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  2692. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  2693. APP.num++;
  2694. }
  2695. imageSaveOptions = null;
  2696. doc = null;
  2697. }
  2698. catch (Exception ex)
  2699. {
  2700. //if(ex.Message.ToString().Equals("{\"The document appears to be corrupted and cannot be loaded.\"}"))
  2701. //{
  2702. // MessageWindow.Show("Word文件无效或者Word文件被加密!");
  2703. //}
  2704. //else
  2705. //{
  2706. MessageWindow.Show("该文件无法使用!");
  2707. //}
  2708. LogHelper.WriteErrLog("【导入方法(ConvertWordToImage)】错误日志:" + ex.Message, ex);
  2709. }
  2710. return images;
  2711. }
  2712. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  2713. {
  2714. SaveFormat sf;// = SaveFormat.Unknown;
  2715. if (imageFormat.Equals(ImageFormat.Png))
  2716. {
  2717. sf = SaveFormat.Png;
  2718. }
  2719. else if (imageFormat.Equals(ImageFormat.Jpeg))
  2720. {
  2721. sf = SaveFormat.Jpeg;
  2722. }
  2723. else if (imageFormat.Equals(ImageFormat.Tiff))
  2724. {
  2725. sf = SaveFormat.Tiff;
  2726. }
  2727. else if (imageFormat.Equals(ImageFormat.Bmp))
  2728. {
  2729. sf = SaveFormat.Bmp;
  2730. }
  2731. else
  2732. {
  2733. sf = SaveFormat.Unknown;
  2734. }
  2735. return sf;
  2736. }
  2737. #region 图像缩放,移动
  2738. private bool mouseDown;
  2739. private System.Windows.Point mouseXY;
  2740. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  2741. {
  2742. ContentControl img = sender as ContentControl;
  2743. if (img == null)
  2744. {
  2745. return;
  2746. }
  2747. img.CaptureMouse();
  2748. mouseDown = true;
  2749. mouseXY = e.GetPosition(img);
  2750. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  2751. }
  2752. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  2753. {
  2754. ContentControl img = sender as ContentControl;
  2755. if (img == null)
  2756. {
  2757. return;
  2758. }
  2759. img.ReleaseMouseCapture();
  2760. mouseDown = false;
  2761. }
  2762. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  2763. {
  2764. ContentControl img = sender as ContentControl;
  2765. if (img == null)
  2766. {
  2767. return;
  2768. }
  2769. if (mouseDown)
  2770. {
  2771. Domousemove(img, e);
  2772. }
  2773. }
  2774. /// <summary>
  2775. /// x y轴
  2776. /// </summary>
  2777. /// <param name="img"></param>
  2778. /// <param name="e"></param>
  2779. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  2780. {
  2781. if (e.LeftButton != MouseButtonState.Pressed)
  2782. {
  2783. return;
  2784. }
  2785. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  2786. {
  2787. return;
  2788. }
  2789. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  2790. TranslateTransform transform = group.Children[1] as TranslateTransform;
  2791. System.Windows.Point position = e.GetPosition(img);
  2792. transform.X -= mouseXY.X - position.X;
  2793. transform.Y -= mouseXY.Y - position.Y;
  2794. mouseXY = position;
  2795. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  2796. {
  2797. X = transform.X,
  2798. Y = transform.Y
  2799. };
  2800. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2801. }
  2802. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  2803. {
  2804. ContentControl img = sender as ContentControl;
  2805. if (img == null)
  2806. {
  2807. return;
  2808. }
  2809. System.Windows.Point point = e.GetPosition(img);
  2810. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  2811. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  2812. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  2813. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  2814. double delta = e.Delta * 0.001;
  2815. DowheelZoom(group, point, delta);
  2816. }
  2817. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  2818. {
  2819. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  2820. ScaleTransform transform = group.Children[0] as ScaleTransform;
  2821. if (transform.ScaleX + delta < 0.1)
  2822. {
  2823. return;
  2824. }
  2825. transform.ScaleX += delta;
  2826. transform.ScaleY += delta;
  2827. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  2828. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  2829. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  2830. LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  2831. + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  2832. );
  2833. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  2834. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  2835. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  2836. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  2837. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  2838. {
  2839. X = transform1.X,
  2840. Y = transform1.Y
  2841. };
  2842. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  2843. {
  2844. CenterX = imgCanvas.ActualWidth,
  2845. CenterY = imgCanvas.ActualHeight
  2846. };
  2847. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  2848. }
  2849. #endregion
  2850. #region 点阵笔相关
  2851. #region 值初始化
  2852. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  2853. /// <summary>
  2854. /// A4点阵纸点阵宽度
  2855. /// </summary>
  2856. private const int A4_WIDTH = 5600;
  2857. /// <summary>
  2858. /// A4点阵纸点阵高度
  2859. /// </summary>
  2860. private const int A4_HEIGHT = 7920;
  2861. /// <summary>
  2862. /// 画板
  2863. /// </summary>
  2864. private Graphics graphics;
  2865. /// <summary>
  2866. /// 笔画坐标数组
  2867. /// </summary>
  2868. private List<System.Drawing.Point> stroke;
  2869. /// <summary>
  2870. /// 笔序列号
  2871. /// </summary>
  2872. private string penSerial;
  2873. /// <summary>
  2874. /// 笔是否在点
  2875. /// </summary>
  2876. private bool isPenDown;
  2877. //当前点阵地址
  2878. private string currentPageSerial = string.Empty;
  2879. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  2880. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  2881. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  2882. #endregion
  2883. public void InitPen()
  2884. {
  2885. stroke = new List<System.Drawing.Point>();
  2886. //获取点阵笔实例,并绑定点阵笔事件
  2887. //将授权文件内容传入,获取点阵笔对象实例
  2888. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  2889. //绑定笔连接事件
  2890. APP.digitalPen.PenConnected += OnPenConnect;
  2891. //绑定笔断开事件
  2892. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  2893. //绑定笔书写输出坐标事件
  2894. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  2895. //绑定抬笔事件
  2896. APP.digitalPen.PenUp += OnPenUp;
  2897. //绑定落笔事件
  2898. APP.digitalPen.PenDown += OnPenDown;
  2899. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  2900. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  2901. //完成初始化点阵笔,开始与点阵笔通信
  2902. ERROR_CODE ER = APP.digitalPen.Start();
  2903. ////绑定笔在新的点阵地址页面书写事件
  2904. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  2905. ////绑定笔信息事件
  2906. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  2907. //启动接收笔数据,完成初始化工作
  2908. ERROR_CODE rc = APP.digitalPen.Start();
  2909. //判断是否成功
  2910. if (ER != ERROR_CODE.ERROR_OK)
  2911. {
  2912. MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  2913. }
  2914. }
  2915. /// <summary>
  2916. /// 落笔
  2917. /// </summary>
  2918. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2919. /// <param name="penSerial">点阵笔序列号</param>
  2920. /// <param name="penType">点阵笔型号编号</param>
  2921. private void OnPenDown(ulong time, string penSerial, int penType)
  2922. {
  2923. if (CheckAccess())
  2924. {
  2925. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  2926. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2927. }
  2928. else
  2929. {
  2930. //labPenSerial.Text = penSerial;
  2931. //labPenStatus.Text = "PenDown";
  2932. isPenDown = true;
  2933. //Dispatcher.Invoke(new Action(() =>
  2934. //{
  2935. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  2936. // {
  2937. // if (APP.PageDrawList[i].PageCode == penSerial)
  2938. // {
  2939. // if (i < APP.pageData.pagenum)
  2940. // {
  2941. // if (i < APP.pageData.currpage)
  2942. // {
  2943. // int num = APP.pageData.currpage - i;
  2944. // APP.pageData.currpage -= num;
  2945. // myblackboard.changepage(APP.pageData.currpage - 1);
  2946. // if (APP.PageDrawList.Count > 0)
  2947. // {
  2948. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2949. // {
  2950. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  2951. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2952. // }
  2953. // else
  2954. // {
  2955. // imgCanvas.Source = null;
  2956. // }
  2957. // }
  2958. // }
  2959. // else
  2960. // {
  2961. // int num = i - APP.pageData.currpage;
  2962. // APP.pageData.currpage += num;
  2963. // myblackboard.changepage(APP.pageData.currpage - 1);
  2964. // if (APP.PageDrawList.Count > 0)
  2965. // {
  2966. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  2967. // {
  2968. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  2969. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  2970. // }
  2971. // else
  2972. // {
  2973. // imgCanvas.Source = null;
  2974. // }
  2975. // }
  2976. // }
  2977. // }
  2978. // return;
  2979. // }
  2980. // }
  2981. // //myblackboard.changepages(0, 0, true);
  2982. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  2983. //}));
  2984. }
  2985. //myblackboard.changepages(0, 0, true);
  2986. }
  2987. /// <summary>
  2988. /// 抬笔
  2989. /// </summary>
  2990. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  2991. /// <param name="penSerial">点阵笔序列号</param>
  2992. /// <param name="penType">点阵笔型号编号</param>
  2993. private void OnPenUp(ulong time, string penSerial, int penType)
  2994. {
  2995. if (CheckAccess())
  2996. {
  2997. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  2998. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  2999. }
  3000. else
  3001. {
  3002. isPenDown = false;
  3003. APP.PenSerial = penSerial;
  3004. //int leftPoints = stroke.Count % 3;
  3005. //if (0 != leftPoints)
  3006. //{
  3007. // int from = stroke.Count - leftPoints - 1;
  3008. // if (from < 0)
  3009. // from = 0;
  3010. // int to = stroke.Count - 1;
  3011. // DrawCoordinates(from, to);
  3012. //}
  3013. stroke.Clear();
  3014. }
  3015. if (APP.pageData.currpage > 0)
  3016. {
  3017. Dispatcher.Invoke(new Action(() =>
  3018. {
  3019. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
  3020. }));
  3021. }
  3022. }
  3023. /// <summary>
  3024. /// 笔断开
  3025. /// </summary>
  3026. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3027. /// <param name="penSerial">点阵笔序列号</param>
  3028. /// <param name="penType">点阵笔型号编号</param>
  3029. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  3030. {
  3031. if (CheckAccess())
  3032. {
  3033. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  3034. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3035. }
  3036. else
  3037. {
  3038. APP.PenSerial = penSerial;
  3039. APP.PenStatus = false;
  3040. Dispatcher.Invoke(new Action(() =>
  3041. {
  3042. txbNotConnected.Text = "未连接";
  3043. txbNotConnecteds.Text = "未连接";
  3044. }));
  3045. }
  3046. }
  3047. /// <summary>
  3048. /// 笔连接
  3049. /// </summary>
  3050. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3051. /// <param name="penSerial">点阵笔序列号</param>
  3052. /// <param name="penType">点阵笔型号编号</param>
  3053. private void OnPenConnect(ulong time, string penSerial, int penType)
  3054. {
  3055. if (CheckAccess())
  3056. {
  3057. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  3058. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  3059. }
  3060. else
  3061. {
  3062. APP.PenSerial = penSerial;
  3063. APP.PenStatus = true;
  3064. this.penSerial = penSerial;
  3065. //连接后,在获取笔数据前,可以清除笔内的历史数据
  3066. //APP.digitalPen.ClearMemory(penSerial);
  3067. //开始接收笔数据
  3068. APP.digitalPen.GetPenData(penSerial);
  3069. Dispatcher.Invoke(new Action(() =>
  3070. {
  3071. txbNotConnected.Text = "已连接";
  3072. txbNotConnecteds.Text = "已连接";
  3073. }));
  3074. }
  3075. }
  3076. /// <summary>
  3077. /// 电池电量
  3078. /// </summary>
  3079. /// <param name="time"></param>
  3080. /// <param name="penSerial"></param>
  3081. /// <param name="penType"></param>
  3082. /// <param name="capacity"></param>
  3083. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  3084. {
  3085. if (CheckAccess())
  3086. {
  3087. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  3088. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  3089. }
  3090. else
  3091. {
  3092. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  3093. }
  3094. }
  3095. /// <summary>
  3096. /// 已用存储
  3097. /// </summary>
  3098. /// <param name="time"></param>
  3099. /// <param name="penSerial"></param>
  3100. /// <param name="penType"></param>
  3101. /// <param name="fillLevel"></param>
  3102. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  3103. {
  3104. if (CheckAccess())
  3105. {
  3106. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  3107. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  3108. }
  3109. else
  3110. {
  3111. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  3112. }
  3113. }
  3114. /// <summary>
  3115. /// 笔书写,收到坐标
  3116. /// </summary>
  3117. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  3118. /// <param name="penSerial">点阵笔序列号</param>
  3119. /// <param name="penType">点阵笔型号编号</param>
  3120. /// <param name="pageSerial">点阵地址</param>
  3121. /// <param name="cx">x坐标</param>
  3122. /// <param name="cy">y坐标</param>
  3123. /// <param name="force">压力值</param>
  3124. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  3125. {
  3126. if (CheckAccess())
  3127. {
  3128. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  3129. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  3130. }
  3131. else
  3132. {
  3133. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  3134. if (!isPenDown)
  3135. {
  3136. return;
  3137. }
  3138. stroke.Add(new System.Drawing.Point(cx, cy));
  3139. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  3140. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  3141. //点
  3142. double testX = cx * PropW;
  3143. double testY = cy * PropH;
  3144. //pageSerial //点阵IP地址 与打印的页面关联
  3145. if (APP.pageData.currpage > 0)
  3146. {
  3147. Dispatcher.Invoke(new Action(() =>
  3148. {
  3149. //myblackboard.changepages(testX, testY,false);
  3150. myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
  3151. #region 设置滚动条位置
  3152. //点在显示页面上方
  3153. if (testY < scroMain.VerticalOffset)
  3154. {
  3155. //滚动条当前位置
  3156. double RollCurrentLocation = scroMain.VerticalOffset;
  3157. //向上滚动至以点为中心需要滚动的距离
  3158. double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
  3159. //如果小于0则等于0
  3160. double RollLocation = RollCurrentLocation - UpRoll;
  3161. if (RollLocation < 0)
  3162. {
  3163. RollLocation = 0;
  3164. }
  3165. ////滚动条实际偏移量
  3166. //double RollOffset = RollCurrentLocation - RollLocation;
  3167. scroMain.ScrollToVerticalOffset(RollLocation);
  3168. }
  3169. //点在显示页面下方
  3170. if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
  3171. {
  3172. //滚动条当前位置
  3173. double RollCurrentLocation = scroMain.VerticalOffset;
  3174. //向下滚动至以点为中心需要滚动的距离
  3175. double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  3176. //如果小于0则等于0
  3177. double RollLocation = RollCurrentLocation + DownRoll;
  3178. //滚动条最大滚动值
  3179. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  3180. if (RollLocation > ScrollbarMaxNum)
  3181. {
  3182. RollLocation = ScrollbarMaxNum;
  3183. }
  3184. ////滚动条实际偏移量
  3185. //double RollOffset = RollLocation-RollCurrentLocation;
  3186. scroMain.ScrollToVerticalOffset(RollLocation);
  3187. }
  3188. #endregion
  3189. //gridM.Height //A4高度
  3190. //scroMain.VerticalOffset;//获取滚动条位置
  3191. //scroMain.ActualHeight//A4纸显示高度
  3192. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  3193. //Mouse.GetPosition(this)
  3194. if (testX > 0 && testY > 0)
  3195. {
  3196. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3197. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  3198. SetCursorPos((int)getP.X, (int)getP.Y);
  3199. }
  3200. }));
  3201. }
  3202. ////每3个点画一条曲线
  3203. //if (stroke.Count % 3 == 0)
  3204. //{
  3205. // int from = stroke.Count - 3 - 1;
  3206. // if (from < 0)
  3207. // from = 0;
  3208. // int to = stroke.Count - 1;
  3209. // DrawCoordinates(from, to);
  3210. //}
  3211. }
  3212. }
  3213. /// <summary>
  3214. /// 停止笔
  3215. /// </summary>
  3216. public void StopDigitalPen()
  3217. {
  3218. //停止,释放资源
  3219. APP.digitalPen.Stop();
  3220. }
  3221. /// <summary>
  3222. /// 清空笔内存储
  3223. /// </summary>
  3224. public void ClearPenStorage()
  3225. {
  3226. if (!string.IsNullOrEmpty(penSerial))
  3227. {
  3228. APP.digitalPen.ClearMemory(penSerial);
  3229. }
  3230. }
  3231. /// <summary>
  3232. /// 获取剩余电量
  3233. /// </summary>
  3234. public void GetPenElectricityQuantity()
  3235. {
  3236. if (!string.IsNullOrEmpty(penSerial))
  3237. {
  3238. APP.digitalPen.GetBatteryCapacity(penSerial);
  3239. }
  3240. }
  3241. /// <summary>
  3242. /// 获取存储空间
  3243. /// </summary>
  3244. public void GetUsedStorage()
  3245. {
  3246. if (!string.IsNullOrEmpty(penSerial))
  3247. {
  3248. APP.digitalPen.GetMemoryFillLevel(penSerial);
  3249. }
  3250. }
  3251. /// <summary>
  3252. /// 开启悬浮
  3253. /// </summary>
  3254. public void 开启悬浮()
  3255. {
  3256. if (!string.IsNullOrEmpty(penSerial))
  3257. {
  3258. APP.digitalPen.SetPenHoverMode(true, penSerial);
  3259. }
  3260. }
  3261. /// <summary>
  3262. /// 关闭悬浮
  3263. /// </summary>
  3264. public void 关闭悬浮()
  3265. {
  3266. if (!string.IsNullOrEmpty(penSerial))
  3267. {
  3268. APP.digitalPen.SetPenHoverMode(false, penSerial);
  3269. }
  3270. }
  3271. #endregion
  3272. /// <summary>
  3273. /// 最小化
  3274. /// </summary>
  3275. /// <param name="sender"></param>
  3276. /// <param name="e"></param>
  3277. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  3278. {
  3279. if (WindowState == WindowState.Minimized)
  3280. {
  3281. WindowState = WindowState.Normal;
  3282. }
  3283. else
  3284. {
  3285. WindowState = WindowState.Minimized;
  3286. }
  3287. }
  3288. /// <summary>
  3289. /// 位置确定
  3290. /// </summary>
  3291. /// <param name="sender"></param>
  3292. /// <param name="e"></param>
  3293. private void BtnOk_Click(object sender, RoutedEventArgs e)
  3294. {
  3295. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3296. //btnOk.Visibility = Visibility.Collapsed;
  3297. //blackboard_canvas.Visibility = Visibility.Visible;
  3298. }
  3299. /// <summary>
  3300. /// 引用user32.dll动态链接库(windows api),
  3301. /// 使用库中定义 API:SetCursorPos
  3302. /// 设置光标位置
  3303. /// </summary>
  3304. [System.Runtime.InteropServices.DllImport("user32.dll")]
  3305. private static extern int SetCursorPos(int x, int y);
  3306. #region 图片拉伸移动
  3307. private System.Windows.Point initialPoint;
  3308. /// <summary>
  3309. /// 隐藏图片四个点和线
  3310. /// </summary>
  3311. private void HideAngleBorder()
  3312. {
  3313. RectLeftUp.Visibility = Visibility.Hidden;
  3314. RectRightUp.Visibility = Visibility.Hidden;
  3315. RectLeftDown.Visibility = Visibility.Hidden;
  3316. RectRightDown.Visibility = Visibility.Hidden;
  3317. RectImgBorder.Visibility = Visibility.Hidden;
  3318. }
  3319. private void ShowAngleBorder()
  3320. {
  3321. PointLocation();
  3322. RectLeftUp.Visibility = Visibility.Visible;
  3323. RectRightUp.Visibility = Visibility.Visible;
  3324. RectLeftDown.Visibility = Visibility.Visible;
  3325. RectRightDown.Visibility = Visibility.Visible;
  3326. RectImgBorder.Visibility = Visibility.Visible;
  3327. }
  3328. /// <summary>
  3329. /// 确定四个点和边框的位置大小
  3330. /// </summary>
  3331. private void PointLocation()
  3332. {
  3333. RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
  3334. RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
  3335. RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
  3336. Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
  3337. Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
  3338. Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  3339. Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
  3340. Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
  3341. Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  3342. Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  3343. Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  3344. }
  3345. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  3346. {
  3347. System.Windows.Point point = e.GetPosition(imgCanvas);
  3348. initialPoint = point;
  3349. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  3350. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  3351. //{
  3352. // Console.WriteLine("在范围内");
  3353. //}
  3354. HideAngleBorder();
  3355. }
  3356. private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3357. {
  3358. if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
  3359. {
  3360. System.Windows.Point point = e.GetPosition(imgCanvas);
  3361. imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
  3362. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3363. {
  3364. X = imgCanvas.Margin.Left,
  3365. Y = imgCanvas.Margin.Top
  3366. };
  3367. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  3368. {
  3369. CenterX = imgCanvas.ActualWidth,
  3370. CenterY = imgCanvas.ActualHeight
  3371. };
  3372. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3373. }
  3374. }
  3375. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  3376. {
  3377. if (mouseDown)
  3378. {
  3379. ShowAngleBorder();
  3380. }
  3381. }
  3382. private System.Drawing.PointF imgRightDown;
  3383. /// <summary>
  3384. /// 设置控件最上层
  3385. /// </summary>
  3386. /// <param name="element"></param>
  3387. public void BringToFront(Thumb element)//图片置于最顶层显示
  3388. {
  3389. if (element == null)
  3390. {
  3391. return;
  3392. }
  3393. Canvas parent = element.Parent as Canvas;
  3394. if (parent == null)
  3395. {
  3396. return;
  3397. }
  3398. int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
  3399. .Where(x => x != element)
  3400. .Select(x => Canvas.GetZIndex(x))
  3401. .Max();
  3402. Canvas.SetZIndex(element, maxZ + 1);
  3403. }
  3404. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  3405. {
  3406. try
  3407. {
  3408. Thumb thu = (Thumb)sender;
  3409. BringToFront(thu);
  3410. imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
  3411. HideAngleBorder();
  3412. switch (thu.Name)
  3413. {
  3414. case "RectLeftUp":
  3415. RectLeftUp.Visibility = Visibility.Visible;
  3416. break;
  3417. case "RectRightUp":
  3418. RectRightUp.Visibility = Visibility.Visible;
  3419. break;
  3420. case "RectLeftDown":
  3421. RectLeftDown.Visibility = Visibility.Visible;
  3422. break;
  3423. case "RectRightDown":
  3424. RectRightDown.Visibility = Visibility.Visible;
  3425. break;
  3426. default:
  3427. break;
  3428. }
  3429. }
  3430. catch (Exception ex)
  3431. {
  3432. MessageWindow.Show(ex.Message);
  3433. }
  3434. }
  3435. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  3436. {
  3437. try
  3438. {
  3439. if (mouseDown)
  3440. {
  3441. Thumb thu = (Thumb)sender;
  3442. #region 判断是否超出 暂无
  3443. double plul = Canvas.GetLeft(RectLeftUp);
  3444. double plut = Canvas.GetTop(RectLeftUp);
  3445. double prdl = Canvas.GetLeft(RectRightDown);
  3446. double prdt = Canvas.GetTop(RectRightDown);
  3447. #endregion
  3448. //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  3449. //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  3450. double imgW = 0;
  3451. double imgH = 0;
  3452. double imgX = 0;
  3453. double imgY = 0;
  3454. switch (thu.Name)
  3455. {
  3456. case "RectLeftUp":
  3457. #region 左上
  3458. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  3459. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  3460. imgX = 0;
  3461. imgY = 0;
  3462. if (imgW < 50)
  3463. {
  3464. imgCanvas.Width = 50;
  3465. imgX = imgCanvas.Margin.Left;
  3466. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  3467. }
  3468. else
  3469. {
  3470. imgCanvas.Width = imgW;
  3471. imgX = Mouse.GetPosition(gridM).X;
  3472. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  3473. }
  3474. if (imgH < 50)
  3475. {
  3476. imgCanvas.Height = 50;
  3477. imgY = imgCanvas.Margin.Top;
  3478. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  3479. }
  3480. else
  3481. {
  3482. imgCanvas.Height = imgH;
  3483. imgY = Mouse.GetPosition(gridM).Y;
  3484. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  3485. }
  3486. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  3487. #endregion
  3488. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  3489. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  3490. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
  3491. break;
  3492. case "RectRightUp":
  3493. #region 右上
  3494. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  3495. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  3496. imgX = 0;
  3497. imgY = 0;
  3498. if (imgW < 50)
  3499. {
  3500. imgCanvas.Width = 50;
  3501. imgX = imgCanvas.Margin.Left;
  3502. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  3503. }
  3504. else
  3505. {
  3506. imgCanvas.Width = imgW;
  3507. imgX = imgCanvas.Margin.Left;
  3508. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  3509. }
  3510. if (imgH < 50)
  3511. {
  3512. imgCanvas.Height = 50;
  3513. imgY = imgCanvas.Margin.Top;
  3514. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  3515. }
  3516. else
  3517. {
  3518. imgCanvas.Height = imgH;
  3519. imgY = Mouse.GetPosition(gridM).Y;
  3520. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  3521. }
  3522. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  3523. //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  3524. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  3525. //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
  3526. #endregion
  3527. break;
  3528. case "RectLeftDown":
  3529. #region 左下
  3530. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  3531. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  3532. imgX = 0;
  3533. imgY = 0;
  3534. if (imgW < 50)
  3535. {
  3536. imgCanvas.Width = 50;
  3537. imgX = imgCanvas.Margin.Left;
  3538. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  3539. }
  3540. else
  3541. {
  3542. imgCanvas.Width = imgW;
  3543. imgX = Mouse.GetPosition(gridM).X;
  3544. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  3545. }
  3546. if (imgH < 50)
  3547. {
  3548. imgCanvas.Height = 50;
  3549. imgY = imgCanvas.Margin.Top;
  3550. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  3551. }
  3552. else
  3553. {
  3554. imgCanvas.Height = imgH;
  3555. imgY = imgCanvas.Margin.Top;
  3556. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  3557. }
  3558. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  3559. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  3560. //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  3561. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
  3562. #endregion
  3563. break;
  3564. case "RectRightDown":
  3565. #region 右下
  3566. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  3567. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  3568. if (imgW < 50)
  3569. {
  3570. imgCanvas.Width = 50;
  3571. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  3572. }
  3573. else
  3574. {
  3575. imgCanvas.Width = imgW;
  3576. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  3577. }
  3578. if (imgH < 50)
  3579. {
  3580. imgCanvas.Height = 50;
  3581. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  3582. }
  3583. else
  3584. {
  3585. imgCanvas.Height = imgH;
  3586. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  3587. }
  3588. //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  3589. //imgCanvas.Width += e.HorizontalChange;
  3590. //imgCanvas.Height += e.VerticalChange;
  3591. #endregion
  3592. break;
  3593. default:
  3594. break;
  3595. }
  3596. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3597. {
  3598. X = imgCanvas.Margin.Left,
  3599. Y = imgCanvas.Margin.Top
  3600. };
  3601. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  3602. {
  3603. CenterX = imgCanvas.ActualWidth,
  3604. CenterY = imgCanvas.ActualHeight
  3605. };
  3606. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3607. }
  3608. //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
  3609. //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
  3610. //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
  3611. //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
  3612. }
  3613. catch (Exception)
  3614. {
  3615. MessageWindow.Show("图片过小!");
  3616. }
  3617. }
  3618. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  3619. {
  3620. ShowAngleBorder();
  3621. }
  3622. #endregion
  3623. #region 方法
  3624. /// <summary>
  3625. /// 录屏 录制 截图 导入文档 增加 主页面显示
  3626. /// </summary>
  3627. private void Record()
  3628. {
  3629. GridMain.Visibility = Visibility.Visible;
  3630. gridSetUp.Visibility = Visibility.Collapsed;
  3631. gridUpload.Visibility = Visibility.Collapsed;
  3632. if (APP.pageData.pagenum > 0)
  3633. {
  3634. gridPage.Visibility = Visibility.Visible;
  3635. }
  3636. DataContext = APP.pageData;
  3637. }
  3638. /// <summary>
  3639. /// 设置页面显示
  3640. /// </summary>
  3641. private void SetUp()
  3642. {
  3643. }
  3644. #endregion
  3645. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3646. {
  3647. mouseDown = true;
  3648. }
  3649. private void Button_Click(object sender, RoutedEventArgs e)
  3650. {
  3651. System.Drawing.Size a = PrimaryScreen.DESKTOP;
  3652. System.Drawing.Size b = PrimaryScreen.WorkingArea;
  3653. int c = PrimaryScreen.DpiX;
  3654. int d = PrimaryScreen.DpiY;
  3655. float x = PrimaryScreen.ScaleX;
  3656. float y = PrimaryScreen.ScaleY;
  3657. }
  3658. }
  3659. }