12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169 |
- 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;
-
- 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;
- //定义事件
- public event ChangeTextHandler ChangeTextEvent;
- //定义委托
- public delegate void ChangeTextHandler(string text);
- #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.Text = FileToolsCommon.GetConfigValue("VideoType");
- if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
- {
- rbnY.IsChecked = true;
- }
- else
- {
- rbnN.IsChecked = true;
- }
- txbStoragePath.Text = FileToolsCommon.GetConfigValue("VideoSavePath");
- Initialize();
- }
- /// <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;
- }
- #endregion
-
- #region 事件
- /// <summary>
- /// 窗体移动
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
- /// <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);
- }
- }
- /// <summary>
- /// 摄像头关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
- {
- wfhCamera.Visibility = Visibility.Hidden;
- CameraHelper.CloseDevice();
- }
- #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)
- {
- 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;
- }
- /// <summary>
- /// 设置 浏览事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBrowse_Click(object sender, RoutedEventArgs e)
- {
- 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(() =>
- {
- OpenDialogPPT();
- }
- ));
- })
- {
- 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 != "")
- {
- string filepath = ofd.FileName;
- string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- APP.Paths = ConvertWordToImage(filepath, path, "", 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;
- }
- }
- }
- }
- private void OpenDialogPPT()
- {
- 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 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();
-
- 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;
- }
- }
- }
- }
- /// <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)//是否第一次录制 初始化录制
- {
- 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 + "_录制." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
- if (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- MessageBoxResult dr = System.Windows.MessageBox.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
- if (dr == MessageBoxResult.OK)
- {
- FileToolsCommon.DeleteFile(VideoSavePathName);
- }
- 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 保存图片
- //new Thread(new ThreadStart(new Action(() =>
- //{
- // while (true)
- // {
- // Thread.Sleep(200);
- // if (IsStartCount)
- // {
- // ImgNum++;
- // Dispatcher.Invoke(() =>
- // {
- // lblNumber.Content = ImgNum;
- // string FilePathName = ImgPath + ImgNum + ".png";
- // ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
- // });
- // }
- // }
- //}))).Start();
- #endregion
- }
- #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)GridMain.ActualWidth, (int)GridMain.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);
- APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
- }))).Start();
-
- }
- 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)
- {
-
- }
- /// <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)
- {
- 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)
- {
- 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
- }
- }
|