12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654 |
- 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;
- using XHWK.WKTool.DAL;
- using System.Text;
- using System.Collections.Specialized;
- using XHWK.WKTool.Config;
- using System.Windows.Threading;
-
- 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];
- /// <summary>
- /// 当前颜色
- /// </summary>
- private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
- /// <summary>
- /// 笔迹粗细
- /// </summary>
- private int PenSize = 2;
- private DispatcherTimer t = null;
- /// <summary>
- /// 计时器状态
- /// </summary>
- private enum State
- {
- Start,
- Pause,
- End
- }
- /// <summary>
- /// 状态
- /// </summary>
- private State _state = State.End;
- /// <summary>
- /// 计时用
- /// </summary>
- private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
- #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();
- this.ResizeMode = System.Windows.ResizeMode.CanMinimize;
- btnPrint.IsEnabled = false;
-
- myblackboard = new BlackboardNew(blackboard_canvas);
- APP.pageData.pagenum = 0;
- APP.pageData.currpage = 0;
- DataContext = APP.pageData;
-
- //APP.SaveDraw();//画板模型第一页初始化
- APP.PageDrawList = new List<Model_DrawData>();
- Model_DrawData model_DrawData = new Model_DrawData();
- model_DrawData.PageNum = APP.pageData.currpage;
- APP.PageDrawList.Add(model_DrawData);
- txbv.Text = "v"+ZConfig.versionName;
- 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()
- {
- #region 数据初始化
- APP.pageData.pagenum = 0;
- APP.pageData.currpage = APP.pageData.pagenum;
- btnStop.IsEnabled = false;//停止录制按钮不可点击
- #endregion
-
-
-
- APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- //创建 DrawingAttributes 类的一个实例
- drawingAttributes = new DrawingAttributes();
- //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
- blackboard_canvas.UseCustomCursor = true;
- drawingAttributes.FitToCurve = true;
- drawingAttributes.IgnorePressure = false;
- drawingAttributes.Width = PenSize;
- drawingAttributes.Height = PenSize;
- drawingAttributes.Color = Color;
- blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
- //wfhCamera.Visibility = Visibility.Hidden;
- ImgPDFPath = null;
- ImgPDFPath = new string[300];
-
- }
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Stack()
- {
- _state = State.Start;
- }
- /// <summary>
- /// 暂停
- /// </summary>
- private void TimeOut()
- {
- _state = State.Pause;
- }
- /// <summary>
- /// 结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void End()
- {
- _state = State.End;
- }
- /// <summary>
- /// 时钟回调
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnTimer(object sender, EventArgs e)
- {
- switch (_state)
- {
- case State.Start:
- {
- _timeSpan += new TimeSpan(0, 0, 0, 1);
- }
- break;
-
- case State.Pause:
- {
- }
- break;
-
- case State.End:
- {
- _timeSpan = new TimeSpan();
- //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
- }
- break;
- }
-
- string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
- txbTime.Text = time;
- //txbTime.Text = time;
- }
- /// <summary>
- /// 修改布局
- /// </summary>
- public void SetUpLayout()
- {
- //宽高比1276,1040
- //double AspectRatio = 1276.0 / 1040.0;
- ////System.Drawing.Size des = PrimaryScreen.DESKTOP;
- //System.Drawing.Size workingArea = PrimaryScreen.WorkingArea;
- //this.Height = workingArea.Height;
-
- }
- #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);
- RbnOpen = new List<string>();
- times = new System.Timers.Timer(300);//设置执行一次(false)还是一直执行(true)
- times.AutoReset = true;//设置是否执行System.Timers.Timer.Elapsed事件
- times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
- times.Enabled = true; //启动计时器
-
- IsRbnOpen = true;
-
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- FileToolsCommon.CreateDirectory(imgPath);
- }
- }
-
- 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 imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- //string FilePathName = ImgPath + RsImgName.Count + ".png";
- string path = CameraHelper.CaptureImage(imgPath, time.ToString());
- if (!string.IsNullOrWhiteSpace(path))
- {
- RbnOpen.Add(path);
- imgPlayerRight.Visibility = Visibility.Visible;
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if ("1".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Visible;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRight.Source = new BitmapImage(new Uri(path));
- }
- else if ("2".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Visible;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Source = new BitmapImage(new Uri(path));
- }
- else if ("3".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Visible;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
- }
- else if ("4".Equals(APP.CameraPosition))
- {
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Visible;
- imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
- }
- else
- {
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- imgPlayerRight.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;
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- 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.CheckScreenCapturerRecorder())
- {
- MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
- APP.InstallScreenCapturerRecorder();
- return;
- }
- #region 限制只允许录制一个录屏 废弃
- //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
- //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
- //{
- // MessageBoxResult dr = MessageWindow.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
- // if (dr == MessageBoxResult.OK)
- // {
- // try
- // {
- // FileToolsCommon.DeleteFile(RecordScreenPathName);
- // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
- // }
- // catch (Exception ex)
- // {
- // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
- // }
- // }
- // else
- // {
- // return;
- // }
- //}
- #endregion
- if (APP.W_ScreenRecordingToolbarWindow == null)
- {
- APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
- {
- Topmost = true
- };
- APP.W_ScreenRecordingToolbarWindow.Initialize();
-
- }
- else
- {
- APP.W_ScreenRecordingToolbarWindow.Initialize();
- }
- APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
- //显示在右下角
- APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
- APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 60;
- APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 30;
- APP.W_ScreenRecordingToolbarWindow.Topmost = true;
- APP.W_ScreenRecordingToolbarWindow.Show();
- Hide();
- }
- /// <summary>
- /// 保存录屏中
- /// </summary>
- private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
- {
- TxbRecordScreenWord.Text = "保存中";//
- btnScreenRecording.IsEnabled = false;
-
- new Thread(new ThreadStart(new Action(() =>
- {
- while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
- {
- Thread.Sleep(100);
- }
- Dispatcher.Invoke(() =>
- {
- btnScreenRecording.IsEnabled = true;
- TxbRecordScreenWord.Text = "录屏";
- });
- }))).Start();
-
- }
- /// <summary>
- /// 上传事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- if (APP.IsLoginType == false)
- {
- Login();
- return;
- }
- if (APP.fileDirectoryWindow == null)
- {
- APP.fileDirectoryWindow = new FileDirectoryWindow();
- //APP.fileDirectoryWindow.Topmost = true;
- APP.fileDirectoryWindow.Owner = this;
- }
- else
- {
- APP.fileDirectoryWindow.Initialize();
- }
- APP.fileDirectoryWindow.ShowDialog();
- }
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnDown_Click(object sender, RoutedEventArgs e)
- {
- if (IsFirstR)
- {
- APP.Killffmpeg();
- APP.SaveWkData();
- APP.SaveDraw();
- Thread.Sleep(100);
- System.Environment.Exit(0);
- }
- else
- {
- MessageWindow.Show("当前正在录制,请先停止录制。");
- return;
- //MessageBoxResult dr = MessageWindow.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
- //if (dr == MessageBoxResult.OK)
- //{
- // APP.SaveWkData();
- // APP.SaveDraw();
- // BtnStop_Click(null, null);
- // while (!IsFirstR)
- // {
- // Thread.Sleep(100);
- // }
- // System.Environment.Exit(0);
- //}
- //else
- //{
- // return;
- //}
- }
- }
- /// <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()))
- //{
- // MessageWindow.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 = MessageWindow.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
- // if (dr == MessageBoxResult.OK)
- // {
- // FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
- // }
- // else
- // {
- // return;
- // }
- // }
- // //创建文件夹
- // FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
- //}
- #endregion
-
- ImgRecord.Visibility = Visibility.Visible;//设置结束时可录制
- ImgRecordTwo.Visibility = Visibility.Collapsed;//设置结束时可录制
- BtnRecord.IsEnabled = true;//设置结束时可录制
- 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");
- }
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if (rbnRight.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "1");
- }
- else if (rbnLeft.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "2");
- }
- else if (rbnRightUnder.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "3");
- }
- else if (rbnLeftUnder.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("CameraPosition", "4");
- }
- APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- GridMain.Visibility = Visibility.Visible;
- gridSetUp.Visibility = Visibility.Collapsed;
- imgPlayerRight.Visibility = Visibility.Collapsed;
- imgPlayerLeft.Visibility = Visibility.Collapsed;
- imgPlayerRightUnder.Visibility = Visibility.Collapsed;
- imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 设置事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnSetUp_Click(object sender, RoutedEventArgs e)
- {
- if (!TxbRecordingWord.Text.Equals("暂停"))
- {
- GridMain.Visibility = Visibility.Collapsed;
- gridSetUp.Visibility = Visibility.Visible;
- txbStoragePath.Content = APP.WKData.WkPath;
- ImgRecord.Visibility = Visibility.Collapsed;//设置时不可录制
- ImgRecordTwo.Visibility = Visibility.Visible;//设置时不可录制
- BtnRecord.IsEnabled = false;//设置时不可录制
- /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- if ("1".Equals(APP.CameraPosition))
- {
- rbnRight.IsChecked = true;
- }
- else if ("2".Equals(APP.CameraPosition))
- {
- rbnLeft.IsChecked = true;
- }
- else if ("3".Equals(APP.CameraPosition))
- {
- rbnRightUnder.IsChecked = true;
- }
- else if ("4".Equals(APP.CameraPosition))
- {
- rbnLeftUnder.IsChecked = true;
- }
- }
- }
- /// <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;
- 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;
- Color = Colors.Red;
- imgRed.Visibility = Visibility.Visible;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 黑色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnGray_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Black;
- Color = Colors.Black;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Visible;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 青色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.LimeGreen;
- Color = Colors.LimeGreen;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Visible;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 黄色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnYellow_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.Gold;
- Color = Colors.Gold;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Visible;
- imgBlue.Visibility = Visibility.Collapsed;
- }
- /// <summary>
- /// 画笔颜色事件 蓝色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnBlue_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Color = Colors.DeepSkyBlue;
- Color = Colors.DeepSkyBlue;
- imgRed.Visibility = Visibility.Collapsed;
- imgGray.Visibility = Visibility.Collapsed;
- imgCyanBlue.Visibility = Visibility.Collapsed;
- imgYellow.Visibility = Visibility.Collapsed;
- imgBlue.Visibility = Visibility.Visible;
- }
- /// <summary>
- /// 画笔粗细事件 细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void RbnFine_Click(object sender, RoutedEventArgs e)
- {
- drawingAttributes.Width = 1;
- drawingAttributes.Height = 1;
- PenSize = 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;
- PenSize = 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;
- PenSize = 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();
- APP.W_LoginWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
- APP.W_LoginWindow.Owner = this;
-
- }
- else
- {
- APP.W_LoginWindow.Initialize();
- }
- APP.W_LoginWindow.ShowDialog();
- if (APP.IsLoginType)
- {
- txbLoginType.Text = APP.UserInfo.Username;
-
- ImgUpload.Visibility = Visibility.Visible;
- ImgUploadTwo.Visibility = Visibility.Collapsed;
- }
- else
- {
- txbLoginType.Text = "未登录";
-
- ImgUpload.Visibility = Visibility.Collapsed;
- ImgUploadTwo.Visibility = Visibility.Visible;
- }
- }
- /// <summary>
- /// 截图事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
- {
- string time = GetTimeStamp();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
- ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath,false,out BitmapImage bitmap);
- if (this.WindowState == WindowState.Normal)//截图隐藏窗口
- {
- this.WindowState = WindowState.Minimized;
- }
- 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 (this.WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- this.WindowState = WindowState.Normal;
- }
- if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
- {
- if (APP.pageData.currpage == 0)
- {
- APP.pageData.pagenum += 1;
- APP.pageData.currpage = APP.pageData.pagenum;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.PageDrawList.Count >= APP.pageData.currpage)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
- APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
- }
- else
- {
- Model_DrawData model_DrawData = new Model_DrawData();
- model_DrawData.PageImagePath = APP.ImgPath;
- model_DrawData.PdfImagePath = APP.ImgPath;
- APP.PageDrawList.Add(model_DrawData);
- }
- if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation = false;
- ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- }
- }
- }
- }
- /// <summary>
- /// 截图关闭 非正常关闭截图时,截图清空
- /// </summary>
- private void JietuWindow_click_closeJietuWindowClick()
- {
- if (this.WindowState == WindowState.Minimized)//截图完恢复窗口
- {
- this.WindowState = WindowState.Normal;
- }
- 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)
- {
- 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);
- }
- }
- /// <summary>
- /// 导入文档
- /// </summary>
- private void OpenDialog()
- {
- result = ofd.ShowDialog();
- if (result == System.Windows.Forms.DialogResult.OK)
- {
- if (ofd.FileName != "")
- {
- APP.myloading.Show();
-
- #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"))//ppt
- {
- 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
- string[] page = images.ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData();
- model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
- model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
- model_DrawData.PageNum = i + 1;
- model_DrawData.ImgDocumentation = true;
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else//word
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
- int num = 0;
- for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
- {
- if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
- {
- APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
- APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
- APP.PageDrawList[i].PageNum = i + 1;
- APP.PageDrawList[i].ImgDocumentation = true;
- }
- else
- {
-
- Model_DrawData model_DrawData = new Model_DrawData();
- model_DrawData.PageImagePath = page[i - APP.pageData.pagenum];
- model_DrawData.PdfImagePath = page[i - APP.pageData.pagenum];
- model_DrawData.PageNum = i + 1;
- model_DrawData.ImgDocumentation = true;
- APP.PageDrawList.Add(model_DrawData);
- }
- ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
- APP.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- APP.pageData.currpage = APP.pageData.pagenum + 1;
- APP.pageData.pagenum += num;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- }
- if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
- {
-
- imgCanvas.Source = null;
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- imgDocumentation.Visibility = Visibility.Visible;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = null;
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- APP.myloading.Hide();
- }
- catch (Exception ex)
- {
- APP.myloading.Hide();
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + 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.CheckScreenCapturerRecorder())
- {
- MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
- APP.InstallScreenCapturerRecorder();
- return;
- }
- if (APP.pageData.currpage > 0)
- {
- blackboard_canvas.Visibility = Visibility.Visible;
- }
- else
- {
- MessageWindow.Show("请先导入文档或截图!");
- return;
- }
-
- //btnStop.IsEnabled = true;//停止录制按钮可点击
- StartRecord();
- }
- /// <summary>
- /// 停止录制窗口内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnStop_Click(object sender, RoutedEventArgs e)
- {
- blackboard_canvas.Visibility = Visibility.Collapsed;
- EndRecord();
- }
- System.Timers.Timer timer;
-
- /// <summary>
- /// 设置录屏文件地址
- /// </summary>
- void SetUpVideoPathName()
- {
- }
- /// <summary>
- /// 开始录制和暂停录制
- /// </summary>
- void StartRecord()
- {
- if (IsSuspendR)
- {
- if (IsFirstR)//是否第一次录制 初始化录制
- {
- #region 计时器初始化
- if (t == null)
- {
- t = new DispatcherTimer();
- t.Tick += OnTimer;
- t.Interval = new TimeSpan(0, 0, 0, 1);
- t.IsEnabled = true;
- t.Start();
- }
- t.Interval = new TimeSpan(0, 0, 0, 1);
- txbTime.Visibility = Visibility.Visible;
- #endregion
-
- VideoInfo = new Model_Video();
- VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
- VideoInfo.WkType = Enum_WKVidetype.RecordingLessons;
-
- ImgPath = APP.WKData.WkPath + "temp/Image/";
- AudioPathName = APP.WKData.WkPath + "temp/audio/";
- FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
- FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
- FileToolsCommon.CreateDirectory(ImgPath);
- FileToolsCommon.CreateDirectory(AudioPathName);
- AudioPathName += APP.WKData.WkName + ".MP3";
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
- int num = 1;
- while (FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
- num++;
- }
-
- #region 设置录屏唯一 废弃
- //if (FileToolsCommon.IsExistFile(VideoSavePathName))
- //{
- // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
- // if (dr == MessageBoxResult.OK)
- // {
- // try
- // {
- // FileToolsCommon.DeleteFile(VideoSavePathName);
- // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
- // }
- // catch (Exception ex)
- // {
- // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
- // }
- // }
- // else
- // {
- // return;
- // }
- //}
- #endregion
-
- #region 禁用按钮
- ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
- ImgPrintTwo.Visibility = Visibility.Visible;
- btnPrint.IsEnabled = false;
-
- ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
-
- ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
- ImgImportTwo.Visibility = Visibility.Visible;
- btnImport.IsEnabled = false;
-
- ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
- ImgScreenRecordingTwo.Visibility = Visibility.Visible;
- btnScreenRecording.IsEnabled = false;
-
- ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
- ImgUploadTwo.Visibility = Visibility.Visible;
- btnUpload.IsEnabled = false;
-
- ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
- ImgSetUpTwo.Visibility = Visibility.Visible;
- btnSetUp.IsEnabled = false;
-
- btnLoginType.IsEnabled = false;
- #endregion
-
- #region 录像倒计时
- if (APP.W_CountdownWindow == null)
- {
- APP.W_CountdownWindow = new CountdownWindow();
- APP.W_CountdownWindow.Initialize();
- //APP.W_CountdownWindow.Topmost = true;
- }
- else
- {
- APP.W_CountdownWindow.Initialize();
- //APP.W_CountdownWindow.Topmost = true;
- }
- APP.W_CountdownWindow.Show();
- #endregion
- 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; //启动计时器
- }
-
- //继续录制
- IsSuspendR = false;
- //BtnRecording.Content = "暂停录制";
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
- ImgStop.Visibility = Visibility.Collapsed;
- ImgStopTwo.Visibility = Visibility.Visible;
- TxbRecordingWord.Text = "暂停";
- #region 2秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- btnStop.IsEnabled = false;
- });
- Thread.Sleep(2000);
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- });
- }))).Start();
- #endregion
- try
- {
- new Thread(new ThreadStart(new Action(() =>
- {
- Thread.Sleep(1000);
- APP.FFmpeg.StartRecordingAudio(AudioPathName);
- Thread.Sleep(1000);
- Dispatcher.Invoke(() =>
- {
- IsStartCount = true;
- Stack();
- //timer.Start();
- });
- }))).Start();
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- else
- {
- //暂停
- IsSuspendR = true;
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
- ImgStop.Visibility = Visibility.Visible;
- ImgStopTwo.Visibility = Visibility.Collapsed;
- TxbRecordingWord.Text = "继续";
- TimeOut();
- #region 2秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- btnStop.IsEnabled = false;
- });
- Thread.Sleep(2000);
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- });
- }))).Start();
- #endregion
- try
- {
- APP.FFmpeg.SuspendFFmpeg();
- new Thread(new ThreadStart(new Action(() =>
- {
- while (APP.FFmpeg.myProcess != null)
- {
- Thread.Sleep(100);
- }
- IsStartCount = false;
- }))).Start();
- }
- catch (Exception ex)
- {
- MessageWindow.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)
- {
- #region 恢复被禁用的按钮
- ImgPrint.Visibility = Visibility.Visible;
- ImgPrintTwo.Visibility = Visibility.Collapsed;
- btnPrint.IsEnabled = true;
-
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
-
- ImgImport.Visibility = Visibility.Visible;
- ImgImportTwo.Visibility = Visibility.Collapsed;
- btnImport.IsEnabled = true;
-
- ImgScreenRecording.Visibility = Visibility.Visible;
- ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
- btnScreenRecording.IsEnabled = true;
-
- ImgUpload.Visibility = Visibility.Visible;
- ImgUploadTwo.Visibility = Visibility.Collapsed;
- btnUpload.IsEnabled = true;
-
- ImgSetUp.Visibility = Visibility.Visible;
- ImgSetUpTwo.Visibility = Visibility.Collapsed;
- btnSetUp.IsEnabled = true;
-
- btnLoginType.IsEnabled = true;
-
-
- //btnStop.IsEnabled = false;//停止录制按钮不可点击
-
- #endregion
-
- IsSuspendR = true;
- ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
- ImgStop.Visibility = Visibility.Visible;
- ImgStopTwo.Visibility = Visibility.Collapsed;
- TimeOut();
- txbType.Text = "保存中";
- #region 2秒内不可点击
- new Thread(new ThreadStart(new Action(() =>
- {
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = false;
- btnStop.IsEnabled = false;
- });
- }))).Start();
- #endregion
- try
- {
- #region 清空画板数据
- APP.pageData.currpage = 0;
- APP.pageData.pagenum = 0;
- myblackboard.clear();
- APP.PageDrawList.Clear();
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- #endregion
-
- //缩略图
- string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(ThumbnailPath);
- //缩略图存储位置
- string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileNameNoExtension(VideoSavePathName) + ".JPG";
- int gridActWidth = (int)GridMain.ActualWidth;
- int gridActHeight = (int)GridMain.ActualHeight;
- 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(() =>
- //{
- //判断音频是否存在 判断音频临时文件夹是否存在
- if (!FileToolsCommon.IsExistFile(AudioPathName))
- {
- Thread.Sleep(100);
- }
- if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
- {
- Thread.Sleep(100);
- }
- APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, gridActWidth, gridActHeight);
- //}))).Start();
- //new Thread(new ThreadStart(new Action(() =>
- //{
- while (!FileToolsCommon.IsExistFile(VideoSavePathName))
- {
- Thread.Sleep(100);
- }
- while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSavePathName) + "temp/"))
- {
- Thread.Sleep(100);
- }
- Dispatcher.Invoke(() =>
- {
- BtnRecord.IsEnabled = true;
- btnStop.IsEnabled = true;
- TxbRecordingWord.Text = "录制";
- End();
- txbTime.Text = "";
- txbTime.Visibility = Visibility.Hidden;
- txbType.Text = "";
- });
- FileToolsCommon.DeleteFile(ThumbnailPathName);
- VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- Thread.Sleep(500);
- //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
- VideoInfo.VideoPath = VideoSavePathName;
- VideoInfo.ThumbnailPath = ThumbnailPathName;
- APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName);
- VideoInfo.FileGuid = Guid.NewGuid().ToString();
- VideoInfo.IsUpload = false;
- VideoInfo.Uploaded = 0;
- VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
- APP.VideoList.Add(VideoInfo);
- //保存数据
- APP.SaveWkData();
- IsFirstR = true;
- }))).Start();
- //List<Model_Video> VideoList
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- }
- }
- }
- #endregion
-
- /// <summary>
- /// 增加事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- if (APP.pageData.currpage > 0)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- }
- if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
- {
- blackboard_canvas.Visibility = Visibility.Visible;
- }
- APP.pageData.pagenum += 1;
- gridPage.Visibility = Visibility.Visible;//页码大于0 显示
- APP.pageData.currpage = APP.pageData.pagenum;
- //myblackboard.changepage(APP.pageData.currpage - 1);
- ///清空页面图片UI
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- ///画板模型增加一页
- Model_DrawData model_DrawData = new Model_DrawData();
- model_DrawData.PageNum = APP.pageData.currpage;
- APP.PageDrawList.Add(model_DrawData);
- //APP.SaveDraw();
- if (btnImport.IsEnabled == true)
- {
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- }
- /// <summary>
- /// 打印事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnPrint_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //3种情况 1.文档图片 2.截图图片 3.没有图片
-
-
-
- iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
- //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
- ////设置纸张横向
- //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
-
- string imgPath = FileToolsCommon.GetFileAbsolutePath("temp");
- FileToolsCommon.CreateFile(imgPath);
- imgPath += "\\101.pdf";
- iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
- document.Open();
- iTextSharp.text.Image image;
- for (int i = 0; i < APP.PageDrawList.Count; i++)
- {
- long ii = Timestamp();
- string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
- RectangleF rectangleFs = new RectangleF();
- MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- if (String.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
- {
-
- }
- else if (APP.PageDrawList[i].ImgDocumentation == true)
- {
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
- }
- else
- {
- RectangleF rectangleF = new RectangleF();
- rectangleF.Width = (float)APP.PageDrawList[i].ImageSizes.CenterX;
- rectangleF.Height = (float)APP.PageDrawList[i].ImageSizes.CenterY;
- rectangleF.X = (float)APP.PageDrawList[i].ImageLocation.X;
- rectangleF.Y = (float)APP.PageDrawList[i].ImageLocation.Y;
-
-
- string msg = string.Empty;
- bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
- if (isImg)
- {
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- }
- else
- {
- image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
- }
- }
-
-
-
-
- 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();
- if (APP.W_PrintWindow == null)
- {
- APP.W_PrintWindow = new PrintWindow();
- //APP.W_PrintWindow.Topmost = true;
- APP.W_PrintWindow.Owner = this;
- }
- if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
- {
- APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath);
- }
- else
- {
- APP.W_PrintWindow.Initialize("");
- }
- APP.W_PrintWindow.ShowDialog();
- //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>
- /// <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 (btnImport.IsEnabled == true)
- {
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- if (APP.pageData.currpage <= APP.PageDrawList.Count)
- {
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- {
- //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
-
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
- {
- var group = IMG.FindResource("Imageview") as TransformGroup;
- var transform = group.Children[1] as TranslateTransform;
- #region 高低 缩放比例
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
- {
- var transform1 = group.Children[0] as ScaleTransform;
- transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
- transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
- imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
- imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
- }
- #endregion
- #region XY轴
- transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
- transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
- #endregion
- mouseDown = false;
- }
- }
- }
- else
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- }
- }
- }
- }
- /// <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 (btnImport.IsEnabled == true)
- {
- ///截图可用
- ImgScreenshot.Visibility = Visibility.Visible;
- ImgScreenshotTwo.Visibility = Visibility.Collapsed;
- btnScreenshot.IsEnabled = true;
- }
- if (APP.pageData.currpage <= APP.PageDrawList.Count)
- {
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
- {
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- }
- if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- {
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
- ImgScreenshotTwo.Visibility = Visibility.Visible;
- btnScreenshot.IsEnabled = false;
- }
- else
- {
- imgDocumentation.Source = null;
- imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
- {
- var group = IMG.FindResource("Imageview") as TransformGroup;
- #region 高低 缩放比例
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
- {
- var transform1 = group.Children[0] as ScaleTransform;
- transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
- transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
- imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
- imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
- }
- #endregion
- #region 坐标XY轴
- var transform = group.Children[1] as TranslateTransform;
- transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
- transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
- #endregion
- mouseDown = false;
- }
- }
- }
- else
- {
- imgCanvas.Source = null;
- imgDocumentation.Source = null;
- }
- }
- }
- }
- /// <summary>
- /// 生成图片
- /// </summary>
- /// <param name="_path">图片地址</param>
- /// <param name="_saveimg">保存位置</param>
- /// <param name="_rectangle">图片位置</param>
- /// <param name="errmsg">错误消息</param>
- /// <returns></returns>
- private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
- {
- errmsg = null;
- try
- {
- Bitmap bitmap = null;
-
- //创建要显示的图片对象,根据参数的个数设置宽度
- Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
- Graphics g = Graphics.FromImage(backgroudImg);
- //清除画布,背景设置为白色
- g.Clear(System.Drawing.Color.White);
-
- if (!string.IsNullOrWhiteSpace(_path))
- {
- bitmap = ImageHelper.ReadBitmapFile(_path);
- g.DrawImage(bitmap, _rectangle);
- }
-
-
- backgroudImg.Save(_saveimg);
-
- g.Dispose();
- backgroudImg.Dispose();
- if (bitmap != null)
- {
- bitmap.Dispose();
- }
-
- GC.Collect();
- return true;
- }
- catch (Exception ex)
- {
- errmsg = ex.Message;
- LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
- return false;
- }
-
- }
- /// <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)
- {
- MessageWindow.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);
- }
- }
- /// <summary>
- /// x y轴
- /// </summary>
- /// <param name="img"></param>
- /// <param name="e"></param>
- private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
- {
- if (e.LeftButton != MouseButtonState.Pressed)
- {
- return;
- }
- if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
- {
- 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;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform.X;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform.Y;
- //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- }
- 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);
- LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
- + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
- );
-
- //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
-
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform();
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X = transform1.X;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y = transform1.Y;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform();
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX = imgCanvas.ActualWidth;
- APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY = imgCanvas.ActualHeight;
- APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
- }
- #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)
- {
- MessageWindow.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;
-
- //Dispatcher.Invoke(new Action(() =>
- //{
- // for (int i = 0; i < APP.PageDrawList.Count; i++)
- // {
- // if (APP.PageDrawList[i].PageCode == penSerial)
- // {
- // if (i < APP.pageData.pagenum)
- // {
- // if (i < APP.pageData.currpage)
- // {
- // int num = APP.pageData.currpage - i;
- // APP.pageData.currpage -= num;
- // myblackboard.changepage(APP.pageData.currpage - 1);
- // if (APP.PageDrawList.Count > 0)
- // {
- // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- // {
- // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
-
- // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- // }
- // else
- // {
- // imgCanvas.Source = null;
- // }
- // }
- // }
- // else
- // {
- // int num = i - APP.pageData.currpage;
- // APP.pageData.currpage += num;
- // myblackboard.changepage(APP.pageData.currpage - 1);
- // if (APP.PageDrawList.Count > 0)
- // {
-
- // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
- // {
- // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
- // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
- // }
- // else
- // {
- // imgCanvas.Source = null;
- // }
- // }
- // }
- // }
- // return;
- // }
- // }
- // //myblackboard.changepages(0, 0, true);
- // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
- //}));
- }
- //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();
- }
- if (APP.pageData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
- }));
- }
-
-
- }
-
- /// <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.MessageWindow.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.MessageWindow.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地址 与打印的页面关联
- if (APP.pageData.currpage > 0)
- {
- Dispatcher.Invoke(new Action(() =>
- {
- //myblackboard.changepages(testX, testY,false);
- myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (testY < scroMain.VerticalOffset)
- {
- //滚动条当前位置
- double RollCurrentLocation = scroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation - UpRoll;
- if (RollLocation < 0)
- {
- RollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- scroMain.ScrollToVerticalOffset(RollLocation);
- }
- //点在显示页面下方
- if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
- {
- //滚动条当前位置
- double RollCurrentLocation = scroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
- //如果小于0则等于0
- double RollLocation = RollCurrentLocation + DownRoll;
- //滚动条最大滚动值
- double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
- if (RollLocation > ScrollbarMaxNum)
- {
- RollLocation = ScrollbarMaxNum;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollLocation-RollCurrentLocation;
- scroMain.ScrollToVerticalOffset(RollLocation);
- }
- #endregion
- //gridM.Height //A4高度
- //scroMain.VerticalOffset;//获取滚动条位置
- //scroMain.ActualHeight//A4纸显示高度
- //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
-
- //Mouse.GetPosition(this)
- if (testX > 0 && testY > 0)
- {
- //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
- System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }));
- }
-
-
-
- ////每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 (this.WindowState == WindowState.Minimized)
- {
- this.WindowState = WindowState.Normal;
- }
- else
- {
- this.WindowState = WindowState.Minimized;
- }
- }
- /// <summary>
- /// 位置确定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnOk_Click(object sender, RoutedEventArgs e)
- {
- //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
- //btnOk.Visibility = Visibility.Collapsed;
- //blackboard_canvas.Visibility = Visibility.Visible;
- }
- /// <summary>
- /// 引用user32.dll动态链接库(windows api),
- /// 使用库中定义 API:SetCursorPos
- /// 设置光标位置
- /// </summary>
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern int SetCursorPos(int x, int y);
- /// 截图的图片鼠标右键事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- imgCanvas.Source = null;
- }
-
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- //System.Windows.SplashScreen(LoadDialog);
- //Common.system.SplashScreen.Show(typeof(LoadDialog));
- //Thread.Sleep(5000);
- //Common.system.SplashScreen.Close();
- APP.myloading.Show();
- Thread.Sleep(1000);
- APP.myloading.Hide();
- }
- }
- }
|