星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHMicroLessonSystemWindow.xaml.cs 45KB

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