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

XHMicroLessonSystemWindow.xaml.cs 148KB

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