星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

XHMicroLessonSystemWindow.xaml.cs 159KB

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