星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

MainWindow.xaml.cs 153KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144
  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. private System.Timers.Timer _times;
  853. /// <summary>
  854. /// 摄像头打开事件
  855. /// </summary>
  856. /// <param name="sender">
  857. /// </param>
  858. /// <param name="e">
  859. /// </param>
  860. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  861. {
  862. if (!_isRbnOpen)
  863. {
  864. #region 防止连击
  865. if (_isPressButton)
  866. {
  867. return;
  868. }
  869. _isPressButton = true;
  870. Task.Run
  871. (
  872. () =>
  873. {
  874. Thread.Sleep(3000);
  875. _isPressButton = false;
  876. }
  877. );
  878. #endregion 防止连击
  879. CameraHelper.UpdateCameraDevices();
  880. if (CameraHelper.CameraDevices.Count > 0)
  881. {
  882. if (string.IsNullOrWhiteSpace(App.CameraName))
  883. {
  884. App.CameraName = CameraHelper.CameraDevices[0].MonikerString;
  885. }
  886. int cameraIndex = 0;
  887. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  888. {
  889. if (CameraHelper.CameraDevices[i].MonikerString == App.CameraName)
  890. {
  891. cameraIndex = i;
  892. }
  893. }
  894. CameraHelper.imageCallback = LoadImage;
  895. CameraHelper.StartCameraDevice(cameraIndex, this.Dispatcher);
  896. if (_timer != null)
  897. {
  898. _times.Elapsed -= Times_Elapsed;
  899. _times.Enabled = false;
  900. _times.Dispose();
  901. }
  902. _times = new System.Timers.Timer(200) //初始值为300
  903. {
  904. AutoReset = true //设置是否执行System.Timers.Timer.Elapsed事件
  905. }; //设置执行一次(false)还是一直执行(true)
  906. _times.Elapsed += Times_Elapsed;
  907. _times.Enabled = true; //启动计时器
  908. _isRbnOpen = true;
  909. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  910. FileToolsCommon.CreateDirectory(imgPath);
  911. HeadImg.Visibility = Visibility.Visible;
  912. // < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  913. switch (App.CameraPosition)
  914. {
  915. case "1":
  916. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  917. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  918. break;
  919. case "2":
  920. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  921. HeadImg.VerticalAlignment = VerticalAlignment.Top;
  922. break;
  923. case "3":
  924. HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
  925. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  926. break;
  927. case "4":
  928. HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
  929. HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
  930. break;
  931. }
  932. RbnTurnOff.IsEnabled = false;
  933. Task.Run
  934. (
  935. () =>
  936. {
  937. Thread.Sleep(3000);
  938. Dispatcher.Invoke
  939. (
  940. () =>
  941. {
  942. RbnTurnOff.IsEnabled = true;
  943. }
  944. );
  945. }
  946. );
  947. }
  948. }
  949. }
  950. /// <summary>
  951. /// 摄像头关闭事件
  952. /// </summary>
  953. /// <param name="sender">
  954. /// </param>
  955. /// <param name="e">
  956. /// </param>
  957. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  958. {
  959. if (_isRbnOpen)
  960. {
  961. #region 防止连击
  962. if (_isPressButton)
  963. {
  964. return;
  965. }
  966. _isPressButton = true;
  967. Task.Run
  968. (
  969. () =>
  970. {
  971. Thread.Sleep(500);
  972. _isPressButton = false;
  973. }
  974. );
  975. #endregion 防止连击
  976. _isRbnOpen = false;
  977. HeadImg.Visibility = Visibility.Hidden;
  978. RbnOpen.IsEnabled = false;
  979. CameraHelper.CloseDevice();
  980. RbnOpen.IsEnabled = true;
  981. if (_timer != null)
  982. {
  983. _times.Elapsed -= Times_Elapsed;
  984. _times.Enabled = false;
  985. _times.Dispose();
  986. _times = null;
  987. }
  988. }
  989. }
  990. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  991. {
  992. if (_isRbnOpen)
  993. {
  994. try
  995. {
  996. long time = Timestamp();
  997. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  998. CameraHelper.CaptureImage(imgPath, time.ToString());
  999. }
  1000. catch (Exception ex)
  1001. {
  1002. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  1003. }
  1004. }
  1005. }
  1006. #endregion 摄像头
  1007. #region 设备检测
  1008. /// <summary>
  1009. /// 设备检测
  1010. /// </summary>
  1011. /// <param name="sender">
  1012. /// </param>
  1013. /// <param name="e">
  1014. /// </param>
  1015. private async void BtnDevice_Click(object sender, RoutedEventArgs e)
  1016. {
  1017. if (RbnTurnOff.IsChecked != null && !(bool)RbnTurnOff.IsChecked)
  1018. {
  1019. RbnTurnOff.IsChecked = true;
  1020. RbnTurnOff_Click(null, null);
  1021. await Task.Delay(1000);
  1022. }
  1023. DeviceWindow deviceWin = new DeviceWindow();
  1024. deviceWin.ShowDialog();
  1025. }
  1026. #endregion 设备检测
  1027. #endregion 事件
  1028. #region 画笔
  1029. /// <summary>
  1030. /// 画笔颜色事件 蓝色
  1031. /// </summary>
  1032. /// <param name="sender">
  1033. /// </param>
  1034. /// <param name="e">
  1035. /// </param>
  1036. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  1037. {
  1038. _drawingAttributes.Color = Colors.DeepSkyBlue;
  1039. _color = Colors.DeepSkyBlue;
  1040. ImgRed.Visibility = Visibility.Collapsed;
  1041. ImgGray.Visibility = Visibility.Collapsed;
  1042. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1043. ImgYellow.Visibility = Visibility.Collapsed;
  1044. ImgBlue.Visibility = Visibility.Visible;
  1045. }
  1046. /// <summary>
  1047. /// 画笔颜色事件 青色
  1048. /// </summary>
  1049. /// <param name="sender">
  1050. /// </param>
  1051. /// <param name="e">
  1052. /// </param>
  1053. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  1054. {
  1055. _drawingAttributes.Color = Colors.LimeGreen;
  1056. _color = Colors.LimeGreen;
  1057. ImgRed.Visibility = Visibility.Collapsed;
  1058. ImgGray.Visibility = Visibility.Collapsed;
  1059. ImgCyanBlue.Visibility = Visibility.Visible;
  1060. ImgYellow.Visibility = Visibility.Collapsed;
  1061. ImgBlue.Visibility = Visibility.Collapsed;
  1062. }
  1063. /// <summary>
  1064. /// 画笔颜色事件 黑色
  1065. /// </summary>
  1066. /// <param name="sender">
  1067. /// </param>
  1068. /// <param name="e">
  1069. /// </param>
  1070. private void BtnGray_Click(object sender, RoutedEventArgs e)
  1071. {
  1072. _drawingAttributes.Color = Colors.Black;
  1073. _color = Colors.Black;
  1074. ImgRed.Visibility = Visibility.Collapsed;
  1075. ImgGray.Visibility = Visibility.Visible;
  1076. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1077. ImgYellow.Visibility = Visibility.Collapsed;
  1078. ImgBlue.Visibility = Visibility.Collapsed;
  1079. }
  1080. /// <summary>
  1081. /// 画笔颜色事件 红色
  1082. /// </summary>
  1083. /// <param name="sender">
  1084. /// </param>
  1085. /// <param name="e">
  1086. /// </param>
  1087. private void BtnRed_Click(object sender, RoutedEventArgs e)
  1088. {
  1089. //设置 DrawingAttributes 的 Color 属性设置颜色
  1090. _drawingAttributes.Color = Colors.Red;
  1091. _color = Colors.Red;
  1092. ImgRed.Visibility = Visibility.Visible;
  1093. ImgGray.Visibility = Visibility.Collapsed;
  1094. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1095. ImgYellow.Visibility = Visibility.Collapsed;
  1096. ImgBlue.Visibility = Visibility.Collapsed;
  1097. }
  1098. /// <summary>
  1099. /// 画笔颜色事件 白色
  1100. /// </summary>
  1101. /// <param name="sender">
  1102. /// </param>
  1103. /// <param name="e">
  1104. /// </param>
  1105. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  1106. {
  1107. _drawingAttributes.Color = Colors.White;
  1108. _color = Colors.White;
  1109. }
  1110. /// <summary>
  1111. /// 画笔颜色事件 黄色
  1112. /// </summary>
  1113. /// <param name="sender">
  1114. /// </param>
  1115. /// <param name="e">
  1116. /// </param>
  1117. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  1118. {
  1119. _drawingAttributes.Color = Colors.Gold;
  1120. _color = Colors.Gold;
  1121. ImgRed.Visibility = Visibility.Collapsed;
  1122. ImgGray.Visibility = Visibility.Collapsed;
  1123. ImgCyanBlue.Visibility = Visibility.Collapsed;
  1124. ImgYellow.Visibility = Visibility.Visible;
  1125. ImgBlue.Visibility = Visibility.Collapsed;
  1126. }
  1127. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1128. {
  1129. _mouseDown = true;
  1130. _imageOperationUtil.setMouseDown(_mouseDown);
  1131. }
  1132. /// <summary>
  1133. /// 画笔粗细事件 粗
  1134. /// </summary>
  1135. /// <param name="sender">
  1136. /// </param>
  1137. /// <param name="e">
  1138. /// </param>
  1139. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  1140. {
  1141. _drawingAttributes.Width = 5;
  1142. _drawingAttributes.Height = 5;
  1143. _penSize = 5;
  1144. }
  1145. /// <summary>
  1146. /// 画笔粗细事件 细
  1147. /// </summary>
  1148. /// <param name="sender">
  1149. /// </param>
  1150. /// <param name="e">
  1151. /// </param>
  1152. private void RbnFine_Click(object sender, RoutedEventArgs e)
  1153. {
  1154. _drawingAttributes.Width = 1;
  1155. _drawingAttributes.Height = 1;
  1156. _penSize = 1;
  1157. }
  1158. /// <summary>
  1159. /// 画笔粗细事件 中
  1160. /// </summary>
  1161. /// <param name="sender">
  1162. /// </param>
  1163. /// <param name="e">
  1164. /// </param>
  1165. private void RbnIn_Click(object sender, RoutedEventArgs e)
  1166. {
  1167. _drawingAttributes.Width = 3;
  1168. _drawingAttributes.Height = 3;
  1169. _penSize = 3;
  1170. }
  1171. #endregion 画笔
  1172. #region 导入截图
  1173. /// <summary>
  1174. /// 防止图片地址重复
  1175. /// </summary>
  1176. private long _wordImgNum = 9999;
  1177. /// <summary>
  1178. /// 返回一个时间戳到毫秒
  1179. /// </summary>
  1180. /// <returns>
  1181. /// </returns>
  1182. public static long Timestamp()
  1183. {
  1184. TimeSpan ts = DateTime.UtcNow
  1185. - new DateTime
  1186. (
  1187. 1970,
  1188. 1,
  1189. 1,
  1190. 0,
  1191. 0,
  1192. 0,
  1193. 0
  1194. );
  1195. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  1196. return timestr;
  1197. }
  1198. /// <summary>
  1199. /// 获取时间戳
  1200. /// </summary>
  1201. /// <returns>
  1202. /// </returns>
  1203. public string GetTimeStamp()
  1204. {
  1205. TimeSpan ts = DateTime.Now
  1206. - new DateTime
  1207. (
  1208. 1970,
  1209. 1,
  1210. 1,
  1211. 0,
  1212. 0,
  1213. 0,
  1214. 0
  1215. );
  1216. return Convert.ToInt64(ts.TotalSeconds).ToString();
  1217. }
  1218. /// <summary>
  1219. /// 导入-结束
  1220. /// </summary>
  1221. /// <returns>
  1222. /// </returns>
  1223. public void InvokeServerCompate(object obj)
  1224. {
  1225. //APP.myloading.Hide();
  1226. App.myloading.Hide();
  1227. }
  1228. public void WindowType()
  1229. {
  1230. this.Activate();
  1231. }
  1232. /// <summary>
  1233. /// 导入事件
  1234. /// </summary>
  1235. /// <param name="sender">
  1236. /// </param>
  1237. /// <param name="e">
  1238. /// </param>
  1239. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1240. {
  1241. try
  1242. {
  1243. PrepareRecord();
  1244. HideAngleBorder();
  1245. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1246. _ofd = new System.Windows.Forms.OpenFileDialog
  1247. {
  1248. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1249. //增加导入图片
  1250. Filter = @"文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1251. InitialDirectory = desktopPath,
  1252. Multiselect = false,
  1253. AddExtension = true,
  1254. DereferenceLinks = true
  1255. };
  1256. App.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1257. }
  1258. catch (Exception ex)
  1259. {
  1260. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1261. }
  1262. }
  1263. /// <summary>
  1264. /// 截图事件
  1265. /// </summary>
  1266. /// <param name="sender">
  1267. /// </param>
  1268. /// <param name="e">
  1269. /// </param>
  1270. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  1271. {
  1272. JietuAction();
  1273. }
  1274. private async void JietuAction()
  1275. {
  1276. PrepareRecord();
  1277. HideAngleBorder();
  1278. if (WindowState == WindowState.Normal) //截图隐藏窗口
  1279. {
  1280. WindowState = WindowState.Minimized;
  1281. }
  1282. await Task.Delay(300);
  1283. ImgCanvas.Margin = new Thickness
  1284. (
  1285. 0,
  1286. 0,
  1287. 0,
  1288. 0
  1289. );
  1290. App.ImgPath = string.Empty;
  1291. string time = GetTimeStamp();
  1292. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  1293. App.ImgPath = desktopPath;
  1294. ImageHelper.GetScreenshot
  1295. (
  1296. new Rectangle
  1297. (
  1298. 0,
  1299. 0,
  1300. 0,
  1301. 0
  1302. )
  1303. {
  1304. Location = default,
  1305. Size = default
  1306. },
  1307. desktopPath,
  1308. false,
  1309. out var _
  1310. );
  1311. _kHook.Stop();
  1312. if (App.W_JieTuWindow != null)
  1313. {
  1314. App.W_JieTuWindow.initialization();
  1315. App.W_JieTuWindow.Screenshot();
  1316. App.W_JieTuWindow.InitializeKeyDownEvent();
  1317. App.W_JieTuWindow.WindowState = WindowState.Maximized;
  1318. App.W_JieTuWindow.Visibility = Visibility.Visible;
  1319. }
  1320. else
  1321. {
  1322. App.W_JieTuWindow = new JieTuWindow();
  1323. App.W_JieTuWindow.InitializeKeyDownEvent();
  1324. // 订阅事件
  1325. App.W_JieTuWindow.ChangeTextEvent += frm_ChangeTextEvent;
  1326. App.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  1327. App.W_JieTuWindow.Show();
  1328. }
  1329. }
  1330. /// <summary>
  1331. /// 截图关闭窗口
  1332. /// </summary>
  1333. /// <param name="text">
  1334. /// </param>
  1335. private void frm_ChangeTextEvent(string text)
  1336. {
  1337. if ("关闭窗口".Equals(text))
  1338. {
  1339. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1340. {
  1341. WindowState = WindowState.Normal;
  1342. Activate();
  1343. }
  1344. InitializeKeyDownEvent();
  1345. if (!string.IsNullOrWhiteSpace(App.ImgPath) && File.Exists(App.ImgPath))
  1346. {
  1347. if (App.PageContextData.currpage == 0)
  1348. {
  1349. App.PageContextData.pagenum += 1;
  1350. App.PageContextData.currpage = App.PageContextData.pagenum;
  1351. myblackboard.changepage(App.PageContextData.currpage - 1);
  1352. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1353. #region 插入页码
  1354. #endregion 插入页码
  1355. }
  1356. if (App.PageDrawList.Count >= App.PageContextData.currpage)
  1357. {
  1358. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
  1359. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
  1360. }
  1361. else
  1362. {
  1363. Model_DrawData modelDrawData = new Model_DrawData
  1364. {
  1365. PageImagePath = App.ImgPath,
  1366. PdfImagePath = App.ImgPath
  1367. };
  1368. App.PageDrawList.Add(modelDrawData);
  1369. }
  1370. if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  1371. {
  1372. ImgDocumentation.Source = null;
  1373. BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1374. _mouseDown = false;
  1375. _imageOperationUtil.setMouseDown(_mouseDown);
  1376. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1377. {
  1378. X = 0.1,
  1379. Y = 0.1
  1380. };
  1381. App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
  1382. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  1383. ImgCanvas.Source = bitImg;
  1384. ImgCanvas.Width = bitImg.Width;
  1385. ImgCanvas.Height = bitImg.Height;
  1386. ScroMain.ScrollToVerticalOffset(0);
  1387. App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1388. {
  1389. CenterX = ImgCanvas.Width,
  1390. CenterY = ImgCanvas.Height
  1391. };
  1392. BtnPrint.IsEnabled = true;
  1393. }
  1394. }
  1395. }
  1396. else if ("取消".Equals(text))
  1397. {
  1398. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1399. {
  1400. WindowState = WindowState.Normal;
  1401. }
  1402. }
  1403. }
  1404. /// <summary>
  1405. /// 导入-开始
  1406. /// </summary>
  1407. /// <returns>
  1408. /// </returns>
  1409. private object InvokeServering()
  1410. {
  1411. Dispatcher.Invoke
  1412. (
  1413. () =>
  1414. {
  1415. _result = _ofd.ShowDialog();
  1416. }
  1417. );
  1418. if (_result == System.Windows.Forms.DialogResult.OK)
  1419. {
  1420. if (_ofd.FileName != "")
  1421. {
  1422. List<string> imagelist = new List<string>()
  1423. {
  1424. "jpg",
  1425. "jpeg",
  1426. "png",
  1427. "bmp"
  1428. };
  1429. Dispatcher.Invoke
  1430. (
  1431. () =>
  1432. {
  1433. App.myloading.Show();
  1434. myblackboard.changepage(App.PageContextData.pagenum);
  1435. }
  1436. );
  1437. string filepath = _ofd.FileName;
  1438. string filesuff = filepath.Substring(filepath.LastIndexOf(".", StringComparison.Ordinal) + 1).ToLower();
  1439. if (_ofd.SafeFileName != null)
  1440. {
  1441. string path = _ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1442. string type = _ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1443. if (type.Contains("typezsygppt")) //ppt
  1444. {
  1445. try
  1446. {
  1447. #region PPT转PDF
  1448. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1449. path = pathTemp + path + ".pdf";
  1450. FileToolsCommon.CreateDirectory(pathTemp);
  1451. //PPT转PDF
  1452. Presentation ppt = new Presentation(filepath);
  1453. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1454. #endregion PPT转PDF
  1455. #region PDF转图片
  1456. // 图片绝对路径集合
  1457. List<string> images = new List<string>();
  1458. string directoryPath = pathTemp;
  1459. //定义Jpeg转换设备
  1460. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(path);
  1461. Directory.CreateDirectory(directoryPath);
  1462. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1463. var device = new Aspose.Pdf.Devices.JpegDevice(100);
  1464. //遍历每一页转为jpg
  1465. for (int i = 1; i <= pdfDoc.Pages.Count; i++)
  1466. {
  1467. long ii = Timestamp();
  1468. string filePathOutPut = Path.Combine
  1469. (
  1470. directoryPath,
  1471. string.Format
  1472. (
  1473. "{0}{1}.jpg",
  1474. ii,
  1475. i
  1476. )
  1477. );
  1478. images.Add(filePathOutPut);
  1479. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1480. try
  1481. {
  1482. device.Process(pdfDoc.Pages[i], fs);
  1483. fs.Close();
  1484. }
  1485. catch (Exception)
  1486. {
  1487. fs.Close();
  1488. File.Delete(filePathOutPut);
  1489. }
  1490. }
  1491. #endregion PDF转图片
  1492. Dispatcher.Invoke
  1493. (
  1494. () =>
  1495. {
  1496. string[] page = images.ToArray();
  1497. int num = 0;
  1498. int iStart = App.PageContextData.pagenum; //导入文档的开始下标
  1499. int iEnd = page.Length + App.PageContextData.pagenum; //导入文档的结束下标
  1500. for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1501. {
  1502. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1503. {
  1504. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1505. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1506. App.PageDrawList[i].PageNum = i + 1;
  1507. App.PageDrawList[i].ImgDocumentation = true;
  1508. App.PageDrawList[i].Type = "ppt";
  1509. }
  1510. else
  1511. {
  1512. Model_DrawData modelDrawData = new Model_DrawData
  1513. {
  1514. PageImagePath = page[i - App.PageContextData.pagenum],
  1515. PdfImagePath = page[i - App.PageContextData.pagenum],
  1516. PageNum = i + 1,
  1517. ImgDocumentation = true,
  1518. Type = "ppt"
  1519. };
  1520. if (App.PageDrawList != null)
  1521. {
  1522. App.PageDrawList.Add(modelDrawData);
  1523. }
  1524. }
  1525. BtnPrint.IsEnabled = true;
  1526. App.SaveDraw();
  1527. num++;
  1528. }
  1529. if (num > 0)
  1530. {
  1531. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1532. App.PageContextData.pagenum += num;
  1533. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1534. }
  1535. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1536. {
  1537. ImgCanvas.Source = null;
  1538. BtnScreenshot.IsEnabled = false;
  1539. ImgDocumentation.Source = null;
  1540. ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1541. ScroMain.ScrollToVerticalOffset(0);
  1542. for (int i = iStart; i < iEnd; i++)
  1543. {
  1544. App.PageDrawList[i].ImageLocation = new TranslateTransform
  1545. {
  1546. X = 0.1,
  1547. Y = 0.1
  1548. };
  1549. App.PageDrawList[i].IsImageLocation = true;
  1550. App.PageDrawList[i].ImageSizes = new ScaleTransform
  1551. {
  1552. CenterX = ImgCanvas.Width,
  1553. CenterY = ImgCanvas.Height
  1554. };
  1555. }
  1556. }
  1557. else
  1558. {
  1559. ImgDocumentation.Source = null;
  1560. ImgCanvas.Source = null;
  1561. ImgPpt.Source = null;
  1562. //截图可用
  1563. BtnScreenshot.IsEnabled = true;
  1564. }
  1565. }
  1566. );
  1567. }
  1568. catch (Exception ex)
  1569. {
  1570. Dispatcher.Invoke
  1571. (
  1572. () =>
  1573. {
  1574. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1575. }
  1576. );
  1577. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1578. }
  1579. }
  1580. else if (type.Contains("typepdf"))
  1581. {
  1582. try
  1583. {
  1584. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1585. #region PDF转图片
  1586. // 图片绝对路径集合
  1587. List<string> images = new List<string>();
  1588. string directoryPath = pathTemp;
  1589. //aspose许可证
  1590. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1591. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1592. //l.SetLicense(licenseName);
  1593. //定义Jpeg转换设备
  1594. Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(filepath);
  1595. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1596. //directoryPath += quality;
  1597. Directory.CreateDirectory(directoryPath);
  1598. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1599. var device = new Aspose.Pdf.Devices.JpegDevice(100);
  1600. //遍历每一页转为jpg
  1601. for (int i = 1; i <= pdfDoc.Pages.Count; i++)
  1602. {
  1603. long ii = Timestamp();
  1604. string filePathOutPut = Path.Combine
  1605. (
  1606. directoryPath,
  1607. string.Format
  1608. (
  1609. "{0}{1}.jpg",
  1610. ii,
  1611. i
  1612. )
  1613. );
  1614. images.Add(filePathOutPut);
  1615. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1616. try
  1617. {
  1618. device.Process(pdfDoc.Pages[i], fs);
  1619. fs.Close();
  1620. }
  1621. catch (Exception)
  1622. {
  1623. fs.Close();
  1624. File.Delete(filePathOutPut);
  1625. }
  1626. }
  1627. #endregion PDF转图片
  1628. string[] page = images.ToArray();
  1629. int num = 0;
  1630. Dispatcher.Invoke
  1631. (
  1632. () =>
  1633. {
  1634. for (int i = App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1635. {
  1636. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1637. {
  1638. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1639. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1640. App.PageDrawList[i].PageNum = i + 1;
  1641. App.PageDrawList[i].ImgDocumentation = true;
  1642. App.PageDrawList[i].Type = "word";
  1643. }
  1644. else
  1645. {
  1646. Model_DrawData modelDrawData = new Model_DrawData
  1647. {
  1648. PageImagePath = page[i - App.PageContextData.pagenum],
  1649. PdfImagePath = page[i - App.PageContextData.pagenum],
  1650. PageNum = i + 1,
  1651. ImgDocumentation = true,
  1652. Type = "word"
  1653. };
  1654. if (App.PageDrawList != null)
  1655. {
  1656. App.PageDrawList.Add(modelDrawData);
  1657. }
  1658. }
  1659. BtnPrint.IsEnabled = true;
  1660. App.SaveDraw();
  1661. num++;
  1662. }
  1663. if (num > 0)
  1664. {
  1665. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1666. App.PageContextData.pagenum += num;
  1667. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1668. }
  1669. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1670. {
  1671. ImgCanvas.Source = null;
  1672. ImgPpt.Source = null;
  1673. BtnScreenshot.IsEnabled = false;
  1674. ImgDocumentation.Visibility = Visibility.Visible;
  1675. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
  1676. ScroMain.ScrollToVerticalOffset(0);
  1677. }
  1678. else
  1679. {
  1680. ImgDocumentation.Source = null;
  1681. ImgCanvas.Source = null;
  1682. ImgPpt.Source = null;
  1683. //截图可用
  1684. BtnScreenshot.IsEnabled = true;
  1685. }
  1686. }
  1687. );
  1688. }
  1689. catch (Exception ex)
  1690. {
  1691. Dispatcher.Invoke
  1692. (
  1693. () =>
  1694. {
  1695. MessageWindow.Show(ex.Message);
  1696. }
  1697. );
  1698. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1699. }
  1700. }
  1701. else if (imagelist.Contains(filesuff)) //导入图片
  1702. {
  1703. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1704. if (!Directory.Exists(imagepath))
  1705. {
  1706. Directory.CreateDirectory(imagepath);
  1707. }
  1708. TimeSpan ts = DateTime.UtcNow
  1709. - new DateTime
  1710. (
  1711. 1970,
  1712. 1,
  1713. 1,
  1714. 0,
  1715. 0,
  1716. 0,
  1717. 0
  1718. );
  1719. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1720. string filepathCopy = Path.Combine(imagepath, timestr + _ofd.SafeFileName);
  1721. File.Copy(filepath, filepathCopy);
  1722. filepath = filepathCopy;
  1723. App.ImgPath = filepath;
  1724. Dispatcher.Invoke
  1725. (
  1726. () =>
  1727. {
  1728. if (App.PageContextData.currpage == 0)
  1729. {
  1730. App.PageContextData.pagenum += 1;
  1731. App.PageContextData.currpage = App.PageContextData.pagenum;
  1732. myblackboard.changepage(App.PageContextData.currpage - 1);
  1733. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1734. #region 插入页码
  1735. #endregion 插入页码
  1736. }
  1737. else
  1738. {
  1739. App.PageContextData.pagenum += 1;
  1740. App.PageContextData.currpage = App.PageContextData.pagenum;
  1741. myblackboard.changepage(App.PageContextData.currpage - 1);
  1742. }
  1743. if (App.PageDrawList.Count >= App.PageContextData.currpage)
  1744. {
  1745. App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
  1746. App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
  1747. }
  1748. else
  1749. {
  1750. Model_DrawData modelDrawData = new Model_DrawData
  1751. {
  1752. PageImagePath = App.ImgPath,
  1753. PdfImagePath = App.ImgPath
  1754. };
  1755. App.PageDrawList.Add(modelDrawData);
  1756. }
  1757. if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  1758. {
  1759. ImgDocumentation.Source = null;
  1760. BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  1761. _mouseDown = false;
  1762. _imageOperationUtil.setMouseDown(_mouseDown);
  1763. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
  1764. {
  1765. X = 0.1,
  1766. Y = 0.1
  1767. };
  1768. App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
  1769. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  1770. ImgCanvas.Source = bitImg;
  1771. ImgCanvas.Width = bitImg.Width;
  1772. ImgCanvas.Height = bitImg.Height;
  1773. ScroMain.ScrollToVerticalOffset(0);
  1774. ImgCanvas.Margin = new Thickness
  1775. (
  1776. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
  1777. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
  1778. 0,
  1779. 0
  1780. );
  1781. App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
  1782. {
  1783. CenterX = ImgCanvas.Width,
  1784. CenterY = ImgCanvas.Height
  1785. };
  1786. BtnPrint.IsEnabled = true;
  1787. }
  1788. }
  1789. );
  1790. }
  1791. else //word
  1792. {
  1793. try
  1794. {
  1795. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1796. _wordImgNum += 1;
  1797. string[] page = ZAsposeUtil.ConvertWordToImage
  1798. (
  1799. filepath,
  1800. paths,
  1801. "" + _wordImgNum
  1802. )
  1803. .ToArray();
  1804. int num = 0;
  1805. Dispatcher.Invoke
  1806. (
  1807. () =>
  1808. {
  1809. for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
  1810. {
  1811. if (App.PageDrawList != null && App.PageDrawList.Count > i)
  1812. {
  1813. App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
  1814. App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
  1815. App.PageDrawList[i].PageNum = i + 1;
  1816. App.PageDrawList[i].ImgDocumentation = true;
  1817. App.PageDrawList[i].Type = "word";
  1818. }
  1819. else
  1820. {
  1821. Model_DrawData modelDrawData = new Model_DrawData
  1822. {
  1823. PageImagePath = page[i - App.PageContextData.pagenum],
  1824. PdfImagePath = page[i - App.PageContextData.pagenum],
  1825. PageNum = i + 1,
  1826. ImgDocumentation = true,
  1827. Type = "word"
  1828. };
  1829. if (App.PageDrawList != null)
  1830. {
  1831. App.PageDrawList.Add(modelDrawData);
  1832. }
  1833. }
  1834. BtnPrint.IsEnabled = true;
  1835. App.SaveDraw();
  1836. num++;
  1837. }
  1838. if (num > 0)
  1839. {
  1840. App.PageContextData.currpage = App.PageContextData.pagenum + 1;
  1841. App.PageContextData.pagenum += num;
  1842. GridPage.Visibility = Visibility.Visible; //页码大于0 显示
  1843. }
  1844. if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
  1845. {
  1846. ImgCanvas.Source = null;
  1847. ImgPpt.Source = null;
  1848. BtnScreenshot.IsEnabled = false;
  1849. ImgDocumentation.Visibility = Visibility.Visible;
  1850. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
  1851. ScroMain.ScrollToVerticalOffset(0);
  1852. }
  1853. else
  1854. {
  1855. ImgDocumentation.Source = null;
  1856. ImgCanvas.Source = null;
  1857. ImgPpt.Source = null;
  1858. //截图可用
  1859. BtnScreenshot.IsEnabled = true;
  1860. }
  1861. }
  1862. );
  1863. }
  1864. catch (Exception ex)
  1865. {
  1866. Dispatcher.Invoke
  1867. (
  1868. () =>
  1869. {
  1870. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1871. }
  1872. );
  1873. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1874. }
  1875. }
  1876. }
  1877. #region 插入页码
  1878. #endregion 插入页码
  1879. }
  1880. }
  1881. //OpenDialog();
  1882. return "";
  1883. }
  1884. /// <summary>
  1885. /// 截图关闭 非正常关闭截图时,截图清空
  1886. /// </summary>
  1887. private void JietuWindow_click_closeJietuWindowClick()
  1888. {
  1889. if (WindowState == WindowState.Minimized) //截图完恢复窗口
  1890. {
  1891. WindowState = WindowState.Normal;
  1892. }
  1893. App.W_JieTuWindow = null;
  1894. }
  1895. #region 导入转换图片
  1896. #endregion 导入转换图片
  1897. #endregion 导入截图
  1898. #region 上传 列表
  1899. /// <summary>
  1900. /// 搜索集合匹配的索引
  1901. /// </summary>
  1902. /// <typeparam name="T">
  1903. /// </typeparam>
  1904. /// <param name="parent">
  1905. /// </param>
  1906. /// <param name="childName">
  1907. /// </param>
  1908. /// <returns>
  1909. /// </returns>
  1910. public static List<T> FindChilds<T>(DependencyObject parent, string childName) where T : DependencyObject
  1911. {
  1912. List<T> list = new List<T>();
  1913. if (parent == null)
  1914. {
  1915. return list;
  1916. }
  1917. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  1918. for (int i = 0; i < childrenCount; i++)
  1919. {
  1920. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  1921. // 如果子控件不是需查找的控件类型
  1922. T childType = child as T;
  1923. if (childType == null)
  1924. {
  1925. // 在下一级控件中递归查找
  1926. FindChilds<T>(child, childName);
  1927. list.AddRange(FindChilds<T>(child, childName));
  1928. }
  1929. else if (!string.IsNullOrEmpty(childName))
  1930. {
  1931. FrameworkElement frameworkElement = child as FrameworkElement;
  1932. // 如果控件名称符合参数条件
  1933. if (frameworkElement != null && frameworkElement.Name == childName)
  1934. {
  1935. list.Add((T)child);
  1936. }
  1937. }
  1938. else
  1939. {
  1940. // 查找到了控件
  1941. list.Add((T)child);
  1942. }
  1943. }
  1944. return list;
  1945. }
  1946. /// <summary>
  1947. /// 加载视频列表
  1948. /// </summary>
  1949. public void LoadingVideoList()
  1950. {
  1951. try
  1952. {
  1953. _modelVideoList = new List<Model_Video>();
  1954. foreach (Model_WKData vdata in App.WKDataList)
  1955. {
  1956. #region 计时器初始化
  1957. if (vdata.VideoList == null)
  1958. {
  1959. continue;
  1960. }
  1961. foreach (Model_Video videoinfo in vdata.VideoList)
  1962. {
  1963. try
  1964. {
  1965. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  1966. {
  1967. continue;
  1968. }
  1969. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  1970. {
  1971. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString(CultureInfo.InvariantCulture) + " MB";
  1972. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  1973. }
  1974. _modelVideoList.Add(videoinfo);
  1975. }
  1976. catch (Exception ex)
  1977. {
  1978. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1979. }
  1980. }
  1981. #endregion 计时器初始化
  1982. }
  1983. //翻转
  1984. if (_modelVideoList.Count > 1)
  1985. {
  1986. _modelVideoList.Reverse();
  1987. }
  1988. }
  1989. catch (Exception ex)
  1990. {
  1991. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1992. }
  1993. }
  1994. /// <summary>
  1995. /// 上传事件
  1996. /// </summary>
  1997. /// <param name="sender">
  1998. /// </param>
  1999. /// <param name="e">
  2000. /// </param>
  2001. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  2002. {
  2003. if (GridMyVideo.Visibility == Visibility.Visible)
  2004. {
  2005. GridMyVideo.Visibility = Visibility.Collapsed;
  2006. GridMain.Visibility = Visibility.Visible;
  2007. GridM.IsEnabled = true;
  2008. GridRecordingTitle.Visibility = Visibility.Visible;
  2009. }
  2010. else
  2011. {
  2012. PageHide();
  2013. GridMyVideo.Visibility = Visibility.Visible;
  2014. LoadUploadInitData();
  2015. }
  2016. }
  2017. #endregion 上传 列表
  2018. #region 新上传 显示缩略图
  2019. #region 初始值
  2020. private readonly double _controlHeight = 260;
  2021. private readonly double _controlWidth = 250;
  2022. /// <summary>
  2023. /// 当前页
  2024. /// </summary>
  2025. private int _currentPage = 1;
  2026. /// <summary>
  2027. /// 横向间隔
  2028. /// </summary>
  2029. private double _intervalX;
  2030. /// <summary>
  2031. /// 纵向间隔
  2032. /// </summary>
  2033. private double _intervalY;
  2034. /// <summary>
  2035. /// 页面高
  2036. /// </summary>
  2037. private double _pageH;
  2038. /// <summary>
  2039. /// 每页显示的视频数
  2040. /// </summary>
  2041. private int _pageShowNum;
  2042. /// <summary>
  2043. /// 页面宽
  2044. /// </summary>
  2045. private double _pageW;
  2046. /// <summary>
  2047. /// 总页数
  2048. /// </summary>
  2049. private int _totalPage;
  2050. /// <summary>
  2051. /// 视频信息列表
  2052. /// </summary>
  2053. private readonly List<Uc_VideoItem> _videoControlList = new List<Uc_VideoItem>();
  2054. #endregion 初始值
  2055. /// <summary>
  2056. /// 加载当前页数据
  2057. /// </summary>
  2058. private void LoadCurrentPageData()
  2059. {
  2060. LblVideoPageNum.Content = _currentPage + "/" + _totalPage;
  2061. //隐藏显示的控件
  2062. if (_videoControlList.Count > 0)
  2063. {
  2064. foreach (Uc_VideoItem item in _videoControlList)
  2065. {
  2066. if (item.Visibility != Visibility.Hidden)
  2067. {
  2068. item.Visibility = Visibility.Hidden;
  2069. }
  2070. }
  2071. }
  2072. double w = _intervalX; //每次增加250
  2073. double h = _intervalY; //每次增加260
  2074. //加载控件
  2075. for (int i = 0; i < _pageShowNum; i++)
  2076. {
  2077. int dataIndex = (_currentPage - 1) * _pageShowNum + i;
  2078. if (dataIndex == _modelVideoList.Count)
  2079. {
  2080. return;
  2081. }
  2082. Uc_VideoItem videoItem;
  2083. if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
  2084. {
  2085. videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
  2086. }
  2087. else
  2088. {
  2089. if (!FileToolsCommon.IsExistFile(_modelVideoList[dataIndex].ThumbnailPath))
  2090. {
  2091. continue;
  2092. }
  2093. videoItem = new Uc_VideoItem(_modelVideoList[dataIndex]) { Tag = _modelVideoList[dataIndex].FileGuid };
  2094. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2095. videoItem.Click_UploadLogin += Login;
  2096. videoItem.Width = _controlWidth;
  2097. videoItem.Height = _controlHeight;
  2098. videoItem.HorizontalAlignment = HorizontalAlignment.Left;
  2099. videoItem.VerticalAlignment = VerticalAlignment.Top;
  2100. GridMyVideo.Children.Add(videoItem);
  2101. _videoControlList.Add(videoItem);
  2102. }
  2103. videoItem.Margin = new Thickness
  2104. (
  2105. w,
  2106. h,
  2107. 0,
  2108. 0
  2109. );
  2110. videoItem.Visibility = Visibility.Visible;
  2111. if (w + _controlWidth + _controlWidth > _pageW)
  2112. {
  2113. w = _intervalX;
  2114. h += _controlHeight + _intervalY;
  2115. }
  2116. else
  2117. {
  2118. w += _controlWidth + _intervalX;
  2119. }
  2120. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2121. //return;
  2122. }
  2123. }
  2124. /// <summary>
  2125. /// 初始化加载上传页面数据
  2126. /// </summary>
  2127. private void LoadUploadInitData()
  2128. {
  2129. App.myloading.Show();
  2130. //加载视频列表
  2131. LoadingVideoList();
  2132. if (_modelVideoList.Count > 0)
  2133. {
  2134. LblVideoMess.Visibility = Visibility.Hidden;
  2135. BtnVideoUpPage.Visibility = Visibility.Visible;
  2136. LblVideoPageNum.Visibility = Visibility.Visible;
  2137. BtnVideoDownPage.Visibility = Visibility.Visible;
  2138. if (GridMyVideo.ActualHeight > 0)
  2139. {
  2140. _pageW = GridMyVideo.ActualWidth;
  2141. _pageH = GridMyVideo.ActualHeight;
  2142. }
  2143. else
  2144. {
  2145. _pageW = GridRecordingArea.ActualWidth;
  2146. _pageH = GridRecordingArea.ActualHeight;
  2147. }
  2148. //获取设置控件大小 新增 页面原始1061 911
  2149. //ControlWidth = 250.00 * PropWid;
  2150. //ControlHeight = 260.00 * PropHei;
  2151. //ControlWidth=
  2152. //ControlHeight=
  2153. //根据页面大小获取每页显示的数量 H260W250
  2154. int videoRow = (int)((_pageH - 50) / _controlHeight);
  2155. int videColumn = (int)(_pageW / _controlWidth);
  2156. //横向间隔
  2157. _intervalX = (_pageW - (videColumn * _controlWidth)) / (videColumn + 1);
  2158. _intervalY = (_pageH - 50 - (videoRow * _controlHeight)) / (videoRow + 1);
  2159. _pageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2160. //获取总页数
  2161. _totalPage = _modelVideoList.Count / _pageShowNum + (_modelVideoList.Count % _pageShowNum > 0 ? 1 : 0);
  2162. //如果当前页大于总页数 总页数为当前页
  2163. if (_totalPage < _currentPage)
  2164. {
  2165. _currentPage = _totalPage;
  2166. }
  2167. LoadCurrentPageData();
  2168. }
  2169. else
  2170. {
  2171. LblVideoMess.Visibility = Visibility.Visible;
  2172. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2173. LblVideoPageNum.Visibility = Visibility.Hidden;
  2174. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2175. //隐藏显示的控件
  2176. if (_videoControlList.Count > 0)
  2177. {
  2178. foreach (Uc_VideoItem item in _videoControlList)
  2179. {
  2180. if (item.Visibility != Visibility.Hidden)
  2181. {
  2182. item.Visibility = Visibility.Hidden;
  2183. }
  2184. }
  2185. }
  2186. }
  2187. App.myloading.Hide();
  2188. }
  2189. #region 分页
  2190. /// <summary>
  2191. /// 下一页
  2192. /// </summary>
  2193. /// <param name="sender">
  2194. /// </param>
  2195. /// <param name="e">
  2196. /// </param>
  2197. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2198. {
  2199. if (_currentPage < _totalPage)
  2200. {
  2201. _currentPage++;
  2202. LoadCurrentPageData();
  2203. }
  2204. }
  2205. /// <summary>
  2206. /// 上一页
  2207. /// </summary>
  2208. /// <param name="sender">
  2209. /// </param>
  2210. /// <param name="e">
  2211. /// </param>
  2212. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2213. {
  2214. if (_currentPage > 1)
  2215. {
  2216. _currentPage--;
  2217. LoadCurrentPageData();
  2218. }
  2219. }
  2220. #endregion 分页
  2221. #endregion 新上传 显示缩略图
  2222. #region 录屏
  2223. /// <summary>
  2224. /// 录屏事件
  2225. /// </summary>
  2226. /// <param name="sender">
  2227. /// </param>
  2228. /// <param name="e">
  2229. /// </param>
  2230. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2231. {
  2232. _luoBoPenUtil.lb_device_mouse();
  2233. if (!_microphoneGood)
  2234. {
  2235. MessageWindow.Show("麦克风不可用");
  2236. return;
  2237. }
  2238. if (!_loudspeakerGood)
  2239. {
  2240. MessageWindow.Show("扬声器不可用");
  2241. return;
  2242. }
  2243. PrepareRecord();
  2244. _kHook.Stop();
  2245. if (App.W_ScreenRecordingToolbarWindow == null)
  2246. {
  2247. App.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow { Topmost = true };
  2248. App.W_ScreenRecordingToolbarWindow.Initialize();
  2249. }
  2250. else
  2251. {
  2252. App.W_ScreenRecordingToolbarWindow.Initialize();
  2253. }
  2254. App.W_ScreenRecordingToolbarWindow.ClickStopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2255. //显示在右下角
  2256. App.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2257. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2258. float dip = graphics.DpiX;
  2259. App.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Width;
  2260. App.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Height - 100;
  2261. App.W_ScreenRecordingToolbarWindow.Topmost = true;
  2262. App.W_ScreenRecordingToolbarWindow.Show();
  2263. Hide();
  2264. }
  2265. /// <summary>
  2266. /// 保存录屏中
  2267. /// </summary>
  2268. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2269. {
  2270. TxbTime.Text = "00:00";
  2271. TxbType.Text = "保存中";
  2272. _recordType = 4;
  2273. RecordBtnStatus();
  2274. new Thread
  2275. (
  2276. () =>
  2277. {
  2278. while (FileToolsCommon.IsExistDirectory(App.WKData.WkPath + "_temppath/"))
  2279. {
  2280. Thread.Sleep(100);
  2281. }
  2282. Thread.Sleep(100);
  2283. Dispatcher.Invoke
  2284. (
  2285. () =>
  2286. {
  2287. _recordType = 0;
  2288. RecordBtnStatus();
  2289. }
  2290. );
  2291. }
  2292. ).Start();
  2293. }
  2294. #endregion 录屏
  2295. #region 录制窗口
  2296. #region 变量
  2297. /// <summary>
  2298. /// 录制大小
  2299. /// </summary>
  2300. private int _gridActHeight = 898;
  2301. /// <summary>
  2302. /// 录制大小
  2303. /// </summary>
  2304. private int _gridActWidth = 1276;
  2305. /// <summary>
  2306. /// 录制类型 0停止,1录制中,2暂停中 3倒计时 4合并中
  2307. /// </summary>
  2308. private int _recordType;
  2309. /// <summary>
  2310. /// 录制计时
  2311. /// </summary>
  2312. private DateTime _srTime = DateTime.Now;
  2313. /// <summary>
  2314. /// 音频保存路径名
  2315. /// </summary>
  2316. private string _tempAudioPathName;
  2317. /// <summary>
  2318. /// 视频合成前路径名
  2319. /// </summary>
  2320. private string _tempVideoPathName;
  2321. /// <summary>
  2322. /// 截图定时器
  2323. /// </summary>
  2324. private Timer _timer;
  2325. /// <summary>
  2326. /// 视频保存路径名
  2327. /// </summary>
  2328. private string _videoSavePathName;
  2329. #endregion 变量
  2330. private bool _isPressButton;
  2331. //视频写入
  2332. private readonly VideoFileWriter _videoWriter = new VideoFileWriter();
  2333. //录制麦克风的声音
  2334. private WaveInEvent _waveIn;
  2335. private bool _waveInRuning;
  2336. //音频写入
  2337. private WaveFileWriter _writer;
  2338. /// <summary>
  2339. /// 录制窗口内容
  2340. /// </summary>
  2341. /// <param name="sender">
  2342. /// </param>
  2343. /// <param name="e">
  2344. /// </param>
  2345. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2346. {
  2347. RecordAction();
  2348. }
  2349. private async void RecordAction()
  2350. {
  2351. #region 防止连击
  2352. if (_isPressButton)
  2353. {
  2354. return;
  2355. }
  2356. _isPressButton = true;
  2357. new Thread
  2358. (
  2359. () =>
  2360. {
  2361. Thread.Sleep(500);
  2362. _isPressButton = false;
  2363. }
  2364. ).Start();
  2365. #endregion 防止连击
  2366. if (_recordType == 4)
  2367. {
  2368. return;
  2369. }
  2370. if (_recordType != 0)
  2371. {
  2372. if (_recordType == 1)
  2373. {
  2374. //录制中暂停
  2375. _recordType = 2;
  2376. RecordBtnStatus();
  2377. }
  2378. else if (_recordType == 2)
  2379. {
  2380. //暂停中继续录制
  2381. _recordType = 1;
  2382. RecordBtnStatus();
  2383. }
  2384. }
  2385. else
  2386. {
  2387. if (App.PageContextData.currpage == 0)
  2388. {
  2389. MessageWindow.Show("请先导入文档或截图!");
  2390. return;
  2391. }
  2392. StartPauseGrid.Visibility = Visibility.Hidden;
  2393. StopGrid.Visibility = Visibility.Hidden;
  2394. CloseGrid.Visibility = Visibility.Hidden;
  2395. if (!_microphoneGood)
  2396. {
  2397. StartPauseGrid.Visibility = Visibility.Visible;
  2398. StopGrid.Visibility = Visibility.Visible;
  2399. CloseGrid.Visibility = Visibility.Visible;
  2400. MessageWindow.Show("麦克风不可用");
  2401. return;
  2402. }
  2403. BlackboardCanvas.Visibility = Visibility.Visible;
  2404. if (RectImgBorder.Visibility != Visibility.Hidden)
  2405. {
  2406. HideAngleBorder();
  2407. }
  2408. PrepareRecord();
  2409. BtnPrint.IsEnabled = false;
  2410. BtnScreenshot.IsEnabled = false;
  2411. BtnImport.IsEnabled = false;
  2412. BtnScreenRecording.IsEnabled = false;
  2413. BtnUpload.IsEnabled = false;
  2414. BtnSetUp.IsEnabled = false;
  2415. BtnDevice.IsEnabled = false;
  2416. BtnLoginType.IsEnabled = false;
  2417. BlackboardCanvas.Visibility = Visibility.Visible;
  2418. TxbType.Text = "准备录制";
  2419. BtnRecord.Visibility = Visibility.Collapsed;
  2420. BtnRecordSuspend.Visibility = Visibility.Visible;
  2421. BtnRecord.IsEnabled = true;
  2422. BtnStop.IsEnabled = true;
  2423. #region 录像倒计时
  2424. if (App.W_CountdownWindow == null)
  2425. {
  2426. App.W_CountdownWindow = new CountdownWindow();
  2427. }
  2428. App.W_CountdownWindow.InitAndShow();
  2429. #endregion 录像倒计时
  2430. await Task.Delay(3000);
  2431. //停止中开始录制
  2432. CloseGrid.Visibility = Visibility.Visible;
  2433. _recordType = 1;
  2434. RecordBtnStatus();
  2435. await StartRecord();
  2436. StartPauseGrid.Visibility = Visibility.Visible;
  2437. StopGrid.Visibility = Visibility.Visible;
  2438. }
  2439. RecordBtnStatus();
  2440. }
  2441. private void RecordBtnStatus()
  2442. {
  2443. if (_recordType == 0)
  2444. {
  2445. StartPauseGrid.Visibility = Visibility.Visible;
  2446. TxbType.Text = "准备录制";
  2447. BtnRecord.Visibility = Visibility.Visible;
  2448. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2449. BtnScreenRecording.IsEnabled = true;
  2450. BtnRecord.IsEnabled = true;
  2451. BtnStop.IsEnabled = false;
  2452. }
  2453. else if (_recordType == 1)
  2454. {
  2455. StartPauseGrid.Visibility = Visibility.Visible;
  2456. TxbType.Text = "录制中";
  2457. BtnRecord.Visibility = Visibility.Collapsed;
  2458. BtnRecordSuspend.Visibility = Visibility.Visible;
  2459. }
  2460. else if (_recordType == 2)
  2461. {
  2462. StartPauseGrid.Visibility = Visibility.Visible;
  2463. TxbType.Text = "暂停中";
  2464. BtnRecord.Visibility = Visibility.Visible;
  2465. BtnRecordSuspend.Visibility = Visibility.Collapsed;
  2466. }
  2467. else if (_recordType == 3)
  2468. {
  2469. TxbType.Text = "倒计时";
  2470. }
  2471. else if (_recordType == 4)
  2472. {
  2473. TxbType.Text = "合并中";
  2474. StartPauseGrid.Visibility = Visibility.Hidden;
  2475. BtnScreenRecording.IsEnabled = false;
  2476. }
  2477. }
  2478. /// <summary>
  2479. /// 停止录制窗口内容
  2480. /// </summary>
  2481. /// <param name="sender">
  2482. /// </param>
  2483. /// <param name="e">
  2484. /// </param>
  2485. private async void BtnStop_Click(object sender, RoutedEventArgs e)
  2486. {
  2487. #region 防止连击
  2488. if (_isPressButton)
  2489. {
  2490. return;
  2491. }
  2492. else
  2493. {
  2494. _isPressButton = true;
  2495. new Thread
  2496. (
  2497. () =>
  2498. {
  2499. Thread.Sleep(500);
  2500. _isPressButton = false;
  2501. }
  2502. ).Start();
  2503. }
  2504. #endregion 防止连击
  2505. if (_recordType != 0)
  2506. {
  2507. _recordType = 4;
  2508. BlackboardCanvas.Visibility = Visibility.Collapsed;
  2509. RecordBtnStatus();
  2510. //鼠标模式
  2511. _luoBoPenUtil.lb_device_mouse();
  2512. await EndRecord();
  2513. _recordType = 0;
  2514. RecordBtnStatus();
  2515. }
  2516. }
  2517. /// <summary>
  2518. /// 停止录制并生成录制文件
  2519. /// </summary>
  2520. private async Task EndRecord()
  2521. {
  2522. #region 恢复被禁用的按钮
  2523. BtnScreenshot.IsEnabled = true;
  2524. BtnImport.IsEnabled = true;
  2525. BtnScreenRecording.IsEnabled = true;
  2526. BtnUpload.IsEnabled = true;
  2527. BtnSetUp.IsEnabled = true;
  2528. BtnDevice.IsEnabled = true;
  2529. BtnLoginType.IsEnabled = true;
  2530. #endregion 恢复被禁用的按钮
  2531. App.PageContextData.currpage = 0;
  2532. App.PageContextData.pagenum = 0;
  2533. myblackboard.clear();
  2534. App.PageDrawList.Clear();
  2535. ImgCanvas.Source = null;
  2536. ImgDocumentation.Source = null;
  2537. ImgPpt.Source = null;
  2538. GridPage.Visibility = Visibility.Collapsed;
  2539. BtnRecord.IsEnabled = false;
  2540. BtnStop.IsEnabled = false;
  2541. BtnScreenRecording.IsEnabled = false;
  2542. _timer.Change(-1, 0);
  2543. _timer.Dispose();
  2544. TxbTime.Text = "00:00";
  2545. TxbType.Text = "保存中";
  2546. _recordType = 4;
  2547. RecordBtnStatus();
  2548. await Task.Run
  2549. (
  2550. () =>
  2551. {
  2552. try
  2553. {
  2554. _videoWriter.Close();
  2555. _waveIn.StopRecording();
  2556. //等待音频结束回调
  2557. while (_waveInRuning)
  2558. {
  2559. Thread.Sleep(300);
  2560. }
  2561. Process[] killProcessArray = Process.GetProcessesByName("ffmpeg");
  2562. foreach (Process killProcess in killProcessArray)
  2563. {
  2564. killProcess.Kill();
  2565. }
  2566. FFMpegConverter ffMpeg = new FFMpegConverter();
  2567. FFMpegInput[] input = new FFMpegInput[]
  2568. {
  2569. new FFMpegInput(_tempVideoPathName),
  2570. new FFMpegInput(_tempAudioPathName)
  2571. };
  2572. // 音视频合并
  2573. ffMpeg.ConvertMedia
  2574. (
  2575. input,
  2576. _videoSavePathName,
  2577. "mp4",
  2578. new OutputSettings()
  2579. );
  2580. //生成缩略图
  2581. string thumbnailPath = FileToolsCommon.GetDirectoryName(_videoSavePathName) + "ThumbnailPath/";
  2582. FileToolsCommon.CreateDirectory(thumbnailPath);
  2583. //缩略图存储位置
  2584. string thumbnailPathName = thumbnailPath + FileToolsCommon.GetIOFileName(_videoSavePathName).Replace(".", "") + ".JPG";
  2585. FileToolsCommon.DeleteFile(thumbnailPathName);
  2586. _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  2587. _videoInfo.VideoPath = _videoSavePathName;
  2588. _videoInfo.ThumbnailPath = thumbnailPathName;
  2589. _videoInfo.FileGuid = Guid.NewGuid().ToString();
  2590. _videoInfo.IsUpload = false;
  2591. _videoInfo.Uploaded = 0;
  2592. try
  2593. {
  2594. App.FFmpeg.GenerateThumbnails
  2595. (
  2596. _tempVideoPathName,
  2597. thumbnailPathName,
  2598. 200,
  2599. 130
  2600. );
  2601. }
  2602. catch (Exception ex)
  2603. {
  2604. LogHelper.WriteErrLog("录制生成缩略图", ex);
  2605. }
  2606. if (!App.VideoList.Exists(x => x.FileGuid == _videoInfo.FileGuid) || !App.VideoList.Exists(x => x.VideoPath == _videoInfo.VideoPath))
  2607. {
  2608. App.VideoList.Add(_videoInfo);
  2609. //保存数据
  2610. App.SaveWkData();
  2611. }
  2612. try
  2613. {
  2614. FileToolsCommon.DeleteFile(_tempVideoPathName);
  2615. FileToolsCommon.DeleteFile(_tempAudioPathName);
  2616. }
  2617. catch (Exception ex)
  2618. {
  2619. LogHelper.WriteErrLog("删除录制临时文件", ex);
  2620. }
  2621. }
  2622. catch (Exception ex)
  2623. {
  2624. Dispatcher.Invoke
  2625. (
  2626. () =>
  2627. {
  2628. MessageWindow.Show(ex.Message);
  2629. }
  2630. );
  2631. }
  2632. }
  2633. );
  2634. BtnRecord.IsEnabled = true;
  2635. BtnStop.IsEnabled = false;
  2636. BtnPrint.IsEnabled = false;
  2637. BtnScreenRecording.IsEnabled = true;
  2638. TxbType.Text = "准备就绪";
  2639. _recordType = 0;
  2640. RecordBtnStatus();
  2641. }
  2642. /// <summary>
  2643. /// 录制保存图片
  2644. /// </summary>
  2645. private void RecordSaveImage()
  2646. {
  2647. try
  2648. {
  2649. //保存图片
  2650. try
  2651. {
  2652. Dispatcher.Invoke
  2653. (
  2654. () =>
  2655. {
  2656. Bitmap bm = ImageHelper.SaveUI2Bitmap
  2657. (
  2658. GridMain,
  2659. _gridActWidth,
  2660. _gridActHeight
  2661. );
  2662. _videoWriter.WriteVideoFrame(bm);
  2663. bm.Dispose();
  2664. }
  2665. );
  2666. }
  2667. catch (Exception e)
  2668. {
  2669. Console.WriteLine(e.Message);
  2670. }
  2671. }
  2672. catch (Exception ex)
  2673. {
  2674. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  2675. }
  2676. }
  2677. //new WaveInEvent();
  2678. /// <summary>
  2679. /// 开始录制和暂停录制
  2680. /// </summary>
  2681. private async Task StartRecord()
  2682. {
  2683. await Task.Run
  2684. (
  2685. () =>
  2686. {
  2687. //电子版切换笔模式
  2688. _luoBoPenUtil.lb_device_hand();
  2689. _videoInfo = new Model_Video
  2690. {
  2691. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2692. WkType = Enum_WKVidetype.RecordingLessons
  2693. };
  2694. FileToolsCommon.DeleteDirectory(App.WKData.WkPath + "temp/");
  2695. FileToolsCommon.CreateDirectory(App.WKData.WkPath);
  2696. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制." + _videoInfo.VideoType.ToString();
  2697. _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn.avi";
  2698. int num = 1;
  2699. while (FileToolsCommon.IsExistFile(_videoSavePathName))
  2700. {
  2701. _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制_" + num + "." + _videoInfo.VideoType.ToString();
  2702. _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn_" + num + ".avi";
  2703. num++;
  2704. }
  2705. _tempAudioPathName = _tempVideoPathName.Replace(".avi", ".mp3");
  2706. _gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
  2707. _gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
  2708. lock (this)
  2709. {
  2710. _videoWriter.Open
  2711. (
  2712. _tempVideoPathName,
  2713. _gridActWidth,
  2714. _gridActHeight,
  2715. 5,
  2716. VideoCodec.MPEG4,
  2717. _gridActWidth * _gridActHeight * 10
  2718. );
  2719. _waveIn = new WaveInEvent();
  2720. _waveInRuning = true;
  2721. _writer = new WaveFileWriter(_tempAudioPathName, _waveIn.WaveFormat);
  2722. //开始录音,写数据
  2723. _waveIn.DataAvailable += (s, a) =>
  2724. {
  2725. if (_recordType == 1)
  2726. {
  2727. _writer.Write
  2728. (
  2729. a.Buffer,
  2730. 0,
  2731. a.BytesRecorded
  2732. );
  2733. }
  2734. };
  2735. //结束录音
  2736. _waveIn.RecordingStopped += (s, a) =>
  2737. {
  2738. _writer.Dispose();
  2739. _writer = null;
  2740. _waveIn.Dispose();
  2741. _waveInRuning = false;
  2742. };
  2743. _waveIn.StartRecording();
  2744. }
  2745. }
  2746. );
  2747. _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2748. //启动截图
  2749. _timer = new Timer
  2750. (
  2751. Timer_Elapsed,
  2752. null,
  2753. 0,
  2754. 200
  2755. );
  2756. }
  2757. /// <summary>
  2758. /// 录制保存图片计时器
  2759. /// </summary>
  2760. /// <param name="sender">
  2761. /// </param>
  2762. private void Timer_Elapsed(object sender)
  2763. {
  2764. if (_recordType == 1)
  2765. {
  2766. Dispatcher.Invoke
  2767. (
  2768. () =>
  2769. {
  2770. _srTime = _srTime.AddMilliseconds(200);
  2771. if (_srTime.Hour > 0)
  2772. {
  2773. TxbTime.Text = _srTime.ToString("HH:mm:ss");
  2774. }
  2775. else
  2776. {
  2777. TxbTime.Text = _srTime.ToString("mm:ss");
  2778. }
  2779. }
  2780. );
  2781. ThreadPool.QueueUserWorkItem
  2782. (
  2783. o =>
  2784. {
  2785. RecordSaveImage();
  2786. }
  2787. );
  2788. }
  2789. }
  2790. #endregion 录制窗口
  2791. #region 分页
  2792. private void ImgXy()
  2793. {
  2794. ImgCanvas.Width = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterX;
  2795. ImgCanvas.Height = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterY;
  2796. ImgCanvas.Margin = new Thickness
  2797. (
  2798. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
  2799. App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
  2800. 0,
  2801. 0
  2802. );
  2803. }
  2804. /// <summary>
  2805. /// 跳转
  2806. /// </summary>
  2807. private void JumpPageClick()
  2808. {
  2809. myblackboard.changepage(App.PageContextData.currpage - 1);
  2810. ScroMain.ScrollToVerticalOffset(0);
  2811. if (BtnImport.IsEnabled)
  2812. {
  2813. //截图可用
  2814. BtnScreenshot.IsEnabled = true;
  2815. }
  2816. if (App.PageContextData.currpage <= App.PageDrawList.Count)
  2817. {
  2818. if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null)
  2819. {
  2820. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = true;
  2821. }
  2822. if (!string.IsNullOrWhiteSpace(TxbCurrpage.Text) && App.PageContextData.currpage <= App.PageDrawList.Count && App.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
  2823. {
  2824. if (App.PageDrawList[App.PageContextData.currpage - 1].ImgDocumentation)
  2825. {
  2826. if ("ppt".Equals(App.PageDrawList[App.PageContextData.currpage - 1].Type))
  2827. {
  2828. ImgCanvas.Source = null;
  2829. ImgDocumentation.Source = null;
  2830. ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2831. BtnScreenshot.IsEnabled = false;
  2832. }
  2833. else
  2834. {
  2835. ImgPpt.Source = null;
  2836. ImgCanvas.Source = null;
  2837. ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2838. BtnScreenshot.IsEnabled = false;
  2839. }
  2840. }
  2841. else
  2842. {
  2843. ImgPpt.Source = null;
  2844. ImgDocumentation.Source = null;
  2845. ImgCanvas.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
  2846. App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
  2847. if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null && App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X > 0)
  2848. {
  2849. _mouseDown = false;
  2850. _imageOperationUtil.setMouseDown(_mouseDown);
  2851. ImgXy();
  2852. }
  2853. }
  2854. }
  2855. else
  2856. {
  2857. ImgPpt.Source = null;
  2858. ImgCanvas.Source = null;
  2859. ImgDocumentation.Source = null;
  2860. }
  2861. }
  2862. }
  2863. // 上一页
  2864. private void last_button_Click(object sender, RoutedEventArgs e)
  2865. {
  2866. if (App.PageContextData.currpage > 1)
  2867. {
  2868. _mouseDown = false;
  2869. _imageOperationUtil.setMouseDown(_mouseDown);
  2870. HideAngleBorder();
  2871. App.PageContextData.currpage -= 1;
  2872. JumpPageClick();
  2873. }
  2874. }
  2875. /// <summary>
  2876. /// 下一页
  2877. /// </summary>
  2878. /// <param name="sender">
  2879. /// </param>
  2880. /// <param name="e">
  2881. /// </param>
  2882. private void next_btn_Click(object sender, RoutedEventArgs e)
  2883. {
  2884. if (App.PageContextData.currpage < App.PageContextData.pagenum)
  2885. {
  2886. _mouseDown = false;
  2887. _imageOperationUtil.setMouseDown(_mouseDown);
  2888. HideAngleBorder();
  2889. App.PageContextData.currpage += 1;
  2890. JumpPageClick();
  2891. }
  2892. }
  2893. #endregion 分页
  2894. #region 图像缩放,移动
  2895. private bool _mouseDown;
  2896. #endregion 图像缩放,移动
  2897. #region 更改设备连接状态
  2898. /// <summary>
  2899. /// 更新设备状态显示
  2900. /// </summary>
  2901. public void UpdateDevStatus()
  2902. {
  2903. if (App.BoardStatus && (App.PenStatus || App.TQLPenStatus))
  2904. {
  2905. Dispatcher.Invoke
  2906. (
  2907. () =>
  2908. {
  2909. TxbNotConnected.Text = "笔/板已连接";
  2910. TxbNotConnecteds.Text = "笔/板已连接";
  2911. }
  2912. );
  2913. }
  2914. else if (App.BoardStatus)
  2915. {
  2916. Dispatcher.Invoke
  2917. (
  2918. () =>
  2919. {
  2920. TxbNotConnected.Text = "手写板已连接";
  2921. TxbNotConnecteds.Text = "手写板已连接";
  2922. }
  2923. );
  2924. }
  2925. else if (App.PenStatus)
  2926. {
  2927. Dispatcher.Invoke
  2928. (
  2929. () =>
  2930. {
  2931. TxbNotConnected.Text = "智能笔已连接";
  2932. TxbNotConnecteds.Text = "智能笔已连接";
  2933. }
  2934. );
  2935. }
  2936. else if (App.TQLPenStatus)
  2937. {
  2938. Dispatcher.Invoke
  2939. (
  2940. () =>
  2941. {
  2942. TxbNotConnected.Text = "智能笔已连接";
  2943. TxbNotConnecteds.Text = "智能笔已连接";
  2944. }
  2945. );
  2946. }
  2947. else
  2948. {
  2949. Dispatcher.Invoke
  2950. (
  2951. () =>
  2952. {
  2953. TxbNotConnected.Text = "未连接";
  2954. TxbNotConnecteds.Text = "未连接";
  2955. }
  2956. );
  2957. }
  2958. }
  2959. #endregion 更改设备连接状态
  2960. #region 腾千里手写笔
  2961. private const float TQLA4_HEIGHT = 1.0f * 3509 / 300 * (float)25.4 / (float)1.524;
  2962. /// <summary>
  2963. /// TQL点阵笔宽高
  2964. /// </summary>
  2965. private const float TQLA4_WIDTH = 1.0f * 2480 / 300 * (float)25.4 / (float)1.524;
  2966. /// <summary>
  2967. /// 是否在书写
  2968. /// </summary>
  2969. private bool _isTqlPenDown;
  2970. //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
  2971. //(float)1512 / (float)150 * (float)25.4 / (float)1.524;
  2972. /// <summary>
  2973. /// TQL初始化
  2974. /// </summary>
  2975. public void InitTqlpPen()
  2976. {
  2977. if (App.TQLPenevents == null)
  2978. {
  2979. App.TQLPenevents = new PenEvents(1);
  2980. }
  2981. else
  2982. {
  2983. App.TQLPenevents.InToType = 1;
  2984. }
  2985. }
  2986. /// <summary>
  2987. /// 笔落下
  2988. /// </summary>
  2989. public void TqlDown()
  2990. {
  2991. _isTqlPenDown = true;
  2992. if (App.PageContextData.currpage > 0)
  2993. {
  2994. Dispatcher.Invoke
  2995. (
  2996. () =>
  2997. {
  2998. myblackboard.changepages
  2999. (
  3000. 0,
  3001. 0,
  3002. true,
  3003. _color,
  3004. _penSize,
  3005. App.PageContextData.currpage - 1,
  3006. 0
  3007. );
  3008. }
  3009. );
  3010. }
  3011. }
  3012. /// <summary>
  3013. /// 笔书写
  3014. /// </summary>
  3015. /// <param name="cx">
  3016. /// </param>
  3017. /// <param name="cy">
  3018. /// </param>
  3019. /// <param name="force">
  3020. /// </param>
  3021. public void TqlPenWrite
  3022. (
  3023. double cx,
  3024. double cy,
  3025. int force
  3026. )
  3027. {
  3028. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  3029. if (!_isTqlPenDown)
  3030. {
  3031. return;
  3032. }
  3033. double propW = BlackboardCanvas.ActualWidth / TQLA4_WIDTH;
  3034. double propH = BlackboardCanvas.ActualHeight / TQLA4_HEIGHT;
  3035. //点
  3036. double tempX = cx * propW;
  3037. double tempY = cy * propH;
  3038. if (App.PageContextData.currpage > 0)
  3039. {
  3040. Dispatcher.Invoke
  3041. (
  3042. () =>
  3043. {
  3044. //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
  3045. float pressure = 1.0f * force / 1023f;
  3046. myblackboard.changepages
  3047. (
  3048. tempX,
  3049. tempY,
  3050. false,
  3051. _color,
  3052. _penSize,
  3053. App.PageContextData.currpage - 1,
  3054. pressure
  3055. );
  3056. #region 设置滚动条位置
  3057. //点在显示页面上方
  3058. if (tempY < ScroMain.VerticalOffset)
  3059. {
  3060. //滚动条当前位置
  3061. double rollCurrentLocation = ScroMain.VerticalOffset;
  3062. //向上滚动至以点为中心需要滚动的距离
  3063. double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3064. //如果小于0则等于0
  3065. double rollLocation = rollCurrentLocation - upRoll;
  3066. if (rollLocation < 0)
  3067. {
  3068. rollLocation = 0;
  3069. }
  3070. ////滚动条实际偏移量
  3071. //double RollOffset = RollCurrentLocation - RollLocation;
  3072. ScroMain.ScrollToVerticalOffset(rollLocation);
  3073. }
  3074. //点在显示页面下方
  3075. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3076. {
  3077. //滚动条当前位置
  3078. double rollCurrentLocation = ScroMain.VerticalOffset;
  3079. //向下滚动至以点为中心需要滚动的距离
  3080. double downRoll = (tempY - rollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3081. //如果小于0则等于0
  3082. double rollLocation = rollCurrentLocation + downRoll;
  3083. //滚动条最大滚动值
  3084. double scrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3085. if (rollLocation > scrollbarMaxNum)
  3086. {
  3087. rollLocation = scrollbarMaxNum;
  3088. }
  3089. ////滚动条实际偏移量
  3090. //double RollOffset = RollLocation-RollCurrentLocation;
  3091. ScroMain.ScrollToVerticalOffset(rollLocation);
  3092. }
  3093. #endregion 设置滚动条位置
  3094. if (tempX > 0 && tempY > 0)
  3095. {
  3096. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3097. SetCursorPos((int)getP.X, (int)getP.Y);
  3098. }
  3099. }
  3100. );
  3101. }
  3102. }
  3103. /// <summary>
  3104. /// 笔抬起
  3105. /// </summary>
  3106. public void TqlUp()
  3107. {
  3108. _isTqlPenDown = false;
  3109. //stroke.Clear();
  3110. if (App.PageContextData.currpage > 0)
  3111. {
  3112. Dispatcher.Invoke
  3113. (
  3114. () =>
  3115. {
  3116. myblackboard.changepages
  3117. (
  3118. 0,
  3119. 0,
  3120. true,
  3121. _color,
  3122. _penSize,
  3123. App.PageContextData.currpage - 1,
  3124. 0
  3125. );
  3126. }
  3127. );
  3128. }
  3129. }
  3130. #endregion 腾千里手写笔
  3131. #region 图片拉伸移动
  3132. /// <summary>
  3133. /// 隐藏图片四个点和线
  3134. /// </summary>
  3135. private void HideAngleBorder()
  3136. {
  3137. _imageOperationUtil.HideAngleBorder();
  3138. }
  3139. private void imgCanvas_MouseMove(object sender, MouseEventArgs e)
  3140. {
  3141. _imageOperationUtil.imgCanvas_MouseMove(sender, e);
  3142. }
  3143. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  3144. {
  3145. _imageOperationUtil.imgCanvas_MouseUp();
  3146. }
  3147. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  3148. {
  3149. _imageOperationUtil.PicEMap_MouseDown(sender, e);
  3150. }
  3151. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  3152. {
  3153. _imageOperationUtil.RectRightUp_DragCompleted();
  3154. }
  3155. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  3156. {
  3157. _imageOperationUtil.RectRightUp_DragDelta(sender, e);
  3158. }
  3159. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  3160. {
  3161. _imageOperationUtil.RectRightUp_DragStarted(sender, e);
  3162. }
  3163. /// <summary>
  3164. /// 鼠标左键点击事件
  3165. /// </summary>
  3166. /// <param name="sender">
  3167. /// </param>
  3168. /// <param name="e">
  3169. /// </param>
  3170. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  3171. {
  3172. _imageOperationUtil.Window_MouseLeftButtonDown_1();
  3173. }
  3174. #endregion 图片拉伸移动
  3175. #region 录屏 录制 截图 导入文档 增加 主页面显示
  3176. /// <summary>
  3177. /// 录屏 录制 截图 导入文档 增加 主页面显示
  3178. /// </summary>
  3179. private void PrepareRecord()
  3180. {
  3181. PageHide();
  3182. GridMain.Visibility = Visibility.Visible;
  3183. GridRecordingTitle.Visibility = Visibility.Visible;
  3184. if (App.PageContextData.pagenum > 0)
  3185. {
  3186. GridPage.Visibility = Visibility.Visible;
  3187. }
  3188. DataContext = App.PageContextData;
  3189. }
  3190. #endregion 录屏 录制 截图 导入文档 增加 主页面显示
  3191. #region 页码跳转
  3192. #endregion 页码跳转
  3193. #region TQL打印
  3194. public static string gPrintFileName;
  3195. private iTextSharp.text.Document _document;
  3196. private bool _gbInitDone;
  3197. /// <summary>
  3198. /// 授权码
  3199. /// </summary>
  3200. private string _gKeyStr;
  3201. private readonly TmatrixClass _tmc = new TmatrixClass();
  3202. /// <summary>
  3203. /// 授权文件位置
  3204. /// </summary>
  3205. private string _tqlAuthorizationPath;
  3206. /// <summary>
  3207. /// 铺码
  3208. /// </summary>
  3209. private bool GenerateCode(string pdfPath)
  3210. {
  3211. try
  3212. {
  3213. if (_gbInitDone == false)
  3214. {
  3215. MessageWindow.Show("打印功能无法使用,无效授权。");
  3216. return false;
  3217. }
  3218. try
  3219. {
  3220. string directoryPath = FileToolsCommon.GetDirectoryName(pdfPath);
  3221. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
  3222. FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
  3223. FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
  3224. FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
  3225. }
  3226. catch (Exception)
  3227. {
  3228. // ignored
  3229. }
  3230. pdfPath = pdfPath.Replace("/", "\\");
  3231. //初始页
  3232. bool[] bPublishImageType = new bool[4];
  3233. bPublishImageType[0] = false;
  3234. bPublishImageType[1] = false;
  3235. bPublishImageType[2] = false;
  3236. bPublishImageType[3] = true;
  3237. int[] gPointType =
  3238. {
  3239. 0,
  3240. 0,
  3241. 0,
  3242. 0,
  3243. 1
  3244. };
  3245. int[] gPointDpi =
  3246. {
  3247. 0,
  3248. 0,
  3249. 0,
  3250. 0,
  3251. 1
  3252. };
  3253. string sGenerateResult = _tmc.GenerateTmatrixCode_OID4
  3254. (
  3255. _gKeyStr,
  3256. pdfPath,
  3257. 0,
  3258. gPointType,
  3259. bPublishImageType,
  3260. gPointDpi
  3261. );
  3262. if (sGenerateResult.Substring(0, 1) == "1")
  3263. {
  3264. Dispatcher.Invoke
  3265. (
  3266. () =>
  3267. {
  3268. MessageWindow.Show("打印功能无法使用,无效授权。");
  3269. }
  3270. );
  3271. return false;
  3272. }
  3273. return true;
  3274. }
  3275. catch (Exception ex)
  3276. {
  3277. Dispatcher.Invoke
  3278. (
  3279. () =>
  3280. {
  3281. MessageWindow.Show("打印失败:" + ex.Message);
  3282. }
  3283. );
  3284. return false;
  3285. }
  3286. }
  3287. /// <summary>
  3288. /// TQL初始化打印
  3289. /// </summary>
  3290. private void TqlPrintInit()
  3291. {
  3292. //初始化
  3293. if (_tmc.TmatrixInitialize() == false)
  3294. {
  3295. }
  3296. else
  3297. {
  3298. _gbInitDone = true;
  3299. }
  3300. _document = new iTextSharp.text.Document
  3301. (
  3302. iTextSharp.text.PageSize.A4,
  3303. 0,
  3304. 0,
  3305. 0,
  3306. 0
  3307. );
  3308. try
  3309. {
  3310. _tqlAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
  3311. StreamReader gsr = new StreamReader(_tqlAuthorizationPath);
  3312. _gKeyStr = gsr.ReadLine();
  3313. gsr.Close();
  3314. string keyCheckResult = _tmc.TmatrixKeyCheck_OID4(_gKeyStr);
  3315. if (keyCheckResult.Substring(0, 1) == "1")
  3316. {
  3317. MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
  3318. LogHelper.WriteErrLog("打印服务授权过期:" + keyCheckResult, null);
  3319. _gbInitDone = false;
  3320. }
  3321. else if (keyCheckResult.Substring(0, 1) == "0")
  3322. {
  3323. }
  3324. }
  3325. catch (Exception ex)
  3326. {
  3327. LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
  3328. MessageWindow.Show("打印服务授权失败,请联系厂家!");
  3329. _gbInitDone = false;
  3330. }
  3331. }
  3332. #endregion TQL打印
  3333. #region 打印界面
  3334. private double _hei;
  3335. private int _msgnum;
  3336. private int _num;
  3337. /// <summary>
  3338. /// 打印状态消息
  3339. /// </summary>
  3340. private string _printMsg = "打印中";
  3341. /// <summary>
  3342. /// 打印进度
  3343. /// </summary>
  3344. private System.Timers.Timer _timesPrint;
  3345. /// <summary>
  3346. /// 打印消息
  3347. /// </summary>
  3348. private System.Timers.Timer _timesPrintMsg;
  3349. private double _wit;
  3350. /// <summary>
  3351. /// 初始化页面
  3352. /// </summary>
  3353. /// <param name="imgPath">
  3354. /// </param>
  3355. /// <param name="wit">
  3356. /// </param>
  3357. /// <param name="hei">
  3358. /// </param>
  3359. public void InitializePrint
  3360. (
  3361. string imgPath,
  3362. double wit,
  3363. double hei
  3364. )
  3365. {
  3366. this._wit = wit;
  3367. this._hei = hei;
  3368. if (!string.IsNullOrWhiteSpace(imgPath))
  3369. {
  3370. ImgPri.Source = new BitmapImage(new Uri(imgPath));
  3371. }
  3372. else
  3373. {
  3374. ImgPri.Source = null;
  3375. }
  3376. GridPrintMask.Visibility = Visibility.Collapsed;
  3377. }
  3378. /// <summary>
  3379. /// 打印初始化
  3380. /// </summary>
  3381. public void InitPrint()
  3382. {
  3383. ResizeMode = ResizeMode.NoResize;
  3384. TqlPrintInit();
  3385. }
  3386. /// <summary>
  3387. /// 生成图片
  3388. /// </summary>
  3389. /// <param name="path">
  3390. /// 图片地址
  3391. /// </param>
  3392. /// <param name="saveimg">
  3393. /// 保存位置
  3394. /// </param>
  3395. /// <param name="rectangle">
  3396. /// 图片位置
  3397. /// </param>
  3398. /// <returns>
  3399. /// </returns>
  3400. private bool MergerPrintImg
  3401. (
  3402. string path,
  3403. string saveimg,
  3404. RectangleF rectangle
  3405. )
  3406. {
  3407. try
  3408. {
  3409. Bitmap bitmap = null;
  3410. //创建要显示的图片对象,根据参数的个数设置宽度
  3411. Bitmap backgroudImg = new Bitmap((int) /*GridM.ActualWidth*/_wit, (int) /*GridM.ActualHeight*/_hei);
  3412. Graphics g = Graphics.FromImage(backgroudImg);
  3413. //清除画布,背景设置为白色
  3414. g.Clear(System.Drawing.Color.White);
  3415. if (!string.IsNullOrWhiteSpace(path))
  3416. {
  3417. bitmap = ImageHelper.ReadBitmapFile(path);
  3418. g.DrawImage(bitmap, rectangle);
  3419. }
  3420. #region 添加箭头
  3421. string str = "↑";
  3422. SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
  3423. Font myfont = new Font("黑体", 14); //设置默认字体格式
  3424. g.DrawString
  3425. (
  3426. str,
  3427. myfont,
  3428. mybrush,
  3429. new Rectangle
  3430. (
  3431. (int)_wit - 50,
  3432. 20,
  3433. 50,
  3434. 50
  3435. )
  3436. );
  3437. #endregion 添加箭头
  3438. backgroudImg.Save(saveimg);
  3439. g.Dispose();
  3440. backgroudImg.Dispose();
  3441. if (bitmap != null)
  3442. {
  3443. bitmap.Dispose();
  3444. }
  3445. GC.Collect();
  3446. return true;
  3447. }
  3448. catch (Exception ex)
  3449. {
  3450. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3451. return false;
  3452. }
  3453. }
  3454. /// <summary>
  3455. /// 开始打印
  3456. /// </summary>
  3457. private void StartPrint(PrintModel printModel)
  3458. {
  3459. try
  3460. {
  3461. _document = new iTextSharp.text.Document
  3462. (
  3463. iTextSharp.text.PageSize.A4,
  3464. 0f,
  3465. 0f,
  3466. 0f,
  3467. 0f
  3468. );
  3469. _printMsg = "生成文件";
  3470. _msgnum = 0;
  3471. string sourcePath1 = printModel.filepath;
  3472. try
  3473. {
  3474. sourcePath1 = sourcePath1.Replace("/", "\\");
  3475. FileStream fs = new FileStream
  3476. (
  3477. sourcePath1,
  3478. FileMode.Create,
  3479. FileAccess.ReadWrite
  3480. );
  3481. _document.AddAuthor("星火微课"); //作者
  3482. _document.AddCreationDate(); //创建时候
  3483. _document.AddCreator("星火微课"); //创建者
  3484. _document.AddSubject("点阵文件"); //主题
  3485. _document.AddTitle("PrintTmatrixCode"); //标题
  3486. _document.AddKeywords("Print");
  3487. _document.AddHeader("TmatrixCode", "0");
  3488. iTextSharp.text.pdf.PdfWriter.GetInstance(_document, fs);
  3489. }
  3490. catch (Exception)
  3491. {
  3492. // ignored
  3493. }
  3494. _document.Open();
  3495. iTextSharp.text.Image image;
  3496. for (int i = 0; i < App.PageDrawList.Count; i++)
  3497. {
  3498. long ii = Timestamp();
  3499. string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3500. string filePathOutPut = Path.Combine
  3501. (
  3502. directoryPath,
  3503. string.Format
  3504. (
  3505. "print{0}{1}.jpg",
  3506. ii,
  3507. i
  3508. )
  3509. );
  3510. RectangleF rectangleFs = new RectangleF();
  3511. MergerPrintImg
  3512. (
  3513. "",
  3514. filePathOutPut,
  3515. rectangleFs
  3516. );
  3517. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3518. if (string.IsNullOrEmpty(App.PageDrawList[i].PageImagePath)) //没有图片
  3519. {
  3520. }
  3521. else if (App.PageDrawList[i].ImgDocumentation && !App.PageDrawList[i].Type.Equals("ppt"))
  3522. {
  3523. image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
  3524. }
  3525. else
  3526. {
  3527. RectangleF rectangleF = new RectangleF
  3528. (
  3529. 0,
  3530. 0,
  3531. 0,
  3532. 0
  3533. );
  3534. var i1 = i;
  3535. Dispatcher.Invoke
  3536. (
  3537. () =>
  3538. {
  3539. rectangleF = new RectangleF
  3540. {
  3541. Width = (float)App.PageDrawList[i1].ImageSizes.CenterX,
  3542. Height = (float)App.PageDrawList[i1].ImageSizes.CenterY,
  3543. X = (float)App.PageDrawList[i1].ImageLocation.X,
  3544. Y = (float)App.PageDrawList[i1].ImageLocation.Y
  3545. };
  3546. }
  3547. );
  3548. bool isImg = MergerPrintImg
  3549. (
  3550. App.PageDrawList[i].PageImagePath,
  3551. filePathOutPut,
  3552. rectangleF
  3553. );
  3554. if (isImg)
  3555. {
  3556. image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3557. }
  3558. else
  3559. {
  3560. image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
  3561. }
  3562. }
  3563. if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3564. {
  3565. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3566. }
  3567. else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3568. {
  3569. image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3570. }
  3571. image.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE;
  3572. _document.NewPage();
  3573. _document.Add(image);
  3574. }
  3575. _document.Close();
  3576. }
  3577. catch (Exception ex)
  3578. {
  3579. Dispatcher.Invoke
  3580. (
  3581. () =>
  3582. {
  3583. BtnPrint.IsEnabled = true;
  3584. _timesPrint.Stop();
  3585. _timesPrintMsg.Stop();
  3586. GridPrintMask.Visibility = Visibility.Collapsed;
  3587. MessageWindow.Show(ex.Message);
  3588. }
  3589. );
  3590. LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
  3591. }
  3592. //PDF位置
  3593. string sourcePath = printModel.filepath;
  3594. if (_isHasCode)
  3595. {
  3596. _printMsg = "铺码中";
  3597. _msgnum = 0;
  3598. Thread.Sleep(500);
  3599. //腾千里生成点阵文件
  3600. if (GenerateCode(sourcePath))
  3601. {
  3602. //打印机名称
  3603. string directoryPath = FileToolsCommon.GetDirectoryName(sourcePath) + "Bg with Images/";
  3604. string[] strs = FileToolsCommon.GetFileNames(directoryPath);
  3605. try
  3606. {
  3607. // 腾千里会根据原PDF的页数生成多个PDF文件
  3608. for (int i = 0; i < strs.Count(); i++)
  3609. {
  3610. _timesPrint.Stop();
  3611. _printMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
  3612. _msgnum = 0;
  3613. _num = 0;
  3614. _timesPrint.Interval = 100;
  3615. _timesPrint.Start();
  3616. string fileName = strs[i];
  3617. //打印文件
  3618. ZPrintUtils.Print2(fileName);
  3619. }
  3620. Dispatcher.Invoke
  3621. (
  3622. () =>
  3623. {
  3624. BtnPrint.IsEnabled = true;
  3625. _num = 99;
  3626. _timesPrint.Stop();
  3627. PgbProcess.Value = 100;
  3628. LbProcess.Content = "100%";
  3629. GridPrintMask.Visibility = Visibility.Collapsed;
  3630. //MessageWindow.Show("已加入打印机队列,打印中。");
  3631. }
  3632. );
  3633. }
  3634. catch (Exception ex)
  3635. {
  3636. Dispatcher.Invoke
  3637. (
  3638. () =>
  3639. {
  3640. MessageWindow.Show("打印失败:" + ex.Message);
  3641. BtnPrint.IsEnabled = true;
  3642. _timesPrint.Stop();
  3643. GridPrintMask.Visibility = Visibility.Collapsed;
  3644. }
  3645. );
  3646. }
  3647. }
  3648. else
  3649. {
  3650. Dispatcher.Invoke
  3651. (
  3652. () =>
  3653. {
  3654. BtnPrint.IsEnabled = true;
  3655. _timesPrint.Stop();
  3656. _timesPrintMsg.Stop();
  3657. GridPrintMask.Visibility = Visibility.Collapsed;
  3658. }
  3659. );
  3660. }
  3661. }
  3662. else
  3663. {
  3664. //打印文件
  3665. ZPrintUtils.Print2(sourcePath);
  3666. Dispatcher.Invoke
  3667. (
  3668. () =>
  3669. {
  3670. BtnPrint.IsEnabled = true;
  3671. _num = 99;
  3672. _timesPrint.Stop();
  3673. PgbProcess.Value = 100;
  3674. LbProcess.Content = "100%";
  3675. GridPrintMask.Visibility = Visibility.Collapsed;
  3676. //MessageWindow.Show("已加入打印机队列,打印中。");
  3677. }
  3678. );
  3679. }
  3680. }
  3681. /// <summary>
  3682. /// 计时器
  3683. /// </summary>
  3684. /// <param name="sender">
  3685. /// </param>
  3686. /// <param name="e">
  3687. /// </param>
  3688. private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
  3689. {
  3690. Dispatcher.Invoke
  3691. (
  3692. () =>
  3693. {
  3694. PgbProcess.Value = _num;
  3695. LbProcess.Content = _num + "%";
  3696. if (_num < 99)
  3697. {
  3698. _num++;
  3699. _timesPrint.Interval += 1.0 * _num / 2;
  3700. }
  3701. else
  3702. {
  3703. _timesPrint.Stop();
  3704. }
  3705. }
  3706. );
  3707. }
  3708. /// <summary>
  3709. /// 消息
  3710. /// </summary>
  3711. /// <param name="sender">
  3712. /// </param>
  3713. /// <param name="e">
  3714. /// </param>
  3715. private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  3716. {
  3717. if (_msgnum > 5)
  3718. _msgnum = 0;
  3719. else
  3720. _msgnum++;
  3721. string point = "";
  3722. point = point.PadRight(_msgnum, '.');
  3723. Dispatcher.Invoke
  3724. (
  3725. () =>
  3726. {
  3727. LabPrintMessage.Content = _printMsg + point;
  3728. }
  3729. );
  3730. }
  3731. #endregion 打印界面
  3732. #region 笔事件回调
  3733. public void penPointEvent
  3734. (
  3735. byte bIndex,
  3736. byte bPenStatus,
  3737. short bx,
  3738. short by,
  3739. short bPress,
  3740. int mNDeviceW,
  3741. int mNDeviceH
  3742. )
  3743. {
  3744. //17是按下,16是抬起
  3745. if (bPenStatus == 16 || bPenStatus == 0)
  3746. {
  3747. //stroke.Clear();
  3748. if (App.PageContextData.currpage > 0)
  3749. {
  3750. Dispatcher.Invoke
  3751. (
  3752. () =>
  3753. {
  3754. myblackboard.changepages
  3755. (
  3756. 0,
  3757. 0,
  3758. true,
  3759. _color,
  3760. _penSize,
  3761. App.PageContextData.currpage - 1,
  3762. 0
  3763. );
  3764. }
  3765. );
  3766. }
  3767. }
  3768. double propW = BlackboardCanvas.ActualWidth / mNDeviceH;
  3769. double propH = BlackboardCanvas.ActualHeight / mNDeviceW;
  3770. //点
  3771. double tempY = (mNDeviceW - bx) * propH;
  3772. double tempX = by * propW;
  3773. //pageSerial //点阵IP地址 与打印的页面关联
  3774. if (App.PageContextData.currpage > 0)
  3775. {
  3776. Dispatcher.Invoke
  3777. (
  3778. () =>
  3779. {
  3780. float pressure = bPress / 100f;
  3781. if (bPress > 0)
  3782. {
  3783. myblackboard.changepages
  3784. (
  3785. tempX,
  3786. tempY,
  3787. false,
  3788. _color,
  3789. _penSize,
  3790. App.PageContextData.currpage - 1,
  3791. pressure
  3792. );
  3793. }
  3794. #region 设置滚动条位置
  3795. //点在显示页面上方
  3796. if (tempY < ScroMain.VerticalOffset)
  3797. {
  3798. //滚动条当前位置
  3799. double rollCurrentLocation = ScroMain.VerticalOffset;
  3800. //向上滚动至以点为中心需要滚动的距离
  3801. double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
  3802. //如果小于0则等于0
  3803. double rollLocation = rollCurrentLocation - upRoll;
  3804. if (rollLocation < 0)
  3805. {
  3806. rollLocation = 0;
  3807. }
  3808. ////滚动条实际偏移量
  3809. //double RollOffset = RollCurrentLocation - RollLocation;
  3810. ScroMain.ScrollToVerticalOffset(rollLocation);
  3811. }
  3812. //点在显示页面下方
  3813. if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
  3814. {
  3815. //滚动条当前位置
  3816. double rollCurrentLocation = ScroMain.VerticalOffset;
  3817. //向下滚动至以点为中心需要滚动的距离
  3818. double downRoll = (tempY - rollCurrentLocation) - (ScroMain.ActualHeight / 2);
  3819. //如果小于0则等于0
  3820. double rollLocation = rollCurrentLocation + downRoll;
  3821. //滚动条最大滚动值
  3822. double scrollbarMaxNum = GridM.ActualHeight - ScroMain.ActualHeight;
  3823. if (rollLocation > scrollbarMaxNum)
  3824. {
  3825. rollLocation = scrollbarMaxNum;
  3826. }
  3827. ////滚动条实际偏移量
  3828. //double RollOffset = RollLocation-RollCurrentLocation;
  3829. ScroMain.ScrollToVerticalOffset(rollLocation);
  3830. }
  3831. #endregion 设置滚动条位置
  3832. if (tempX > 0 && tempY > 0)
  3833. {
  3834. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  3835. System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
  3836. SetCursorPos((int)getP.X, (int)getP.Y);
  3837. }
  3838. }
  3839. );
  3840. }
  3841. }
  3842. public void penStatusEvent()
  3843. {
  3844. UpdateDevStatus();
  3845. }
  3846. #endregion 笔事件回调
  3847. private void Window_Closed(object sender, EventArgs e)
  3848. {
  3849. Environment.Exit(0);
  3850. }
  3851. }
  3852. }