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

XHMicroLessonSystemWindow.xaml.cs 45KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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. namespace XHWK.WKTool
  21. {
  22. /// <summary>
  23. /// 主页面
  24. /// </summary>
  25. public partial class XHMicroLessonSystemWindow : Window
  26. {
  27. #region 字段
  28. /// <summary>
  29. /// 文件目录窗口
  30. /// </summary>
  31. //private CountdownWindow FileDirectoryWindows = null;
  32. private FolderBrowserDialog Ofd;
  33. private DialogResult Result;
  34. public readonly BlackboardNew myblackboard;
  35. private System.Windows.Forms.DialogResult result;
  36. private System.Windows.Forms.OpenFileDialog ofd;
  37. //声明一个 DrawingAttributes 类型的变量
  38. DrawingAttributes drawingAttributes;
  39. //定义事件
  40. public event ChangeTextHandler ChangeTextEvent;
  41. //定义委托
  42. public delegate void ChangeTextHandler(string text);
  43. #endregion
  44. #region 初始化
  45. /// <summary>
  46. /// 主页面
  47. /// </summary>
  48. public XHMicroLessonSystemWindow()
  49. {
  50. 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=")));
  51. InitializeComponent();
  52. myblackboard = new BlackboardNew(blackboard_canvas);
  53. APP.pageData.pagenum = 1;
  54. APP.pageData.currpage = 1;
  55. DataContext = APP.pageData;
  56. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoType");
  57. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  58. {
  59. rbnY.IsChecked = true;
  60. }
  61. else
  62. {
  63. rbnN.IsChecked = true;
  64. }
  65. txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
  66. Initialize();
  67. }
  68. /// <summary>
  69. /// 初始化
  70. /// </summary>
  71. public void Initialize()
  72. {
  73. //创建 DrawingAttributes 类的一个实例
  74. drawingAttributes = new DrawingAttributes();
  75. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  76. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  77. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  78. blackboard_canvas.UseCustomCursor = true;
  79. drawingAttributes.FitToCurve = true;
  80. drawingAttributes.IgnorePressure = false;
  81. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  82. wfhCamera.Visibility = Visibility.Hidden;
  83. }
  84. #endregion
  85. #region 事件
  86. /// <summary>
  87. /// 窗体移动
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  92. {
  93. DragMove();
  94. }
  95. /// <summary>
  96. /// 摄像头打开事件
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  101. {
  102. //UCCamera win = new UCCamera();
  103. ////win.Topmost = true;
  104. //win.ShowDialog();
  105. wfhCamera.Visibility = Visibility.Visible;
  106. CameraHelper.IsDisplay = true;
  107. CameraHelper.SourcePlayer = player;
  108. CameraHelper.UpdateCameraDevices();
  109. if (CameraHelper.CameraDevices.Count > 0)
  110. {
  111. CameraHelper.SetCameraDevice(0);
  112. }
  113. }
  114. /// <summary>
  115. /// 摄像头关闭事件
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  120. {
  121. wfhCamera.Visibility = Visibility.Hidden;
  122. CameraHelper.CloseDevice();
  123. }
  124. #endregion
  125. /// <summary>
  126. /// 录屏事件
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  131. {
  132. if (APP.IsLoginType == false)
  133. {
  134. Login();
  135. return;
  136. }
  137. if (APP.W_ScreenRecordingToolbarWindow == null)
  138. {
  139. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  140. {
  141. Topmost = true
  142. };
  143. APP.W_ScreenRecordingToolbarWindow.Initialize();
  144. }
  145. else
  146. {
  147. APP.W_ScreenRecordingToolbarWindow.Initialize();
  148. }
  149. //显示在右下角
  150. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 10;
  151. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 160;
  152. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  153. APP.W_ScreenRecordingToolbarWindow.Show();
  154. Hide();
  155. }
  156. /// <summary>
  157. /// 上传事件
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  162. {
  163. if (APP.IsLoginType == false)
  164. {
  165. Login();
  166. return;
  167. }
  168. FileDirectoryWindow fileDirectoryWindow = new FileDirectoryWindow();
  169. fileDirectoryWindow.Show();
  170. }
  171. /// <summary>
  172. /// 关闭事件
  173. /// </summary>
  174. /// <param name="sender"></param>
  175. /// <param name="e"></param>
  176. private void BtnDown_Click(object sender, RoutedEventArgs e)
  177. {
  178. System.Environment.Exit(0);
  179. }
  180. /// <summary>
  181. /// 设置 保存事件
  182. /// </summary>
  183. /// <param name="sender"></param>
  184. /// <param name="e"></param>
  185. private void BtnSave_Click(object sender, RoutedEventArgs e)
  186. {
  187. #region 合法性判断
  188. if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
  189. {
  190. System.Windows.MessageBox.Show("路径不可为空!");
  191. return;
  192. }
  193. string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  194. if (!APP.WKData.WkPath.Equals(temp))
  195. {
  196. APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
  197. if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
  198. {
  199. //微课已存在
  200. MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
  201. if (dr == MessageBoxResult.OK)
  202. {
  203. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
  204. }
  205. else
  206. {
  207. return;
  208. }
  209. }
  210. //创建文件夹
  211. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  212. }
  213. #endregion
  214. if (rbnMP4.IsChecked == true)
  215. {
  216. //存储文件
  217. FileToolsCommon.SetConfigValue("VideoType", "1");
  218. }
  219. else if (rbnFLV.IsChecked == true)
  220. {
  221. FileToolsCommon.SetConfigValue("VideoType", "2");
  222. }
  223. else
  224. {
  225. FileToolsCommon.SetConfigValue("VideoType", "3");
  226. }
  227. if (rbnY.IsChecked == true)
  228. {
  229. FileToolsCommon.SetConfigValue("IsSound", "true");
  230. }
  231. else
  232. {
  233. FileToolsCommon.SetConfigValue("IsSound", "false");
  234. }
  235. GridMain.Visibility = Visibility.Visible;
  236. gridSetUp.Visibility = Visibility.Collapsed;
  237. }
  238. /// <summary>
  239. /// 设置事件
  240. /// </summary>
  241. /// <param name="sender"></param>
  242. /// <param name="e"></param>
  243. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  244. {
  245. GridMain.Visibility = Visibility.Collapsed;
  246. gridSetUp.Visibility = Visibility.Visible;
  247. }
  248. /// <summary>
  249. /// 设置 浏览事件
  250. /// </summary>
  251. /// <param name="sender"></param>
  252. /// <param name="e"></param>
  253. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  254. {
  255. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  256. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  257. Result = Ofd.ShowDialog();
  258. if (Result == System.Windows.Forms.DialogResult.OK)
  259. {
  260. if (Ofd.SelectedPath != "")
  261. {
  262. txbStoragePath.Text = Ofd.SelectedPath;
  263. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  264. //string temp = ofd.SelectedPath;
  265. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  266. }
  267. }
  268. }
  269. /// <summary>
  270. /// 画笔颜色事件 白色
  271. /// </summary>
  272. /// <param name="sender"></param>
  273. /// <param name="e"></param>
  274. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  275. {
  276. ////创建 DrawingAttributes 类的一个实例
  277. //drawingAttributes = new DrawingAttributes();
  278. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  279. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  280. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  281. ////设置 DrawingAttributes 的 Color 属性设置颜色
  282. drawingAttributes.Color = Colors.White;
  283. }
  284. /// <summary>
  285. /// 画笔颜色事件 红色
  286. /// </summary>
  287. /// <param name="sender"></param>
  288. /// <param name="e"></param>
  289. private void BtnRed_Click(object sender, RoutedEventArgs e)
  290. {
  291. //设置 DrawingAttributes 的 Color 属性设置颜色
  292. drawingAttributes.Color = Colors.Red;
  293. }
  294. /// <summary>
  295. /// 画笔颜色事件 灰色
  296. /// </summary>
  297. /// <param name="sender"></param>
  298. /// <param name="e"></param>
  299. private void BtnGray_Click(object sender, RoutedEventArgs e)
  300. {
  301. drawingAttributes.Color = Colors.Gray;
  302. }
  303. /// <summary>
  304. /// 画笔颜色事件 青色
  305. /// </summary>
  306. /// <param name="sender"></param>
  307. /// <param name="e"></param>
  308. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  309. {
  310. drawingAttributes.Color = Colors.LimeGreen;
  311. }
  312. /// <summary>
  313. /// 画笔颜色事件 黄色
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  318. {
  319. drawingAttributes.Color = Colors.Gold;
  320. }
  321. /// <summary>
  322. /// 画笔颜色事件 蓝色
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  327. {
  328. drawingAttributes.Color = Colors.DeepSkyBlue;
  329. }
  330. /// <summary>
  331. /// 画笔粗细事件 细
  332. /// </summary>
  333. /// <param name="sender"></param>
  334. /// <param name="e"></param>
  335. private void RbnFine_Click(object sender, RoutedEventArgs e)
  336. {
  337. drawingAttributes.Width = 1;
  338. drawingAttributes.Height = 1;
  339. }
  340. /// <summary>
  341. /// 画笔粗细事件 中
  342. /// </summary>
  343. /// <param name="sender"></param>
  344. /// <param name="e"></param>
  345. private void RbnIn_Click(object sender, RoutedEventArgs e)
  346. {
  347. drawingAttributes.Width = 3;
  348. drawingAttributes.Height = 3;
  349. }
  350. /// <summary>
  351. /// 画笔粗细事件 粗
  352. /// </summary>
  353. /// <param name="sender"></param>
  354. /// <param name="e"></param>
  355. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  356. {
  357. drawingAttributes.Width = 5;
  358. drawingAttributes.Height = 5;
  359. }
  360. /// <summary>
  361. /// 登陆事件
  362. /// </summary>
  363. /// <param name="sender"></param>
  364. /// <param name="e"></param>
  365. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  366. {
  367. Login();
  368. }
  369. /// <summary>
  370. /// 登陆
  371. /// </summary>
  372. private void Login()
  373. {
  374. if (APP.W_LoginWindow == null)
  375. {
  376. APP.W_LoginWindow = new LoginWindow();
  377. }
  378. else
  379. {
  380. APP.W_LoginWindow.Initialize();
  381. }
  382. APP.W_LoginWindow.ShowDialog();
  383. if (APP.IsLoginType)
  384. {
  385. txbLoginType.Text = APP.UserInfo.Username;
  386. }
  387. else
  388. {
  389. txbLoginType.Text = "未登录";
  390. }
  391. }
  392. /// <summary>
  393. /// 截图事件
  394. /// </summary>
  395. /// <param name="sender"></param>
  396. /// <param name="e"></param>
  397. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  398. {
  399. if (APP.IsLoginType == false)
  400. {
  401. Login();
  402. return;
  403. }
  404. string time = GetTimeStamp();
  405. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  406. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
  407. if (APP.W_JieTuWindow != null)
  408. {
  409. APP.W_JieTuWindow.initialization();
  410. APP.W_JieTuWindow.Screenshot();
  411. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  412. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  413. }
  414. else
  415. {
  416. APP.W_JieTuWindow = new JieTuWindow();
  417. // 订阅事件
  418. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  419. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  420. APP.W_JieTuWindow.Show();
  421. }
  422. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  423. }
  424. /// <summary>
  425. /// 截图关闭窗口
  426. /// </summary>
  427. /// <param name="text"></param>
  428. private void frm_ChangeTextEvent(string text)
  429. {
  430. if ("关闭窗口".Equals(text))
  431. {
  432. if(!string.IsNullOrWhiteSpace(APP.ImgPath)&&File.Exists(APP.ImgPath))
  433. {
  434. APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
  435. if(!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  436. {
  437. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  438. }
  439. }
  440. }
  441. }
  442. /// <summary>
  443. /// 截图关闭 非正常关闭截图时,截图清空
  444. /// </summary>
  445. private void JietuWindow_click_closeJietuWindowClick()
  446. {
  447. APP.W_JieTuWindow = null;
  448. }
  449. /// <summary>
  450. /// 获取时间戳
  451. /// </summary>
  452. /// <returns></returns>
  453. public string GetTimeStamp()
  454. {
  455. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  456. return Convert.ToInt64(ts.TotalSeconds).ToString();
  457. }
  458. /// <summary>
  459. /// 导入事件
  460. /// </summary>
  461. /// <param name="sender"></param>
  462. /// <param name="e"></param>
  463. private void BtnImport_Click(object sender, RoutedEventArgs e)
  464. {
  465. if (APP.IsLoginType == false)
  466. {
  467. Login();
  468. return;
  469. }
  470. try
  471. {
  472. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  473. ofd = new System.Windows.Forms.OpenFileDialog
  474. {
  475. Filter = "文档|*.docx;*.doc;*ppt",
  476. InitialDirectory = desktopPath,
  477. Multiselect = false,
  478. AddExtension = true,
  479. DereferenceLinks = true
  480. };
  481. new Thread(
  482. o =>
  483. {
  484. Thread.Sleep(400);
  485. Dispatcher.Invoke(new Action(() =>
  486. {
  487. OpenDialogPPT();
  488. }
  489. ));
  490. })
  491. {
  492. IsBackground = true
  493. }.Start();
  494. }
  495. catch (Exception ex)
  496. {
  497. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  498. }
  499. }
  500. private void OpenDialog()
  501. {
  502. result = ofd.ShowDialog();
  503. if (result == System.Windows.Forms.DialogResult.OK)
  504. {
  505. if (ofd.FileName != "")
  506. {
  507. string filepath = ofd.FileName;
  508. string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  509. APP.Paths = ConvertWordToImage(filepath, path, "", 0, 0, null, 0).ToArray();
  510. for (int i = 0; i < APP.Paths.Length; i++)
  511. {
  512. APP.pageData.pagenum += 1;
  513. }
  514. if (APP.pageData.pagenum > 1)
  515. {
  516. APP.pageData.pagenum -= 1;
  517. }
  518. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  519. {
  520. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  521. }
  522. else
  523. {
  524. imgCanvas.Source = null;
  525. }
  526. }
  527. }
  528. }
  529. private void OpenDialogPPT()
  530. {
  531. result = ofd.ShowDialog();
  532. if (result == System.Windows.Forms.DialogResult.OK)
  533. {
  534. if (ofd.FileName != "")
  535. {
  536. #region PPT转PDF
  537. string filepath = ofd.FileName;
  538. string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
  539. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  540. path = pathTemp + path + ".pdf";
  541. //PPT转PDF
  542. Presentation ppt = new Presentation(filepath);
  543. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  544. #endregion
  545. #region PDF转图片
  546. // 图片绝对路径集合
  547. List<string> images = new List<string>();
  548. string directoryPath = pathTemp;
  549. //aspose许可证
  550. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  551. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  552. //l.SetLicense(licenseName);
  553. //定义Jpeg转换设备
  554. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  555. var device = new Aspose.Pdf.Devices.JpegDevice();
  556. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  557. //directoryPath += quality;
  558. Directory.CreateDirectory(directoryPath);
  559. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  560. device = new Aspose.Pdf.Devices.JpegDevice(100);
  561. //遍历每一页转为jpg
  562. for (var i = 1; i <= document.Pages.Count; i++)
  563. {
  564. long ii = Timestamp();
  565. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  566. images.Add(filePathOutPut);
  567. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  568. try
  569. {
  570. device.Process(document.Pages[i], fs);
  571. fs.Close();
  572. }
  573. catch (Exception ex)
  574. {
  575. fs.Close();
  576. File.Delete(filePathOutPut);
  577. }
  578. }
  579. #endregion
  580. APP.Paths = images.ToArray();
  581. for (int i = 0; i < APP.Paths.Length; i++)
  582. {
  583. APP.pageData.pagenum += 1;
  584. }
  585. if (APP.pageData.pagenum > 1)
  586. {
  587. APP.pageData.pagenum -= 1;
  588. }
  589. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
  590. {
  591. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  592. }
  593. else
  594. {
  595. imgCanvas.Source = null;
  596. }
  597. }
  598. }
  599. }
  600. /// <summary>
  601. /// 返回一个时间戳到毫秒
  602. /// </summary>
  603. /// <returns></returns>
  604. public static long Timestamp()
  605. {
  606. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  607. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  608. return timestr;
  609. }
  610. #region 录制窗口
  611. #region 变量
  612. /// <summary>
  613. /// 视频保存路径
  614. /// </summary>
  615. string RecordingPath;
  616. /// <summary>
  617. /// 图片保存路径
  618. /// </summary>
  619. string ImgPath;
  620. /// <summary>
  621. /// 音频保存路径名
  622. /// </summary>
  623. string AudioPathName;
  624. /// <summary>
  625. /// 视频保存路径名
  626. /// </summary>
  627. string VideoSavePathName;
  628. /// <summary>
  629. /// 暂停录制
  630. /// </summary>
  631. bool IsSuspendR = true;
  632. /// <summary>
  633. /// 是否首次录制
  634. /// </summary>
  635. bool IsFirstR = true;
  636. /// <summary>
  637. /// 图片
  638. /// </summary>
  639. List<string> RsImgName = null;
  640. /// <summary>
  641. /// 是否开始截图计数
  642. /// </summary>
  643. bool IsStartCount = false;
  644. #endregion
  645. /// <summary>
  646. /// 录制窗口内容
  647. /// </summary>
  648. /// <param name="sender"></param>
  649. /// <param name="e"></param>
  650. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  651. {
  652. if (APP.IsLoginType == false)
  653. {
  654. Login();
  655. return;
  656. }
  657. blackboard_canvas.Visibility = Visibility.Visible;
  658. StartRecord();
  659. }
  660. /// <summary>
  661. /// 停止录制窗口内容
  662. /// </summary>
  663. /// <param name="sender"></param>
  664. /// <param name="e"></param>
  665. private void BtnStop_Click(object sender, RoutedEventArgs e)
  666. {
  667. if (APP.IsLoginType == false)
  668. {
  669. Login();
  670. return;
  671. }
  672. blackboard_canvas.Visibility = Visibility.Collapsed;
  673. EndRecord();
  674. }
  675. System.Timers.Timer timer;
  676. /// <summary>
  677. /// 开始录制和暂停录制
  678. /// </summary>
  679. void StartRecord()
  680. {
  681. if (IsSuspendR)
  682. {
  683. if (IsFirstR)//是否第一次录制 初始化录制
  684. {
  685. RecordingPath = APP.WKData.WkPath;
  686. ImgPath = APP.WKData.WkPath + "temp/Image/";
  687. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  688. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  689. FileToolsCommon.CreateDirectory(RecordingPath);
  690. FileToolsCommon.CreateDirectory(ImgPath);
  691. FileToolsCommon.CreateDirectory(AudioPathName);
  692. AudioPathName += APP.WKData.WkName + ".MP3";
  693. VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  694. if (FileToolsCommon.IsExistFile(VideoSavePathName))
  695. {
  696. MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  697. if (dr == MessageBoxResult.OK)
  698. {
  699. FileToolsCommon.DeleteFile(VideoSavePathName);
  700. }
  701. else
  702. {
  703. return;
  704. }
  705. }
  706. IsFirstR = false;
  707. RsImgName = new List<string>();
  708. timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
  709. timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
  710. timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  711. timer.Enabled = true; //启动计时器
  712. #region 保存图片
  713. //new Thread(new ThreadStart(new Action(() =>
  714. //{
  715. // while (true)
  716. // {
  717. // Thread.Sleep(200);
  718. // if (IsStartCount)
  719. // {
  720. // ImgNum++;
  721. // Dispatcher.Invoke(() =>
  722. // {
  723. // lblNumber.Content = ImgNum;
  724. // string FilePathName = ImgPath + ImgNum + ".png";
  725. // ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  726. // });
  727. // }
  728. // }
  729. //}))).Start();
  730. #endregion
  731. }
  732. #region 录像倒计时
  733. if (APP.W_CountdownWindow == null)
  734. {
  735. APP.W_CountdownWindow = new CountdownWindow();
  736. //APP.W_CountdownWindow.Topmost = true;
  737. }
  738. else
  739. {
  740. APP.W_CountdownWindow.Initialize();
  741. APP.W_CountdownWindow.Topmost = true;
  742. }
  743. APP.W_CountdownWindow.Show();
  744. #endregion
  745. //继续录制
  746. IsSuspendR = false;
  747. //BtnRecording.Content = "暂停录制";
  748. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  749. TxbRecordingWord.Text = "暂停";
  750. try
  751. {
  752. APP.FFmpeg.StartRecordingAudio(AudioPathName);
  753. new Thread(new ThreadStart(new Action(() =>
  754. {
  755. Thread.Sleep(1000);
  756. Dispatcher.Invoke(() =>
  757. {
  758. IsStartCount = true;
  759. //timer.Start();
  760. });
  761. }))).Start();
  762. }
  763. catch (Exception ex)
  764. {
  765. System.Windows.MessageBox.Show(ex.Message);
  766. }
  767. }
  768. else
  769. {
  770. //暂停
  771. IsSuspendR = true;
  772. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  773. TxbRecordingWord.Text = "继续";
  774. try
  775. {
  776. APP.FFmpeg.SuspendFFmpeg();
  777. new Thread(new ThreadStart(new Action(() =>
  778. {
  779. while (APP.FFmpeg.myProcess != null)
  780. {
  781. Thread.Sleep(100);
  782. }
  783. IsStartCount = false;
  784. }))).Start();
  785. }
  786. catch (Exception ex)
  787. {
  788. System.Windows.MessageBox.Show(ex.Message);
  789. }
  790. }
  791. }
  792. /// <summary>
  793. /// 录制保存图片
  794. /// </summary>
  795. /// <param name="sender"></param>
  796. /// <param name="e"></param>
  797. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  798. {
  799. if (IsStartCount)
  800. {
  801. try
  802. {
  803. Dispatcher.Invoke(() =>
  804. {
  805. string FilePathName = ImgPath + RsImgName.Count + ".png";
  806. ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
  807. RsImgName.Add(FilePathName);
  808. });
  809. }
  810. catch (Exception ex)
  811. {
  812. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  813. }
  814. }
  815. }
  816. /// <summary>
  817. /// 停止录制并生成录制文件
  818. /// </summary>
  819. void EndRecord()
  820. {
  821. if (!IsFirstR)
  822. {
  823. IsFirstR = true;
  824. IsSuspendR = true;
  825. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  826. TxbRecordingWord.Text = "录制";
  827. try
  828. {
  829. APP.FFmpeg.StopFFmpeg(AudioPathName);
  830. new Thread(new ThreadStart(new Action(() =>
  831. {
  832. while (APP.FFmpeg.myProcess != null)
  833. {
  834. Thread.Sleep(100);
  835. }
  836. Dispatcher.Invoke(() =>
  837. {
  838. IsStartCount = false;
  839. timer.Stop();
  840. });
  841. }))).Start();
  842. new Thread(new ThreadStart(new Action(() =>
  843. {
  844. while (APP.FFmpeg.myProcess != null)
  845. {
  846. Thread.Sleep(100);
  847. }
  848. }))).Start();
  849. APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
  850. //生成缩略图
  851. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  852. FileToolsCommon.CreateDirectory(ThumbnailPath);
  853. //缩略图存储位置
  854. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
  855. new Thread(new ThreadStart(new Action(() =>
  856. {
  857. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  858. {
  859. Thread.Sleep(100);
  860. }
  861. FileToolsCommon.DeleteFile(ThumbnailPathName);
  862. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
  863. }))).Start();
  864. }
  865. catch (Exception ex)
  866. {
  867. System.Windows.MessageBox.Show(ex.Message);
  868. }
  869. }
  870. }
  871. #endregion
  872. /// <summary>
  873. /// 增加事件
  874. /// </summary>
  875. /// <param name="sender"></param>
  876. /// <param name="e"></param>
  877. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  878. {
  879. if (APP.IsLoginType == false)
  880. {
  881. Login();
  882. return;
  883. }
  884. APP.pageData.pagenum += 1;
  885. APP.pageData.currpage = APP.pageData.pagenum;
  886. myblackboard.changepage(APP.pageData.currpage - 1);
  887. imgCanvas.Source = null;
  888. }
  889. /// <summary>
  890. /// 打印事件
  891. /// </summary>
  892. /// <param name="sender"></param>
  893. /// <param name="e"></param>
  894. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  895. {
  896. }
  897. /// <summary>
  898. /// 我的
  899. /// </summary>
  900. /// <param name="sender"></param>
  901. /// <param name="e"></param>
  902. private void BtnMyMine_Click(object sender, RoutedEventArgs e)
  903. {
  904. if (APP.IsLoginType == false)
  905. {
  906. Login();
  907. return;
  908. }
  909. }
  910. /// <summary>
  911. /// 上一页
  912. /// </summary>
  913. /// <param name="sender"></param>
  914. /// <param name="e"></param>
  915. private void last_button_Click(object sender, RoutedEventArgs e)
  916. {
  917. if (APP.pageData.currpage > 1)
  918. {
  919. APP.pageData.currpage -= 1;
  920. myblackboard.changepage(APP.pageData.currpage - 1);
  921. if (APP.Paths.Length > 0)
  922. {
  923. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length&& APP.pageData.currpage > 0)
  924. {
  925. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
  926. }
  927. else
  928. {
  929. imgCanvas.Source = null;
  930. }
  931. }
  932. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  933. {
  934. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  935. }
  936. }
  937. }
  938. /// <summary>
  939. /// 下一页
  940. /// </summary>
  941. /// <param name="sender"></param>
  942. /// <param name="e"></param>
  943. private void next_btn_Click(object sender, RoutedEventArgs e)
  944. {
  945. if (APP.pageData.currpage < APP.pageData.pagenum)
  946. {
  947. APP.pageData.currpage += 1;
  948. myblackboard.changepage(APP.pageData.currpage - 1);
  949. if (APP.Paths.Length > 0)
  950. {
  951. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
  952. {
  953. imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  954. }
  955. else
  956. {
  957. imgCanvas.Source = null;
  958. }
  959. }
  960. if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
  961. {
  962. imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
  963. }
  964. }
  965. }
  966. /// <summary>
  967. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  968. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  969. /// </summary>
  970. /// <param name="pdfInputPath">Word文件路径</param>
  971. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  972. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  973. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  974. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  975. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  976. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  977. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  978. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  979. {
  980. // 返回的图片绝对路径集合
  981. List<string> images = new List<string>();
  982. try
  983. {
  984. // open word file
  985. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  986. // validate parameter
  987. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  988. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  989. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  990. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  991. if (startPageNum <= 0) { startPageNum = 1; }
  992. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  993. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  994. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  995. if (resolution <= 0) { resolution = 128; }
  996. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  997. {
  998. Resolution = resolution
  999. };
  1000. // start to convert each page
  1001. for (int i = startPageNum; i <= endPageNum; i++)
  1002. {
  1003. imageSaveOptions.PageIndex = i - 1;
  1004. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  1005. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  1006. APP.num++;
  1007. }
  1008. imageSaveOptions = null;
  1009. doc = null;
  1010. }
  1011. catch (Exception ex)
  1012. {
  1013. System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
  1014. LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
  1015. }
  1016. return images;
  1017. }
  1018. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  1019. {
  1020. SaveFormat sf;// = SaveFormat.Unknown;
  1021. if (imageFormat.Equals(ImageFormat.Png))
  1022. {
  1023. sf = SaveFormat.Png;
  1024. }
  1025. else if (imageFormat.Equals(ImageFormat.Jpeg))
  1026. {
  1027. sf = SaveFormat.Jpeg;
  1028. }
  1029. else if (imageFormat.Equals(ImageFormat.Tiff))
  1030. {
  1031. sf = SaveFormat.Tiff;
  1032. }
  1033. else if (imageFormat.Equals(ImageFormat.Bmp))
  1034. {
  1035. sf = SaveFormat.Bmp;
  1036. }
  1037. else
  1038. {
  1039. sf = SaveFormat.Unknown;
  1040. }
  1041. return sf;
  1042. }
  1043. #region 图像缩放,移动
  1044. private bool mouseDown;
  1045. private System.Windows.Point mouseXY;
  1046. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1047. {
  1048. var img = sender as ContentControl;
  1049. if (img == null)
  1050. {
  1051. return;
  1052. }
  1053. img.CaptureMouse();
  1054. mouseDown = true;
  1055. mouseXY = e.GetPosition(img);
  1056. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  1057. }
  1058. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  1059. {
  1060. System.Windows.Point point = e.GetPosition(imgCanvas);
  1061. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  1062. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  1063. //{
  1064. // Console.WriteLine("在范围内");
  1065. //}
  1066. }
  1067. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1068. {
  1069. var img = sender as ContentControl;
  1070. if (img == null)
  1071. {
  1072. return;
  1073. }
  1074. img.ReleaseMouseCapture();
  1075. mouseDown = false;
  1076. }
  1077. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  1078. {
  1079. var img = sender as ContentControl;
  1080. if (img == null)
  1081. {
  1082. return;
  1083. }
  1084. if (mouseDown)
  1085. {
  1086. Domousemove(img, e);
  1087. }
  1088. }
  1089. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  1090. {
  1091. if (e.LeftButton != MouseButtonState.Pressed)
  1092. {
  1093. return;
  1094. }
  1095. var group = IMG.FindResource("Imageview") as TransformGroup;
  1096. var transform = group.Children[1] as TranslateTransform;
  1097. var position = e.GetPosition(img);
  1098. transform.X -= mouseXY.X - position.X;
  1099. transform.Y -= mouseXY.Y - position.Y;
  1100. mouseXY = position;
  1101. }
  1102. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  1103. {
  1104. var img = sender as ContentControl;
  1105. if (img == null)
  1106. {
  1107. return;
  1108. }
  1109. var point = e.GetPosition(img);
  1110. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  1111. var PicLocate = e.GetPosition(imgCanvas);
  1112. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  1113. var group = IMG.FindResource("Imageview") as TransformGroup;
  1114. var delta = e.Delta * 0.001;
  1115. DowheelZoom(group, point, delta);
  1116. }
  1117. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  1118. {
  1119. var pointToContent = group.Inverse.Transform(point);
  1120. var transform = group.Children[0] as ScaleTransform;
  1121. if (transform.ScaleX + delta < 0.1) return;
  1122. transform.ScaleX += delta;
  1123. transform.ScaleY += delta;
  1124. var transform1 = group.Children[1] as TranslateTransform;
  1125. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  1126. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  1127. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  1128. }
  1129. #endregion
  1130. }
  1131. }