星火微课系统客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MainWindow.xaml.cs 172KB

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