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

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