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

XHMicroLessonSystemWindow.xaml.cs 180KB

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