星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

XHMicroLessonSystemWindow.xaml.cs 201KB

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