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

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