星火微课系统客户端
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.

MainWindow.xaml.cs 152KB

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