星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

XHMicroLessonSystemWindow.xaml.cs 143KB

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