星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

MainWindow.xaml.cs 172KB

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