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

XHMicroLessonSystemWindow.xaml.cs 225KB

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