星火微课系统客户端
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 166KB

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