1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699 |
- using Aspose.Words;
- using Aspose.Words.Saving;
- using Common.system;
- using System;
- using System.Collections.Generic;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Threading;
- using System.Windows;
- using System.Windows.Forms;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using XHWK.Model;
- using System.Windows.Controls;
- using ComeCapture;
- using Aspose.Slides;
- using static Common.system.PdfTrunImage;
- using TStudyDigitalPen.HID;
- using System.Drawing;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 主页面
- /// </summary>
- public partial class XHMicroLessonSystemWindow : Window
- {
- #region 字段
- /// <summary>
- /// 文件目录窗口
- /// </summary>
- //private CountdownWindow FileDirectoryWindows = null;
- private FolderBrowserDialog Ofd;
- private DialogResult Result;
- public readonly BlackboardNew myblackboard;
- private System.Windows.Forms.DialogResult result;
- private System.Windows.Forms.OpenFileDialog ofd;
- //声明一个 DrawingAttributes 类型的变量
- DrawingAttributes drawingAttributes;
- Model_Video VideoInfo = null;
- //定义事件
- public event ChangeTextHandler ChangeTextEvent;
- //定义委托
- public delegate void ChangeTextHandler(string text);
- /// <summary>
- /// 图片
- /// </summary>
- string [] ImgPDFPath = new string[300];
- #endregion
-
- #region 初始化
- /// <summary>
- /// 主页面
- /// </summary>
- public XHMicroLessonSystemWindow()
- {
- 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=")));
- InitializeComponent();
-
- myblackboard = new BlackboardNew(blackboard_canvas);
- APP.pageData.pagenum = 1;
- APP.pageData.currpage = 1;
- DataContext = APP.pageData;
-
- txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
- if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
- {
- rbnY.IsChecked = true;
- }
- else
- {
- rbnN.IsChecked = true;
- }
- txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
- Initialize();
- InitPen();
- }
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
-
- //创建 DrawingAttributes 类的一个实例
- drawingAttributes = new DrawingAttributes();
- //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- blackboard_canvas.UseCustomCursor = true;
- drawingAttributes.FitToCurve = true;
- drawingAttributes.IgnorePressure = false;
- blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
- //wfhCamera.Visibility = Visibility.Hidden;
- ImgPDFPath = null;
- ImgPDFPath = new string[300];
- }
- #endregion
-
- #region 事件
- /// <summary>
- /// 窗体移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
-
- #region 摄像头
- System.Timers.Timer times;
- List<string> RbnOpen;
- bool IsRbnOpen = false;
- /// <summary>
- /// 摄像头打开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnOpen_Click(object sender, RoutedEventArgs e)
- {
- //UCCamera win = new UCCamera();
- ////win.Topmost = true;
- //win.ShowDialog();
-
-
-
- //wfhCamera.Visibility = Visibility.Visible;
- //CameraHelper.IsDisplay = true;
- //CameraHelper.SourcePlayer = player;
- CameraHelper.UpdateCameraDevices();
- if (CameraHelper.CameraDevices.Count > 0)
- {
- CameraHelper.SetCameraDevice(0);
- imgPlayer.Visibility = Visibility.Visible;
- RbnOpen = new List<string>();
- times = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
- times.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
- times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
- times.Enabled = true; //启动计时器
-
- IsRbnOpen = true;
- }
- }
-
- int I = 9999;
- private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (IsRbnOpen)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- if(I>10010)
- {
- long time = Timestamp();
- //string FilePathName = ImgPath + RsImgName.Count + ".png";
- string path = CameraHelper.CaptureImage(@"G:\103", time.ToString());
- if (!string.IsNullOrWhiteSpace(path))
- {
- RbnOpen.Add(path);
- imgPlayer.Source = new BitmapImage(new Uri(path));
- }
- }
- I++;
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
- }
- /// <summary>
- /// 摄像头关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
- {
- IsRbnOpen = false;
- imgPlayer.Visibility = Visibility.Hidden;
- CameraHelper.CloseDevice();
- I = 9999;
- }
- #endregion
- #endregion
- /// <summary>
- /// 录屏事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- if (APP.W_ScreenRecordingToolbarWindow == null)
- {
- APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
- {
- Topmost = true
- };
- APP.W_ScreenRecordingToolbarWindow.Initialize();
-
- }
- else
- {
- APP.W_ScreenRecordingToolbarWindow.Initialize();
- }
- //显示在右下角
-
- APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 10;
- APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 160;
- APP.W_ScreenRecordingToolbarWindow.Topmost = true;
- APP.W_ScreenRecordingToolbarWindow.Show();
- Hide();
- }
- /// <summary>
- /// 上传事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- FileDirectoryWindow fileDirectoryWindow = new FileDirectoryWindow();
- fileDirectoryWindow.Show();
- }
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDown_Click(object sender, RoutedEventArgs e)
- {
- APP.SaveWkData();
- System.Environment.Exit(0);
- }
- /// <summary>
- /// 设置 保存事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnSave_Click(object sender, RoutedEventArgs e)
- {
- //#region 合法性判断
- //if (string.IsNullOrWhiteSpace(txbStoragePath.Text.Trim()))
- //{
- // System.Windows.MessageBox.Show("路径不可为空!");
- // return;
- //}
- //string temp = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
- //if (!APP.WKData.WkPath.Equals(temp))
- //{
- // APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + APP.WKData.WkName.Trim() + "/";
- // if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
- // {
- // //微课已存在
- // MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
- // if (dr == MessageBoxResult.OK)
- // {
- // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
- // }
- // else
- // {
- // return;
- // }
- // }
- // //创建文件夹
- // FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
- //}
- //#endregion
-
-
- if (rbnMP4.IsChecked == true)
- {
- //存储文件
- FileToolsCommon.SetConfigValue("VideoType", "1");
- }
- else if (rbnFLV.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "2");
- }
- else
- {
- FileToolsCommon.SetConfigValue("VideoType", "3");
- }
- if (rbnY.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("IsSound", "true");
- }
- else
- {
- FileToolsCommon.SetConfigValue("IsSound", "false");
- }
- GridMain.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 设置事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnSetUp_Click(object sender, RoutedEventArgs e)
- {
- GridMain.Visibility = Visibility.Collapsed;
- gridSetUp.Visibility = Visibility.Visible;
- txbStoragePath.Content = APP.WKData.WkPath;
- }
- /// <summary>
- /// 设置 浏览事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBrowse_Click(object sender, RoutedEventArgs e)
- {
-
-
- System.Diagnostics.Process.Start(APP.WKData.WkPath);
- //string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- //Ofd = new System.Windows.Forms.FolderBrowserDialog();
-
- //Result = Ofd.ShowDialog();
- //if (Result == System.Windows.Forms.DialogResult.OK)
- //{
- // if (Ofd.SelectedPath != "")
- // {
-
-
- // //txbStoragePath.Text = Ofd.SelectedPath;
- // //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
- // //string temp = ofd.SelectedPath;
- // //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
- // }
- //}
- }
- /// <summary>
- /// 画笔颜色事件 白色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnWhite_Click(object sender, RoutedEventArgs e)
- {
- ////创建 DrawingAttributes 类的一个实例
- //drawingAttributes = new DrawingAttributes();
- ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- ////设置 DrawingAttributes 的 Color 属性设置颜色
- drawingAttributes.Color = Colors.White;
- }
- /// <summary>
- /// 画笔颜色事件 红色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRed_Click(object sender, RoutedEventArgs e)
- {
-
- //设置 DrawingAttributes 的 Color 属性设置颜色
- drawingAttributes.Color = Colors.Red;
- }
- /// <summary>
- /// 画笔颜色事件 灰色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnGray_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Gray;
- }
- /// <summary>
- /// 画笔颜色事件 青色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.LimeGreen;
- }
- /// <summary>
- /// 画笔颜色事件 黄色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnYellow_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Gold;
- }
- /// <summary>
- /// 画笔颜色事件 蓝色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.DeepSkyBlue;
- }
- /// <summary>
- /// 画笔粗细事件 细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnFine_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 1;
- drawingAttributes.Height = 1;
- }
- /// <summary>
- /// 画笔粗细事件 中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnIn_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 3;
- drawingAttributes.Height = 3;
- }
- /// <summary>
- /// 画笔粗细事件 粗
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnCrude_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 5;
- drawingAttributes.Height = 5;
- }
- /// <summary>
- /// 登陆事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnLoginType_Click(object sender, RoutedEventArgs e)
- {
- Login();
- }
- /// <summary>
- /// 登陆
- /// </summary>
- private void Login()
- {
- if (APP.W_LoginWindow == null)
- {
- APP.W_LoginWindow = new LoginWindow();
-
- }
- else
- {
- APP.W_LoginWindow.Initialize();
- }
- APP.W_LoginWindow.ShowDialog();
- if (APP.IsLoginType)
- {
- txbLoginType.Text = APP.UserInfo.Username;
- }
- else
- {
- txbLoginType.Text = "未登录";
- }
- }
- /// <summary>
- /// 截图事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- string time = GetTimeStamp();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
- ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath);
-
- if (APP.W_JieTuWindow != null)
- {
- APP.W_JieTuWindow.initialization();
- APP.W_JieTuWindow.Screenshot();
- APP.W_JieTuWindow.WindowState = WindowState.Maximized;
- APP.W_JieTuWindow.Visibility = Visibility.Visible;
- }
- else
- {
- APP.W_JieTuWindow = new JieTuWindow();
- // 订阅事件
- APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
- APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
- APP.W_JieTuWindow.Show();
- }
-
- //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
- }
- /// <summary>
- /// 截图关闭窗口
- /// </summary>
- /// <param name="text"></param>
- private void frm_ChangeTextEvent(string text)
- {
- if ("关闭窗口".Equals(text))
- {
- if(!string.IsNullOrWhiteSpace(APP.ImgPath)&&File.Exists(APP.ImgPath))
- {
- APP.JPaths[APP.pageData.currpage]= APP.ImgPath;
- if(!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
- }
- }
- }
- }
- /// <summary>
- /// 截图关闭 非正常关闭截图时,截图清空
- /// </summary>
- private void JietuWindow_click_closeJietuWindowClick()
- {
- APP.W_JieTuWindow = null;
- }
- /// <summary>
- /// 获取时间戳
- /// </summary>
- /// <returns></returns>
- public string GetTimeStamp()
- {
- TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- return Convert.ToInt64(ts.TotalSeconds).ToString();
- }
- /// <summary>
- /// 导入事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnImport_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- try
- {
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- ofd = new System.Windows.Forms.OpenFileDialog
- {
- Filter = "文档|*.docx;*.doc;*ppt",
- InitialDirectory = desktopPath,
- Multiselect = false,
- AddExtension = true,
- DereferenceLinks = true
- };
-
- new Thread(
- o =>
- {
- Thread.Sleep(400);
- Dispatcher.Invoke(new Action(() =>
- {
- OpenDialog();
- }
- ));
- })
- {
- IsBackground = true
- }.Start();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
- }
- }
- private void OpenDialog()
- {
- result = ofd.ShowDialog();
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- if (ofd.FileName != "")
- {
- #region PPT转PDF
- string filepath = ofd.FileName;
- string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
- string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
- if (type.Contains("typezsygppt"))
- {
- try
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- path = pathTemp + path + ".pdf";
- //PPT转PDF
- Presentation ppt = new Presentation(filepath);
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
- #endregion
-
-
- #region PDF转图片
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
- //aspose许可证
- //Aspose.Pdf.License l = new Aspose.Pdf.License();
- //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
- //l.SetLicense(licenseName);
- //定义Jpeg转换设备
- Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
- var device = new Aspose.Pdf.Devices.JpegDevice();
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (var i = 1; i <= document.Pages.Count; i++)
- {
- long ii = Timestamp();
- string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
- images.Add(filePathOutPut);
- FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
- try
- {
- device.Process(document.Pages[i], fs);
- fs.Close();
- }
- catch (Exception ex)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
- #endregion
-
- APP.Paths = images.ToArray();
- ImgPDFPath = images.ToArray();
- for (int i = 0; i < APP.Paths.Length; i++)
- {
- APP.pageData.pagenum += 1;
- }
- if (APP.pageData.pagenum > 1)
- {
- APP.pageData.pagenum -= 1;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
- }
- else
- {
- imgCanvas.Source = null;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
-
- for (int i = 0; i < APP.Paths.Length; i++)
- {
- APP.pageData.pagenum += 1;
- }
- if (APP.pageData.pagenum > 1)
- {
- APP.pageData.pagenum -= 1;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
- }
- else
- {
- imgCanvas.Source = null;
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
- }
- }
-
-
- }
- }
- }
- /// <summary>
- /// 返回一个时间戳到毫秒
- /// </summary>
- /// <returns></returns>
- public static long Timestamp()
- {
- TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
- long timestr = Convert.ToInt64(ts.TotalMilliseconds);
- return timestr;
- }
- #region 录制窗口
- #region 变量
- /// <summary>
- /// 视频保存路径
- /// </summary>
- string RecordingPath;
- /// <summary>
- /// 图片保存路径
- /// </summary>
- string ImgPath;
- /// <summary>
- /// 音频保存路径名
- /// </summary>
- string AudioPathName;
- /// <summary>
- /// 视频保存路径名
- /// </summary>
- string VideoSavePathName;
- /// <summary>
- /// 暂停录制
- /// </summary>
- bool IsSuspendR = true;
- /// <summary>
- /// 是否首次录制
- /// </summary>
- bool IsFirstR = true;
- /// <summary>
- /// 图片
- /// </summary>
- List<string> RsImgName = null;
- /// <summary>
- /// 是否开始截图计数
- /// </summary>
- bool IsStartCount = false;
- #endregion
- /// <summary>
- /// 录制窗口内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnRecord_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
-
- blackboard_canvas.Visibility = Visibility.Visible;
- StartRecord();
- }
- /// <summary>
- /// 停止录制窗口内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnStop_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- blackboard_canvas.Visibility = Visibility.Collapsed;
- EndRecord();
- }
- System.Timers.Timer timer;
- /// <summary>
- /// 开始录制和暂停录制
- /// </summary>
- void StartRecord()
- {
- if (IsSuspendR)
- {
- if (IsFirstR)//是否第一次录制 初始化录制
- {
- VideoInfo = new Model_Video();
- VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
- VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
- RecordingPath = APP.WKData.WkPath;
- ImgPath = APP.WKData.WkPath + "temp/Image/";
- AudioPathName = APP.WKData.WkPath + "temp/audio/";
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
- FileToolsCommon.CreateDirectory(RecordingPath);
- FileToolsCommon.CreateDirectory(ImgPath);
- FileToolsCommon.CreateDirectory(AudioPathName);
- AudioPathName += APP.WKData.WkName + ".MP3";
- VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
-
- if (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- try
- {
- FileToolsCommon.DeleteFile(VideoSavePathName);
- APP.VideoList.RemoveAll(x => x.VidePath == VideoSavePathName);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
- }
- }
- else
- {
- return;
- }
- }
- IsFirstR = false;
- RsImgName = new List<string>();
- timer = new System.Timers.Timer(200);//设置执行一次(false)还是一直执行(true)
- timer.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
- timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
- timer.Enabled = true; //启动计时器
- }
- #region 录像倒计时
- if (APP.W_CountdownWindow == null)
- {
- APP.W_CountdownWindow = new CountdownWindow();
- //APP.W_CountdownWindow.Topmost = true;
- }
- else
- {
- APP.W_CountdownWindow.Initialize();
- APP.W_CountdownWindow.Topmost = true;
- }
- APP.W_CountdownWindow.Show();
- #endregion
- //继续录制
- IsSuspendR = false;
- //BtnRecording.Content = "暂停录制";
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
- TxbRecordingWord.Text = "暂停";
- try
- {
- APP.FFmpeg.StartRecordingAudio(AudioPathName);
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(1000);
- Dispatcher.Invoke(() =>
- {
- IsStartCount = true;
- //timer.Start();
- });
- }))).Start();
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show(ex.Message);
- }
- }
- else
- {
- //暂停
- IsSuspendR = true;
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
- TxbRecordingWord.Text = "继续";
- try
- {
- APP.FFmpeg.SuspendFFmpeg();
- new Thread(new ThreadStart(new Action(() =>
- {
- while (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- IsStartCount = false;
- }))).Start();
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show(ex.Message);
- }
- }
- }
- /// <summary>
- /// 录制保存图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (IsStartCount)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- string FilePathName = ImgPath + RsImgName.Count + ".png";
- ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)this.ActualWidth, (int)this.ActualHeight);
- RsImgName.Add(FilePathName);
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
- }
- /// <summary>
- /// 停止录制并生成录制文件
- /// </summary>
- void EndRecord()
- {
- if (!IsFirstR)
- {
- IsFirstR = true;
- IsSuspendR = true;
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
- TxbRecordingWord.Text = "录制";
- try
- {
- APP.FFmpeg.StopFFmpeg(AudioPathName);
- new Thread(new ThreadStart(new Action(() =>
- {
- while (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- Dispatcher.Invoke(() =>
- {
- IsStartCount = false;
- timer.Stop();
- });
- }))).Start();
-
- new Thread(new ThreadStart(new Action(() =>
- {
- while (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- }))).Start();
- APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.Width, (int)GridMain.Height);
- //生成缩略图
- string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
- new Thread(new ThreadStart(new Action(() =>
- {
- while (!FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- Thread.Sleep(100);
- }
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
- VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- VideoInfo.VidePath = VideoSavePathName;
- VideoInfo.ThumbnailPath = ThumbnailPathName;
- APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
- APP.VideoList.Add(VideoInfo);
- //保存数据
- APP.SaveWkData();
- }))).Start();
- //List<Model_Video> VideoList
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show(ex.Message);
- }
- }
- }
- #endregion
-
- /// <summary>
- /// 增加事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- APP.pageData.pagenum += 1;
- APP.pageData.currpage = APP.pageData.pagenum;
- myblackboard.changepage(APP.pageData.currpage - 1);
- imgCanvas.Source = null;
- }
- /// <summary>
- /// 打印事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPrint_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
-
- //for(int i=0;i< APP.pageData.pagenum; i++)
- //{
-
- //}
-
-
-
- ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
- iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
- try
- {
- //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
- //设置纸张横向
- document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
-
-
- iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
- document.Open();
- iTextSharp.text.Image image;
- for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
- {
- if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
-
-
- image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
-
-
- if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
- }
- else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
- }
- image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
- document.NewPage();
- document.Add(image);
- //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
- //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
- //p1.Leading = 150; //行间距
- //document.Add(p1);
- }
- Console.WriteLine("转换成功!");
- document.Close();
- }
- catch (Exception ex)
- {
- Console.WriteLine("转换失败,原因:" + ex.Message);
- }
- //document.Close();
- ////Console.ReadKey();
-
- int pr = 1;
- string msg = string.Empty;
- string outPut = string.Empty;
- LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
- if(pr==0)
- {
- outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
- APP.OutPut = outPut.Split(',');
- string defa = string.Empty;
- List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
-
- int printResult = 1;
- string standardError = string.Empty;
- string standardOutput = string.Empty;
- LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
-
- }
- }
- /// <summary>
- /// 我的
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnMyMine_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- }
- /// <summary>
- /// 上一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void last_button_Click(object sender, RoutedEventArgs e)
- {
- if (APP.pageData.currpage > 1)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
- FileToolsCommon.CreateDirectory(filePath);
- string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
- ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
- ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
- }
- APP.pageData.currpage -= 1;
- myblackboard.changepage(APP.pageData.currpage - 1);
- if (APP.Paths.Length > 0)
- {
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length&& APP.pageData.currpage > 0)
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
- }
- else
- {
- imgCanvas.Source = null;
- }
- }
- if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
- }
- }
-
- }
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void next_btn_Click(object sender, RoutedEventArgs e)
- {
- if (APP.pageData.currpage < APP.pageData.pagenum)
- {
- try
- {
- Dispatcher.Invoke(() =>
- {
- string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
- FileToolsCommon.CreateDirectory(filePath);
- string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
- ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
- ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
- });
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
- }
- APP.pageData.currpage += 1;
- myblackboard.changepage(APP.pageData.currpage - 1);
- if (APP.Paths.Length > 0)
- {
-
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
- }
- else
- {
- imgCanvas.Source = null;
- }
- }
- if (!string.IsNullOrWhiteSpace(APP.JPaths[APP.pageData.currpage]))
- {
- imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
- }
- }
- }
- /// <summary>
- /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
- /// "ImageFile", 1, 20, ImageFormat.Png, 256);
- /// </summary>
- /// <param name="pdfInputPath">Word文件路径</param>
- /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
- /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
- /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
- /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
- /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
- /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
- public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
- string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
- {
- // 返回的图片绝对路径集合
- List<string> images = new List<string>();
- try
- {
- // open word file
- Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
- // validate parameter
- if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
- if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
- if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
- if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
- if (startPageNum <= 0) { startPageNum = 1; }
- if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
- if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
- if (imageFormat == null) { imageFormat = ImageFormat.Png; }
- if (resolution <= 0) { resolution = 128; }
-
- ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
- {
- Resolution = resolution
- };
-
- // start to convert each page
- for (int i = startPageNum; i <= endPageNum; i++)
- {
- imageSaveOptions.PageIndex = i - 1;
- doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
- images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
- APP.num++;
- }
- imageSaveOptions = null;
- doc = null;
- }
- catch (Exception ex)
- {
- System.Windows.MessageBox.Show("文档已打开,请关闭后重试!");
- LogHelper.WriteErrLog("【课堂考试(ExamWindow)】错误日志:" + ex.Message, ex);
- }
- return images;
- }
- private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
- {
- SaveFormat sf;// = SaveFormat.Unknown;
- if (imageFormat.Equals(ImageFormat.Png))
- {
- sf = SaveFormat.Png;
- }
- else if (imageFormat.Equals(ImageFormat.Jpeg))
- {
- sf = SaveFormat.Jpeg;
- }
- else if (imageFormat.Equals(ImageFormat.Tiff))
- {
- sf = SaveFormat.Tiff;
- }
- else if (imageFormat.Equals(ImageFormat.Bmp))
- {
- sf = SaveFormat.Bmp;
- }
- else
- {
- sf = SaveFormat.Unknown;
- }
-
- return sf;
- }
-
- #region 图像缩放,移动
- private bool mouseDown;
- private System.Windows.Point mouseXY;
- private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- img.CaptureMouse();
- mouseDown = true;
- mouseXY = e.GetPosition(img);
- Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
-
- }
- private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
- {
- System.Windows.Point point = e.GetPosition(imgCanvas);
- //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
- //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
- //{
- // Console.WriteLine("在范围内");
- //}
- }
- private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- var img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- img.ReleaseMouseCapture();
- mouseDown = false;
- }
- private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
- {
- var img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- if (mouseDown)
- {
- Domousemove(img, e);
- }
- }
- private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton != MouseButtonState.Pressed)
- {
- return;
- }
- var group = IMG.FindResource("Imageview") as TransformGroup;
- var transform = group.Children[1] as TranslateTransform;
- var position = e.GetPosition(img);
- transform.X -= mouseXY.X - position.X;
- transform.Y -= mouseXY.Y - position.Y;
- mouseXY = position;
- }
- private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
- {
- var img = sender as ContentControl;
- if (img == null)
- {
- return;
- }
- var point = e.GetPosition(img);
- Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
- var PicLocate = e.GetPosition(imgCanvas);
- Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
-
-
- var group = IMG.FindResource("Imageview") as TransformGroup;
- var delta = e.Delta * 0.001;
- DowheelZoom(group, point, delta);
- }
- private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
- {
- var pointToContent = group.Inverse.Transform(point);
- var transform = group.Children[0] as ScaleTransform;
- if (transform.ScaleX + delta < 0.1) return;
- transform.ScaleX += delta;
- transform.ScaleY += delta;
- var transform1 = group.Children[1] as TranslateTransform;
- transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
- transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
- //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
- }
- #endregion
-
- #region 点阵笔相关
-
- #region 值初始化
- // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
-
- /// <summary>
- /// A4点阵纸点阵宽度
- /// </summary>
- private const int A4_WIDTH = 5600;
-
- /// <summary>
- /// A4点阵纸点阵高度
- /// </summary>
- private const int A4_HEIGHT = 7920;
-
- /// <summary>
- /// 画板
- /// </summary>
- private Graphics graphics;
-
- /// <summary>
- /// 笔画坐标数组
- /// </summary>
- private List<System.Drawing.Point> stroke;
-
- /// <summary>
- /// 笔序列号
- /// </summary>
- private string penSerial;
-
- /// <summary>
- /// 笔是否在点
- /// </summary>
- private bool isPenDown;
-
- //当前点阵地址
- private string currentPageSerial = string.Empty;
-
- //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
- //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
- private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
- #endregion
- public void InitPen()
- {
- stroke = new List<System.Drawing.Point>();
- //获取点阵笔实例,并绑定点阵笔事件
- //将授权文件内容传入,获取点阵笔对象实例
- APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
- //绑定笔连接事件
- APP.digitalPen.PenConnected += OnPenConnect;
- //绑定笔断开事件
- APP.digitalPen.PenDisconnect += OnPenDisconnect;
- //绑定笔书写输出坐标事件
- APP.digitalPen.PenCoordinate += OnPenCoordinate;
- //绑定抬笔事件
- APP.digitalPen.PenUp += OnPenUp;
- //绑定落笔事件
- APP.digitalPen.PenDown += OnPenDown;
- APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
- APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
- //完成初始化点阵笔,开始与点阵笔通信
- ERROR_CODE ER = APP.digitalPen.Start();
-
- ////绑定笔在新的点阵地址页面书写事件
- //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
- ////绑定笔信息事件
- //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
- //启动接收笔数据,完成初始化工作
- ERROR_CODE rc = APP.digitalPen.Start();
- //判断是否成功
- if (ER != ERROR_CODE.ERROR_OK)
- {
- System.Windows.MessageBox.Show("初始化失败,授权过期,返回值:" + ER.ToString());
- }
- }
-
-
- /// <summary>
- /// 落笔
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenDown(ulong time, string penSerial, int penType)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
- this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- //labPenSerial.Text = penSerial;
- //labPenStatus.Text = "PenDown";
- isPenDown = true;
- }
- //myblackboard.changepages(0, 0, true);
- }
-
- /// <summary>
- /// 抬笔
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenUp(ulong time, string penSerial, int penType)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
- this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- isPenDown = false;
- APP.PenSerial = penSerial;
- //int leftPoints = stroke.Count % 3;
- //if (0 != leftPoints)
- //{
- // int from = stroke.Count - leftPoints - 1;
- // if (from < 0)
- // from = 0;
- // int to = stroke.Count - 1;
- // DrawCoordinates(from, to);
- //}
- stroke.Clear();
- }
- Dispatcher.Invoke(new Action(() =>
- {
- //myblackboard.changepages(0, 0, true);
- myblackboard.changepaget(0, 0, true, blackboard_canvas);
- }));
-
- }
-
- /// <summary>
- /// 笔断开
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenDisconnect(ulong time, string penSerial, int penType)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
- this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- APP.PenSerial = penSerial;
- APP.PenStatus = false;
-
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "未连接";
- txbNotConnecteds.Text = "未连接";
- }));
- }
- }
-
- /// <summary>
- /// 笔连接
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- private void OnPenConnect(ulong time, string penSerial, int penType)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
- this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
- }
- else
- {
- APP.PenSerial = penSerial;
- APP.PenStatus = true;
- this.penSerial = penSerial;
- //连接后,在获取笔数据前,可以清除笔内的历史数据
- //APP.digitalPen.ClearMemory(penSerial);
-
- //开始接收笔数据
- APP.digitalPen.GetPenData(penSerial);
- Dispatcher.Invoke(new Action(() =>
- {
- txbNotConnected.Text = "已连接";
- txbNotConnecteds.Text = "已连接";
- }));
-
- }
- }
- /// <summary>
- /// 电池电量
- /// </summary>
- /// <param name="time"></param>
- /// <param name="penSerial"></param>
- /// <param name="penType"></param>
- /// <param name="capacity"></param>
- private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
- this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
- }
- else
- {
- //System.Windows.MessageBox.Show("电池电量:" + capacity.ToString());
- }
- }
-
- /// <summary>
- /// 已用存储
- /// </summary>
- /// <param name="time"></param>
- /// <param name="penSerial"></param>
- /// <param name="penType"></param>
- /// <param name="fillLevel"></param>
- private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
- this.Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
- }
- else
- {
- //System.Windows.MessageBox.Show("存储:" + fillLevel.ToString());
- }
- }
-
- /// <summary>
- /// 笔书写,收到坐标
- /// </summary>
- /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
- /// <param name="penSerial">点阵笔序列号</param>
- /// <param name="penType">点阵笔型号编号</param>
- /// <param name="pageSerial">点阵地址</param>
- /// <param name="cx">x坐标</param>
- /// <param name="cy">y坐标</param>
- /// <param name="force">压力值</param>
- private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
- {
- if (this.CheckAccess())
- {
- Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
- this.Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
- }
- else
- {
- //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
- if (!isPenDown)
- {
- return;
- }
- stroke.Add(new System.Drawing.Point(cx, cy));
-
- double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
- double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
- //点
- double testX=(double)cx * PropW;
- double testY=(double)cy * PropH;
- //pageSerial //点阵IP地址 与打印的页面关联
-
- Dispatcher.Invoke(new Action(() =>
- {
- //myblackboard.changepages(testX, testY,false);
- myblackboard.changepaget(testX, testY, false, blackboard_canvas);
- }));
-
-
- ////每3个点画一条曲线
- //if (stroke.Count % 3 == 0)
- //{
- // int from = stroke.Count - 3 - 1;
- // if (from < 0)
- // from = 0;
- // int to = stroke.Count - 1;
- // DrawCoordinates(from, to);
- //}
- }
- }
-
- /// <summary>
- /// 停止笔
- /// </summary>
- public void StopDigitalPen()
- {
- //停止,释放资源
- APP.digitalPen.Stop();
- }
- /// <summary>
- /// 清空笔内存储
- /// </summary>
- public void ClearPenStorage()
- {
- if (!string.IsNullOrEmpty(penSerial))
- APP.digitalPen.ClearMemory(penSerial);
- }
- /// <summary>
- /// 获取剩余电量
- /// </summary>
- public void GetPenElectricityQuantity()
- {
- if (!string.IsNullOrEmpty(penSerial))
- APP.digitalPen.GetBatteryCapacity(penSerial);
- }
-
- /// <summary>
- /// 获取存储空间
- /// </summary>
- public void GetUsedStorage()
- {
- if (!string.IsNullOrEmpty(penSerial))
- APP.digitalPen.GetMemoryFillLevel(penSerial);
- }
-
- /// <summary>
- /// 开启悬浮
- /// </summary>
- public void 开启悬浮()
- {
- if (!string.IsNullOrEmpty(penSerial))
- APP.digitalPen.SetPenHoverMode(true, penSerial);
- }
-
- /// <summary>
- /// 关闭悬浮
- /// </summary>
- public void 关闭悬浮()
- {
- if (!string.IsNullOrEmpty(penSerial))
- APP.digitalPen.SetPenHoverMode(false, penSerial);
- }
- #endregion
- /// <summary>
- /// 最小化
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnShrink_Click(object sender, RoutedEventArgs e)
- {
- if(Visibility== Visibility.Hidden)
- Visibility = Visibility.Visible;
- else
- Visibility = Visibility.Hidden;
- }
- }
- }
|