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

XHMicroLessonSystemWindow.xaml.cs 169KB

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