12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142 |
- using Accord.Video.FFMPEG;
- using Aspose.Slides;
- using ComeCapture;
- using Common.system;
- using NAudio.Wave;
- using NReco.VideoConverter;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Ink;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using TmatrixLibrary;
- using XHWK.Model;
- using XHWK.WKTool.Models;
- using XHWK.WKTool.Skin;
- using XHWK.WKTool.UControl;
- using XHWK.WKTool.Utils;
- using XHWK.WKTool.Utils.luobo;
- using XHWK.WKTool.Utils.pen;
-
- namespace XHWK.WKTool
- {
- using System.Globalization;
- using system;
-
- /// <summary>
- /// 主页面
- /// </summary>
- public partial class MainWindow : PenEventI
- {
- #region 字段
-
- public BlackboardNew myblackboard;
-
- /// <summary>
- /// 当前颜色
- /// </summary>
- private System.Windows.Media.Color _color = Colors.Red;
-
- //声明一个 DrawingAttributes 类型的变量
- private DrawingAttributes _drawingAttributes;
-
- /// <summary>
- /// 键盘钩子
- /// </summary>
- private KeyboardHookCommon _kHook;
-
- private System.Windows.Forms.OpenFileDialog _ofd;
-
- private System.Windows.Forms.FolderBrowserDialog _fbd;
-
- /// <summary>
- /// 笔迹粗细
- /// </summary>
- private int _penSize = 2;
-
- private System.Windows.Forms.DialogResult _result;
- private System.Windows.Forms.DialogResult _result2;
- private Model_Video _videoInfo;
-
- //定义委托
- public delegate void ChangeTextHandler(string text);
-
- //定义委托
- public delegate void ChangeTextHandlers(string text, int i);
-
- #region 上传
-
- /// <summary>
- /// 视频模型
- /// </summary>
- private List<Model_Video> _modelVideoList;
-
- #endregion 上传
-
- #endregion 字段
-
- #region 初始化
-
- private readonly ImageOperationUtil _imageOperationUtil;
-
- private readonly LuoBoPenUtil _luoBoPenUtil;
-
- /// <summary>
- /// 主页面
- /// </summary>
- public MainWindow()
- {
- InitializeComponent();
-
- #region 调整文字大小
-
- App.PageContextData.WordSize20 = 20.00;
- App.PageContextData.WordSize18 = 18.00;
- App.PageContextData.WordSize16 = 16.00;
- App.PageContextData.WordSize14 = 14.00;
- App.PageContextData.WordSize12 = 12.00;
-
- #endregion 调整文字大小
-
- ResizeMode = ResizeMode.CanMinimize;
- BtnPrint.IsEnabled = false;
- myblackboard = new BlackboardNew(BlackboardCanvas);
- App.PageContextData.pagenum = 0;
- App.PageContextData.currpage = 0;
- DataContext = App.PageContextData;
-
- //APP.SaveDraw();//画板模型第一页初始化
- App.PageDrawList = new List<Model_DrawData>();
- Model_DrawData modelDrawData = new Model_DrawData { PageNum = App.PageContextData.currpage };
- App.PageDrawList.Add(modelDrawData);
- Txbv.Text = (App.isDebug ? "测试版" : "正式版") + " v" + FileToolsCommon.GetConfigValue("VersionName");
- TxbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
- TxbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
- Initialize();
-
- //罗博手写板
- _luoBoPenUtil = new LuoBoPenUtil(this);
- _luoBoPenUtil.InitlbPen();
- //腾千里
- InitTqlpPen();
- SkinSelectInit();
- byte[] license = Convert.FromBase64String
- (
- "PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4="
- );
- new Aspose.Words.License().SetLicense(new MemoryStream(license));
- new Aspose.Pdf.License().SetLicense(new MemoryStream(license));
- new Aspose.Slides.License().SetLicense(new MemoryStream(license));
- _imageOperationUtil = new ImageOperationUtil
- (
- RectLeftUp,
- RectRightUp,
- RectLeftDown,
- RectRightDown,
- RectImgBorder,
- ImgCanvas,
- GridM
- );
- InitPrint();
- }
-
- private void LoadImage(BitmapImage image)
- {
- HeadImg.Source = image;
- try
- {
- switch (App.CameraPosition)
- {
- case "1":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
- HeadImg.VerticalAlignment = VerticalAlignment.Top;
- break;
- case "2":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
- HeadImg.VerticalAlignment = VerticalAlignment.Top;
- break;
- case "3":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
- HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
- break;
- case "4":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
- HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
- break;
- }
- }
- catch (Exception)
- {
- // ignored
- }
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- public void Initialize()
- {
- #region 数据初始化
-
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- FileToolsCommon.CreateDirectory(pathTemp);
- App.PageContextData.pagenum = 0;
- App.PageContextData.currpage = App.PageContextData.pagenum;
- BtnStop.IsEnabled = false; //停止录制按钮不可点击
-
- #endregion 数据初始化
-
- _kHook = new KeyboardHookCommon();
- _kHook.KeyDownEvent += K_hook_KeyDownEvent;
- _kHook.Start(); //安装键盘钩子
- App.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- //创建 DrawingAttributes 类的一个实例
- _drawingAttributes = new DrawingAttributes();
- //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
- //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
- BlackboardCanvas.DefaultDrawingAttributes = _drawingAttributes;
- BlackboardCanvas.UseCustomCursor = true;
- _drawingAttributes.FitToCurve = true;
- _drawingAttributes.IgnorePressure = false;
- _drawingAttributes.Width = _penSize;
- _drawingAttributes.Height = _penSize;
- _drawingAttributes.Color = _color;
- BlackboardCanvas.Cursor = Cursors.Pen;
- }
-
- /// <summary>
- /// 初始化快捷键
- /// </summary>
- public void InitializeKeyDownEvent()
- {
- _kHook.Start(); //安装键盘钩子
- }
-
- /// <summary>
- /// 引用user32.dll动态链接库(windows api), 使用库中定义 API:SetCursorPos 设置光标位置
- /// </summary>
- [System.Runtime.InteropServices.DllImport("user32.dll")]
- private static extern int SetCursorPos(int x, int y);
-
- /// <summary>
- /// 快捷键
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
- {
- if (App.PageContextData.currpage > 1)
- {
- //上一页
- last_button_Click(null, null);
- }
- }
- if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
- {
- if (App.PageContextData.currpage < App.PageContextData.pagenum)
- {
- //下一页
- next_btn_Click(null, null);
- }
- }
- if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
- {
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- ImgCanvas.Source = null;
- App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = null;
- App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = null;
- }
- }
- }
-
- /// <summary>
- /// 加载完成后调整录制区域大小
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private async void Window_Loaded(object sender, RoutedEventArgs e)
- {
- //调整录制区域宽高
- double proportion = 210.0 / 297.0;
- GridM.Height = GridM.ActualWidth / proportion;
- await CheckDevice();
- }
-
- private bool _microphoneGood;
- private bool _loudspeakerGood;
-
- private async Task CheckDevice()
- {
- Task<bool> checkMicrophone = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone));
- Task<bool> checkLoudspeaker = Task.Run(() => ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.loudspeaker));
- await Task.WhenAll(checkMicrophone, checkLoudspeaker);
- _microphoneGood = checkMicrophone.Result;
- _loudspeakerGood = checkMicrophone.Result;
- }
-
- #endregion 初始化
-
- #region 事件
-
- #region 登录
-
- /// <summary>
- /// 登录事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnLoginType_Click(object sender, RoutedEventArgs e)
- {
- if ("未登录".Equals(TxbLoginType.Text) || ImgHeadImgN.Visibility == Visibility.Visible)
- {
- Login();
- }
- else
- {
- MessageBoxResult dr = MessageWindow.Show
- (
- "确定退出登录?",
- "提示",
- MessageBoxButton.OKCancel
- );
- if (dr != MessageBoxResult.OK)
- {
- return;
- }
- LoginType();
- Login();
- }
- }
-
- /// <summary>
- /// 登录
- /// </summary>
- private void Login()
- {
- if (App.W_LoginWindow == null)
- {
- App.W_LoginWindow = new LoginWindow
- {
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- Owner = this
- };
- }
- else
- {
- App.W_LoginWindow.Initialize();
- }
- App.W_LoginWindow.ShowDialog();
- if (App.IsLoginType)
- {
- string headpicPath = FileToolsCommon.GetFileAbsolutePath("/Data/" + App.UserInfo.Username + ".png");
- if (FileToolsCommon.IsExistFile(headpicPath))
- {
- ImgHead.ImageSource = new BitmapImage(new Uri(headpicPath));
- }
- else
- {
- ImgHead.ImageSource = new BitmapImage(new Uri("pack://application:,,,/BlackImages/HM_HeadImg.png"));
- }
- TxbLoginType.Text = App.UserInfo.Username;
- ImgHeadImgN.Visibility = Visibility.Collapsed;
- ImgHeadImg.Visibility = Visibility.Visible;
- }
- else
- {
- TxbLoginType.Text = "未登录";
- ImgHeadImgN.Visibility = Visibility.Visible;
- ImgHeadImg.Visibility = Visibility.Collapsed;
- }
- }
-
- /// <summary>
- /// 状态更改为未登录
- /// </summary>
- private void LoginType()
- {
- App.IsLoginType = false;
- TxbLoginType.Text = "未登录";
- ImgHeadImgN.Visibility = Visibility.Visible;
- ImgHeadImg.Visibility = Visibility.Collapsed;
- App.UserInfo = new Model_UserInfo();
- }
-
- #endregion 登录
-
- #region 设置
-
- /// <summary>
- /// 设置 浏览事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnBrowse_Click(object sender, RoutedEventArgs e)
- {
- _fbd = new System.Windows.Forms.FolderBrowserDialog();
- _result2 = _fbd.ShowDialog();
- if (_result2 != System.Windows.Forms.DialogResult.OK)
- {
- return;
- }
- if (_fbd.SelectedPath != "")
- {
- TxbStoragePath.Content = _fbd.SelectedPath;
- }
- }
-
- /// <summary>
- /// 打开文件所在位置
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void btnOpen_Click(object sender, RoutedEventArgs e)
- {
- Process.Start(App.WKData.WkPath);
- }
-
- /// <summary>
- /// 设置 保存事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSave_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- 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");
- }
- UpdateHideSrToolConfig();
-
- // < !--摄像头位置 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");
- }
- //格式
- if (RbnMp4.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "1");
- }
- else if (RbnFlv.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "2");
- }
- else if (RbnAvi.IsChecked == true)
- {
- FileToolsCommon.SetConfigValue("VideoType", "3");
- }
- App.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
- GridMain.Visibility = Visibility.Visible;
- GridM.IsEnabled = true;
- GridRecordingTitle.Visibility = Visibility.Visible;
- GridSetUp.Visibility = Visibility.Collapsed;
- HeadImg.Visibility = Visibility.Hidden;
- if (_isRbnOpen)
- {
- HeadImg.Visibility = Visibility.Visible;
- }
- if (!TxbStoragePath.Content.ToString().Equals(App.WKData.WkPath))
- {
- //存储文件
- FileToolsCommon.SetConfigValue("VideoSavePath", TxbStoragePath.Content.ToString());
- MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 设置事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSetUp_Click(object sender, RoutedEventArgs e)
- {
- if (GridSetUp.Visibility == Visibility.Collapsed)
- {
- PageHide();
- GridSetUp.Visibility = Visibility.Visible;
- TxbStoragePath.Content = App.WKData.WkPath;
-
- #region 读取用户配置
-
- // < !--摄像头位置 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;
- }
- string type = FileToolsCommon.GetConfigValue("VideoType"); //<!--视频格式 1、MP4 2、FlV 3、AVI-->
- if ("1".Equals(type))
- {
- RbnMp4.IsChecked = true;
- }
- else if ("2".Equals(type))
- {
- RbnFlv.IsChecked = true;
- }
- else if ("3".Equals(type))
- {
- RbnAvi.IsChecked = true;
- }
- string isHide = FileToolsCommon.GetConfigValue("IsHideSRTool"); //工具栏是否隐藏
- if (isHide.Equals("1"))
- {
- RbnHide.IsChecked = true;
- }
- else
- {
- Rbnvisi.IsChecked = true;
- }
-
- //加载皮肤按钮
- SkinSelectInit();
-
- #endregion 读取用户配置
- }
- else
- {
- GridMain.Visibility = Visibility.Visible;
- GridM.IsEnabled = true;
- GridRecordingTitle.Visibility = Visibility.Visible;
- GridSetUp.Visibility = Visibility.Collapsed;
- }
- }
-
- /// <summary>
- /// 更新隐藏录屏工具栏隐藏状态
- /// </summary>
- private void UpdateHideSrToolConfig()
- {
- if (RbnHide.IsChecked == true)
- {
- //隐藏
- FileToolsCommon.SetConfigValue("IsHideSRTool", "1");
- App.IsHideSRTool = true;
- }
- else
- {
- //显示
- FileToolsCommon.SetConfigValue("IsHideSRTool", "0");
- App.IsHideSRTool = false;
- }
- }
-
- #region 切换皮肤
-
- /// <summary>
- /// 科技蓝
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSkinTechnologyBlue_Click(object sender, RoutedEventArgs e)
- {
- if (App.SkinStyle != "1")
- {
- HideSkinSelect();
- SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
- App.SkinStyle = "1";
- FileToolsCommon.SetConfigValue("SkinStyle", "1");
- SkinConfig.SwitchSkin(1);
- }
- }
-
- /// <summary>
- /// 白色
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnSkinWhite_Click(object sender, RoutedEventArgs e)
- {
- if (App.SkinStyle != "0")
- {
- HideSkinSelect();
- SkinSelectWhite.Visibility = Visibility.Visible;
- App.SkinStyle = "0";
- FileToolsCommon.SetConfigValue("SkinStyle", "0");
- SkinConfig.SwitchSkin(0);
- }
- }
-
- /// <summary>
- /// 隐藏皮肤选择键
- /// </summary>
- private void HideSkinSelect()
- {
- SkinSelectWhite.Visibility = Visibility.Hidden;
- SkinSelectTechnologyBlue.Visibility = Visibility.Hidden;
- }
-
- /// <summary>
- /// 加载皮肤选项
- /// </summary>
- private void SkinSelectInit()
- {
- if (App.SkinStyle == "0")
- {
- HideSkinSelect();
- SkinSelectWhite.Visibility = Visibility.Visible;
- SkinConfig.SwitchSkin(0);
- }
- else if (App.SkinStyle == "1")
- {
- HideSkinSelect();
- SkinSelectTechnologyBlue.Visibility = Visibility.Visible;
- SkinConfig.SwitchSkin(1);
- }
- else
- {
- HideSkinSelect();
- SkinSelectWhite.Visibility = Visibility.Visible;
- }
- }
-
- #endregion 切换皮肤
-
- #endregion 设置
-
- private bool _isHasCode;
-
- /// <summary>
- /// 加页事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnAdd_Click(object sender, RoutedEventArgs e)
- {
- _luoBoPenUtil.lb_device_hand();
- PrepareRecord();
- if (App.PageContextData.currpage > 0)
- {
- App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = true;
- }
- if (BlackboardCanvas.Visibility == Visibility.Collapsed)
- {
- BlackboardCanvas.Visibility = Visibility.Visible;
- }
- App.PageContextData.pagenum += 1;
- HideAngleBorder();
- GridPage.Visibility = Visibility.Visible; //页码大于0 显示
- App.PageContextData.currpage = App.PageContextData.pagenum;
- myblackboard.changepage(App.PageContextData.currpage - 1);
- ScroMain.ScrollToVerticalOffset(0);
- //清空页面图片UI
- ImgCanvas.Source = null;
- ImgDocumentation.Source = null;
- ImgPpt.Source = null;
- if (App.PageContextData.pagenum == 1)
- {
- App.PageDrawList = new List<Model_DrawData>();
- }
- //画板模型增加一页
- Model_DrawData modelDrawData = new Model_DrawData { PageNum = App.PageContextData.currpage };
- App.PageDrawList.Add(modelDrawData);
- if (_recordType == 0)
- {
- BtnPrint.IsEnabled = true;
- }
- if (BtnImport.IsEnabled)
- {
- //截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }
-
- /// <summary>
- /// 关闭事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnClose_Click(object sender, RoutedEventArgs e)
- {
- if (_recordType == 0)
- {
- try
- {
- MessageBoxResult br = MessageWindow.Show
- (
- "确定退出系统?",
- "退出",
- MessageBoxButton.OKCancel
- );
- if (br == MessageBoxResult.OK)
- {
- try
- {
- App.Killffmpeg();
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("获取进程失败," + ex.Message, ex);
- }
- App.SaveWkData();
- App.SaveDraw();
- _tmc.TmatrixUninitialize();
- Environment.Exit(0);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("关闭微课失败," + ex.Message, ex);
- Close();
- Application.Current.Shutdown();
- _tmc.TmatrixUninitialize();
- Environment.Exit(0);
- }
- }
- else
- {
- MessageWindow.Show("当前正在录制,请先停止录制。");
- }
- }
-
- /// <summary>
- /// 打印事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnPrint_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- //3种情况 1.文档图片 2.截图图片 3.没有图片
- if (App.PageDrawList.Count == 0)
- {
- MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
- return;
- }
- }
- catch (Exception ex)
- {
- MessageWindow.Show(ex.Message);
- Console.WriteLine(@"转换失败,原因:" + ex.Message);
- }
- if (GridPrintingTitle.Visibility == Visibility.Visible)
- {
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
- else
- {
- GridPrintingTitle.Visibility = Visibility.Visible;
- if (App.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(App.PageDrawList[0].PageImagePath))
- {
- InitializePrint
- (
- App.PageDrawList[0].PageImagePath,
- GridM.ActualWidth,
- GridM.ActualHeight
- );
- }
- else
- {
- InitializePrint
- (
- "",
- GridM.ActualWidth,
- _gridActHeight
- );
- }
- }
- }
-
- /// <summary>
- /// 打印
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnPrint_Print_Click(object sender, RoutedEventArgs e)
- {
- _isHasCode = true;
- Print();
- }
-
- private void BtnPrintCloseClick(object sender, RoutedEventArgs e)
- {
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 打印说明
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void btnPrintExplain_Click(object sender, RoutedEventArgs e)
- {
- Process.Start(FileToolsCommon.GetFileAbsolutePath("/星火微课点阵码打印及印刷指导手册.docx"));
- }
-
- private void PageHide()
- {
- //设置
- GridSetUp.Visibility = Visibility.Collapsed;
- //我的
- GridMyVideo.Visibility = Visibility.Collapsed;
- //首页
- GridMain.Visibility = Visibility.Collapsed;
- GridM.IsEnabled = true;
- //打印
- GridPrintContent.Visibility = Visibility.Collapsed;
- //标题 录制
- GridRecordingTitle.Visibility = Visibility.Collapsed;
- //标题 打印
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
-
- private void Print()
- {
- if (!ZPrintUtils.IsExistAcroRd32())
- {
- MessageBoxResult dr = MessageWindow.Show
- (
- "需要安装PDF阅读器,是否下载安装?",
- "提示",
- MessageBoxButton.OKCancel
- );
- if (dr == MessageBoxResult.OK)
- {
- ZPrintUtils.InstallAcroRd32ByUser();
- }
- return;
- }
- BtnPrint.IsEnabled = false;
- PrintModel printmodel = new PrintModel();
- string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
- imgPath = imgPath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
- printmodel.filepath = imgPath;
- //打印数量
- printmodel.num = 1;
- _printMsg = "准备中";
- _msgnum = 0;
- _num = 0;
- GridPrintMask.Visibility = Visibility.Visible;
- Task.Run
- (
- () =>
- {
- StartPrint(printmodel);
- }
- );
- _timesPrint = new System.Timers.Timer(100);
- _timesPrint.Elapsed += Times_ElapsedClick;
- _timesPrint.Start();
- _timesPrintMsg = new System.Timers.Timer(500);
- _timesPrintMsg.Elapsed += TimesPrintMsg_Elapsed;
- _timesPrintMsg.Start();
- GridPrintingTitle.Visibility = Visibility.Collapsed;
- }
-
- private void Print_No_Code_Click(object sender, RoutedEventArgs e)
- {
- _isHasCode = false;
- Print();
- }
-
- /// <summary>
- /// 窗体移动
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- DragMove();
- }
-
- #region 摄像头
-
- private bool _isRbnOpen;
-
- private System.Timers.Timer _times;
-
- /// <summary>
- /// 摄像头打开事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnOpen_Click(object sender, RoutedEventArgs e)
- {
- if (!_isRbnOpen)
- {
- #region 防止连击
-
- if (_isPressButton)
- {
- return;
- }
- _isPressButton = true;
- Task.Run
- (
- () =>
- {
- Thread.Sleep(3000);
- _isPressButton = false;
- }
- );
-
- #endregion 防止连击
-
- CameraHelper.UpdateCameraDevices();
- if (CameraHelper.CameraDevices.Count > 0)
- {
- if (string.IsNullOrWhiteSpace(App.CameraName))
- {
- App.CameraName = CameraHelper.CameraDevices[0].MonikerString;
- }
- int cameraIndex = 0;
- for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
- {
- if (CameraHelper.CameraDevices[i].MonikerString == App.CameraName)
- {
- cameraIndex = i;
- }
- }
- CameraHelper.imageCallback = LoadImage;
- CameraHelper.StartCameraDevice(cameraIndex, this.Dispatcher);
- if (_timer != null)
- {
- _times.Elapsed -= Times_Elapsed;
- _times.Enabled = false;
- _times.Dispose();
- }
- _times = new System.Timers.Timer(200) //初始值为300
- {
- AutoReset = true //设置是否执行System.Timers.Timer.Elapsed事件
- }; //设置执行一次(false)还是一直执行(true)
- _times.Elapsed += Times_Elapsed;
- _times.Enabled = true; //启动计时器
- _isRbnOpen = true;
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- FileToolsCommon.CreateDirectory(imgPath);
- HeadImg.Visibility = Visibility.Visible;
- // < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
- switch (App.CameraPosition)
- {
- case "1":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
- HeadImg.VerticalAlignment = VerticalAlignment.Top;
- break;
- case "2":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
- HeadImg.VerticalAlignment = VerticalAlignment.Top;
- break;
- case "3":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Right;
- HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
- break;
- case "4":
- HeadImg.HorizontalAlignment = HorizontalAlignment.Left;
- HeadImg.VerticalAlignment = VerticalAlignment.Bottom;
- break;
- }
- RbnTurnOff.IsEnabled = false;
- Task.Run
- (
- () =>
- {
- Thread.Sleep(3000);
- Dispatcher.Invoke
- (
- () =>
- {
- RbnTurnOff.IsEnabled = true;
- }
- );
- }
- );
- }
- }
- }
-
- /// <summary>
- /// 摄像头关闭事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
- {
- if (_isRbnOpen)
- {
- #region 防止连击
-
- if (_isPressButton)
- {
- return;
- }
- _isPressButton = true;
- Task.Run
- (
- () =>
- {
- Thread.Sleep(500);
- _isPressButton = false;
- }
- );
-
- #endregion 防止连击
-
- _isRbnOpen = false;
- HeadImg.Visibility = Visibility.Hidden;
- RbnOpen.IsEnabled = false;
- CameraHelper.CloseDevice();
- RbnOpen.IsEnabled = true;
- if (_timer != null)
- {
- _times.Elapsed -= Times_Elapsed;
- _times.Enabled = false;
- _times.Dispose();
- _times = null;
- }
- }
- }
-
- private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (_isRbnOpen)
- {
- try
- {
- long time = Timestamp();
- string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
- CameraHelper.CaptureImage(imgPath, time.ToString());
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
- }
-
- #endregion 摄像头
-
- #region 设备检测
-
- /// <summary>
- /// 设备检测
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private async void BtnDevice_Click(object sender, RoutedEventArgs e)
- {
- if (RbnTurnOff.IsChecked != null && !(bool)RbnTurnOff.IsChecked)
- {
- RbnTurnOff.IsChecked = true;
- RbnTurnOff_Click(null, null);
- await Task.Delay(1000);
- }
- DeviceWindow deviceWin = new DeviceWindow();
- deviceWin.ShowDialog();
- }
-
- #endregion 设备检测
-
- #endregion 事件
-
- #region 画笔
-
- /// <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 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 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 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 BtnWhite_Click(object sender, RoutedEventArgs e)
- {
- _drawingAttributes.Color = Colors.White;
- _color = Colors.White;
- }
-
- /// <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;
- }
-
- private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- _mouseDown = true;
- _imageOperationUtil.setMouseDown(_mouseDown);
- }
-
- /// <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 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;
- }
-
- #endregion 画笔
-
- #region 导入截图
-
- /// <summary>
- /// 防止图片地址重复
- /// </summary>
- private long _wordImgNum = 9999;
-
- /// <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;
- }
-
- /// <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>
- /// <returns>
- /// </returns>
- public void InvokeServerCompate(object obj)
- {
- //APP.myloading.Hide();
- App.myloading.Hide();
- }
-
- public void WindowType()
- {
- this.Activate();
- }
-
- /// <summary>
- /// 导入事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnImport_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- PrepareRecord();
- HideAngleBorder();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
- _ofd = new System.Windows.Forms.OpenFileDialog
- {
- //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
- //增加导入图片
- Filter = @"文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
- InitialDirectory = desktopPath,
- Multiselect = false,
- AddExtension = true,
- DereferenceLinks = true
- };
- App.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 截图事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
- {
- if (_recordType == 4)
- {
- return;
- }
- JietuAction();
- }
-
- private async void JietuAction()
- {
- PrepareRecord();
- HideAngleBorder();
- if (WindowState == WindowState.Normal) //截图隐藏窗口
- {
- WindowState = WindowState.Minimized;
- }
- await Task.Delay(300);
- ImgCanvas.Margin = new Thickness
- (
- 0,
- 0,
- 0,
- 0
- );
- App.ImgPath = string.Empty;
- string time = GetTimeStamp();
- string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
- App.ImgPath = desktopPath;
- ImageHelper.GetScreenshot
- (
- new Rectangle
- (
- 0,
- 0,
- 0,
- 0
- )
- {
- Location = default,
- Size = default
- },
- desktopPath,
- false,
- out var _
- );
- _kHook.Stop();
- if (App.W_JieTuWindow != null)
- {
- App.W_JieTuWindow.initialization();
- App.W_JieTuWindow.Screenshot();
- App.W_JieTuWindow.InitializeKeyDownEvent();
- App.W_JieTuWindow.WindowState = WindowState.Maximized;
- App.W_JieTuWindow.Visibility = Visibility.Visible;
- }
- else
- {
- App.W_JieTuWindow = new JieTuWindow();
- App.W_JieTuWindow.InitializeKeyDownEvent();
- // 订阅事件
- App.W_JieTuWindow.ChangeTextEvent += frm_ChangeTextEvent;
- App.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
- App.W_JieTuWindow.Show();
- }
- }
-
- /// <summary>
- /// 截图关闭窗口
- /// </summary>
- /// <param name="text">
- /// </param>
- private void frm_ChangeTextEvent(string text)
- {
- if ("关闭窗口".Equals(text))
- {
- if (WindowState == WindowState.Minimized) //截图完恢复窗口
- {
- WindowState = WindowState.Normal;
- Activate();
- }
- InitializeKeyDownEvent();
- if (!string.IsNullOrWhiteSpace(App.ImgPath) && File.Exists(App.ImgPath))
- {
- if (App.PageContextData.currpage == 0)
- {
- App.PageContextData.pagenum += 1;
- App.PageContextData.currpage = App.PageContextData.pagenum;
- myblackboard.changepage(App.PageContextData.currpage - 1);
- GridPage.Visibility = Visibility.Visible; //页码大于0 显示
-
- #region 插入页码
-
- #endregion 插入页码
- }
- if (App.PageDrawList.Count >= App.PageContextData.currpage)
- {
- App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
- App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
- }
- else
- {
- Model_DrawData modelDrawData = new Model_DrawData
- {
- PageImagePath = App.ImgPath,
- PdfImagePath = App.ImgPath
- };
- App.PageDrawList.Add(modelDrawData);
- }
- if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
- {
- ImgDocumentation.Source = null;
- BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
- _mouseDown = false;
- _imageOperationUtil.setMouseDown(_mouseDown);
- App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
- App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
- App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
- ImgCanvas.Source = bitImg;
- ImgCanvas.Width = bitImg.Width;
- ImgCanvas.Height = bitImg.Height;
- ScroMain.ScrollToVerticalOffset(0);
- App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = ImgCanvas.Width,
- CenterY = ImgCanvas.Height
- };
- BtnPrint.IsEnabled = true;
- }
- }
- }
- else if ("取消".Equals(text))
- {
- if (WindowState == WindowState.Minimized) //截图完恢复窗口
- {
- WindowState = WindowState.Normal;
- }
- }
- }
-
- /// <summary>
- /// 导入-开始
- /// </summary>
- /// <returns>
- /// </returns>
- private object InvokeServering()
- {
- Dispatcher.Invoke
- (
- () =>
- {
- _result = _ofd.ShowDialog();
- }
- );
- if (_result == System.Windows.Forms.DialogResult.OK)
- {
- if (_ofd.FileName != "")
- {
- List<string> imagelist = new List<string>()
- {
- "jpg",
- "jpeg",
- "png",
- "bmp"
- };
- Dispatcher.Invoke
- (
- () =>
- {
- App.myloading.Show();
- myblackboard.changepage(App.PageContextData.pagenum);
- }
- );
- string filepath = _ofd.FileName;
- string filesuff = filepath.Substring(filepath.LastIndexOf(".", StringComparison.Ordinal) + 1).ToLower();
- if (_ofd.SafeFileName != null)
- {
- string path = _ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
- string type = _ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
- if (type.Contains("typezsygppt")) //ppt
- {
- try
- {
- #region PPT转PDF
-
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- path = pathTemp + path + ".pdf";
- FileToolsCommon.CreateDirectory(pathTemp);
-
- //PPT转PDF
- Presentation ppt = new Presentation(filepath);
- ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
-
- #endregion PPT转PDF
-
- #region PDF转图片
-
- // 图片绝对路径集合
- List<string> images = new List<string>();
- string directoryPath = pathTemp;
-
- //定义Jpeg转换设备
- Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(path);
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- var device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= pdfDoc.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(pdfDoc.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
-
- #endregion PDF转图片
-
- Dispatcher.Invoke
- (
- () =>
- {
- string[] page = images.ToArray();
- int num = 0;
- int iStart = App.PageContextData.pagenum; //导入文档的开始下标
- int iEnd = page.Length + App.PageContextData.pagenum; //导入文档的结束下标
- for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
- {
- if (App.PageDrawList != null && App.PageDrawList.Count > i)
- {
- App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
- App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
- App.PageDrawList[i].PageNum = i + 1;
- App.PageDrawList[i].ImgDocumentation = true;
- App.PageDrawList[i].Type = "ppt";
- }
- else
- {
- Model_DrawData modelDrawData = new Model_DrawData
- {
- PageImagePath = page[i - App.PageContextData.pagenum],
- PdfImagePath = page[i - App.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true,
- Type = "ppt"
- };
- if (App.PageDrawList != null)
- {
- App.PageDrawList.Add(modelDrawData);
- }
- }
- BtnPrint.IsEnabled = true;
- App.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- App.PageContextData.currpage = App.PageContextData.pagenum + 1;
- App.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible; //页码大于0 显示
- }
- if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
- {
- ImgCanvas.Source = null;
- BtnScreenshot.IsEnabled = false;
- ImgDocumentation.Source = null;
- ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
- ScroMain.ScrollToVerticalOffset(0);
- for (int i = iStart; i < iEnd; i++)
- {
- App.PageDrawList[i].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
- App.PageDrawList[i].IsImageLocation = true;
- App.PageDrawList[i].ImageSizes = new ScaleTransform
- {
- CenterX = ImgCanvas.Width,
- CenterY = ImgCanvas.Height
- };
- }
- }
- else
- {
- ImgDocumentation.Source = null;
- ImgCanvas.Source = null;
- ImgPpt.Source = null;
- //截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }
- );
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
- }
- );
- LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
- }
- }
- else if (type.Contains("typepdf"))
- {
- try
- {
- string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
-
- #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 pdfDoc = new Aspose.Pdf.Document(filepath);
- //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
- //directoryPath += quality;
- Directory.CreateDirectory(directoryPath);
- //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
- var device = new Aspose.Pdf.Devices.JpegDevice(100);
- //遍历每一页转为jpg
- for (int i = 1; i <= pdfDoc.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(pdfDoc.Pages[i], fs);
- fs.Close();
- }
- catch (Exception)
- {
- fs.Close();
- File.Delete(filePathOutPut);
- }
- }
-
- #endregion PDF转图片
-
- string[] page = images.ToArray();
- int num = 0;
- Dispatcher.Invoke
- (
- () =>
- {
- for (int i = App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
- {
- if (App.PageDrawList != null && App.PageDrawList.Count > i)
- {
- App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
- App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
- App.PageDrawList[i].PageNum = i + 1;
- App.PageDrawList[i].ImgDocumentation = true;
- App.PageDrawList[i].Type = "word";
- }
- else
- {
- Model_DrawData modelDrawData = new Model_DrawData
- {
- PageImagePath = page[i - App.PageContextData.pagenum],
- PdfImagePath = page[i - App.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true,
- Type = "word"
- };
- if (App.PageDrawList != null)
- {
- App.PageDrawList.Add(modelDrawData);
- }
- }
- BtnPrint.IsEnabled = true;
- App.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- App.PageContextData.currpage = App.PageContextData.pagenum + 1;
- App.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible; //页码大于0 显示
- }
- if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
- {
- ImgCanvas.Source = null;
- ImgPpt.Source = null;
- BtnScreenshot.IsEnabled = false;
- ImgDocumentation.Visibility = Visibility.Visible;
- ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
- ScroMain.ScrollToVerticalOffset(0);
- }
- else
- {
- ImgDocumentation.Source = null;
- ImgCanvas.Source = null;
- ImgPpt.Source = null;
- //截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }
- );
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show(ex.Message);
- }
- );
- LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
- }
- }
- else if (imagelist.Contains(filesuff)) //导入图片
- {
- string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
- if (!Directory.Exists(imagepath))
- {
- Directory.CreateDirectory(imagepath);
- }
- TimeSpan ts = DateTime.UtcNow
- - new DateTime
- (
- 1970,
- 1,
- 1,
- 0,
- 0,
- 0,
- 0
- );
- string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
- string filepathCopy = Path.Combine(imagepath, timestr + _ofd.SafeFileName);
- File.Copy(filepath, filepathCopy);
- filepath = filepathCopy;
- App.ImgPath = filepath;
- Dispatcher.Invoke
- (
- () =>
- {
- if (App.PageContextData.currpage == 0)
- {
- App.PageContextData.pagenum += 1;
- App.PageContextData.currpage = App.PageContextData.pagenum;
- myblackboard.changepage(App.PageContextData.currpage - 1);
- GridPage.Visibility = Visibility.Visible; //页码大于0 显示
-
- #region 插入页码
-
- #endregion 插入页码
- }
- else
- {
- App.PageContextData.pagenum += 1;
- App.PageContextData.currpage = App.PageContextData.pagenum;
- myblackboard.changepage(App.PageContextData.currpage - 1);
- }
- if (App.PageDrawList.Count >= App.PageContextData.currpage)
- {
- App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath = App.ImgPath; //zxycs
- App.PageDrawList[App.PageContextData.currpage - 1].PdfImagePath = App.ImgPath;
- }
- else
- {
- Model_DrawData modelDrawData = new Model_DrawData
- {
- PageImagePath = App.ImgPath,
- PdfImagePath = App.ImgPath
- };
- App.PageDrawList.Add(modelDrawData);
- }
- if (App.PageDrawList.Count >= App.PageContextData.currpage && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
- {
- ImgDocumentation.Source = null;
- BitmapImage bitImg = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
- _mouseDown = false;
- _imageOperationUtil.setMouseDown(_mouseDown);
- App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation = new TranslateTransform
- {
- X = 0.1,
- Y = 0.1
- };
- App.PageDrawList[App.PageContextData.currpage - 1].Type = "截图";
- App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
- ImgCanvas.Source = bitImg;
- ImgCanvas.Width = bitImg.Width;
- ImgCanvas.Height = bitImg.Height;
- ScroMain.ScrollToVerticalOffset(0);
- ImgCanvas.Margin = new Thickness
- (
- App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
- App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
- 0,
- 0
- );
- App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes = new ScaleTransform
- {
- CenterX = ImgCanvas.Width,
- CenterY = ImgCanvas.Height
- };
- BtnPrint.IsEnabled = true;
- }
- }
- );
- }
- else //word
- {
- try
- {
- string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
- _wordImgNum += 1;
- string[] page = ZAsposeUtil.ConvertWordToImage
- (
- filepath,
- paths,
- "" + _wordImgNum
- )
- .ToArray();
- int num = 0;
- Dispatcher.Invoke
- (
- () =>
- {
- for (int i = 0 + App.PageContextData.pagenum; i < page.Length + App.PageContextData.pagenum; i++) //给画板模型加图片路径
- {
- if (App.PageDrawList != null && App.PageDrawList.Count > i)
- {
- App.PageDrawList[i].PageImagePath = page[i - App.PageContextData.pagenum]; //zxycs
- App.PageDrawList[i].PdfImagePath = page[i - App.PageContextData.pagenum];
- App.PageDrawList[i].PageNum = i + 1;
- App.PageDrawList[i].ImgDocumentation = true;
- App.PageDrawList[i].Type = "word";
- }
- else
- {
- Model_DrawData modelDrawData = new Model_DrawData
- {
- PageImagePath = page[i - App.PageContextData.pagenum],
- PdfImagePath = page[i - App.PageContextData.pagenum],
- PageNum = i + 1,
- ImgDocumentation = true,
- Type = "word"
- };
- if (App.PageDrawList != null)
- {
- App.PageDrawList.Add(modelDrawData);
- }
- }
- BtnPrint.IsEnabled = true;
- App.SaveDraw();
- num++;
- }
- if (num > 0)
- {
- App.PageContextData.currpage = App.PageContextData.pagenum + 1;
- App.PageContextData.pagenum += num;
- GridPage.Visibility = Visibility.Visible; //页码大于0 显示
- }
- if (App.PageDrawList != null && App.PageContextData.currpage > 0 && App.PageContextData.currpage <= App.PageDrawList.Count)
- {
- ImgCanvas.Source = null;
- ImgPpt.Source = null;
- BtnScreenshot.IsEnabled = false;
- ImgDocumentation.Visibility = Visibility.Visible;
- ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath)); //给当前页面展示图片
- ScroMain.ScrollToVerticalOffset(0);
- }
- else
- {
- ImgDocumentation.Source = null;
- ImgCanvas.Source = null;
- ImgPpt.Source = null;
- //截图可用
- BtnScreenshot.IsEnabled = true;
- }
- }
- );
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
- }
- );
- LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
- }
- }
- }
-
- #region 插入页码
-
- #endregion 插入页码
- }
- }
- //OpenDialog();
- return "";
- }
-
- /// <summary>
- /// 截图关闭 非正常关闭截图时,截图清空
- /// </summary>
- private void JietuWindow_click_closeJietuWindowClick()
- {
- if (WindowState == WindowState.Minimized) //截图完恢复窗口
- {
- WindowState = WindowState.Normal;
- }
- App.W_JieTuWindow = null;
- }
-
- #region 导入转换图片
-
- #endregion 导入转换图片
-
- #endregion 导入截图
-
- #region 上传 列表
-
- /// <summary>
- /// 搜索集合匹配的索引
- /// </summary>
- /// <typeparam name="T">
- /// </typeparam>
- /// <param name="parent">
- /// </param>
- /// <param name="childName">
- /// </param>
- /// <returns>
- /// </returns>
- public static List<T> FindChilds<T>(DependencyObject parent, string childName) where T : DependencyObject
- {
- List<T> list = new List<T>();
- if (parent == null)
- {
- return list;
- }
- int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
- for (int i = 0; i < childrenCount; i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(parent, i);
- // 如果子控件不是需查找的控件类型
- T childType = child as T;
- if (childType == null)
- {
- // 在下一级控件中递归查找
- FindChilds<T>(child, childName);
- list.AddRange(FindChilds<T>(child, childName));
- }
- else if (!string.IsNullOrEmpty(childName))
- {
- FrameworkElement frameworkElement = child as FrameworkElement;
- // 如果控件名称符合参数条件
- if (frameworkElement != null && frameworkElement.Name == childName)
- {
- list.Add((T)child);
- }
- }
- else
- {
- // 查找到了控件
- list.Add((T)child);
- }
- }
- return list;
- }
-
- /// <summary>
- /// 加载视频列表
- /// </summary>
- public void LoadingVideoList()
- {
- try
- {
- _modelVideoList = new List<Model_Video>();
- foreach (Model_WKData vdata in App.WKDataList)
- {
- #region 计时器初始化
-
- if (vdata.VideoList == null)
- {
- continue;
- }
- foreach (Model_Video videoinfo in vdata.VideoList)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
- {
- continue;
- }
- if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
- {
- videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString(CultureInfo.InvariantCulture) + " MB";
- videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
- }
- _modelVideoList.Add(videoinfo);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
-
- #endregion 计时器初始化
- }
- //翻转
- if (_modelVideoList.Count > 1)
- {
- _modelVideoList.Reverse();
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
- }
- }
-
- /// <summary>
- /// 上传事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnUpload_Click(object sender, RoutedEventArgs e)
- {
- if (GridMyVideo.Visibility == Visibility.Visible)
- {
- GridMyVideo.Visibility = Visibility.Collapsed;
- GridMain.Visibility = Visibility.Visible;
- GridM.IsEnabled = true;
- GridRecordingTitle.Visibility = Visibility.Visible;
- }
- else
- {
- PageHide();
- GridMyVideo.Visibility = Visibility.Visible;
- LoadUploadInitData();
- }
- }
-
- #endregion 上传 列表
-
- #region 新上传 显示缩略图
-
- #region 初始值
-
- private readonly double _controlHeight = 260;
-
- private readonly double _controlWidth = 250;
-
- /// <summary>
- /// 当前页
- /// </summary>
- private int _currentPage = 1;
-
- /// <summary>
- /// 横向间隔
- /// </summary>
- private double _intervalX;
-
- /// <summary>
- /// 纵向间隔
- /// </summary>
- private double _intervalY;
-
- /// <summary>
- /// 页面高
- /// </summary>
- private double _pageH;
-
- /// <summary>
- /// 每页显示的视频数
- /// </summary>
- private int _pageShowNum;
-
- /// <summary>
- /// 页面宽
- /// </summary>
- private double _pageW;
-
- /// <summary>
- /// 总页数
- /// </summary>
- private int _totalPage;
-
- /// <summary>
- /// 视频信息列表
- /// </summary>
- private readonly List<Uc_VideoItem> _videoControlList = new List<Uc_VideoItem>();
-
- #endregion 初始值
-
- /// <summary>
- /// 加载当前页数据
- /// </summary>
- private void LoadCurrentPageData()
- {
- LblVideoPageNum.Content = _currentPage + "/" + _totalPage;
- //隐藏显示的控件
- if (_videoControlList.Count > 0)
- {
- foreach (Uc_VideoItem item in _videoControlList)
- {
- if (item.Visibility != Visibility.Hidden)
- {
- item.Visibility = Visibility.Hidden;
- }
- }
- }
- double w = _intervalX; //每次增加250
- double h = _intervalY; //每次增加260
- //加载控件
- for (int i = 0; i < _pageShowNum; i++)
- {
- int dataIndex = (_currentPage - 1) * _pageShowNum + i;
- if (dataIndex == _modelVideoList.Count)
- {
- return;
- }
- Uc_VideoItem videoItem;
- if (_videoControlList.Exists(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid))
- {
- videoItem = _videoControlList.Find(x => x.Tag.ToString() == _modelVideoList[dataIndex].FileGuid);
- }
- else
- {
- if (!FileToolsCommon.IsExistFile(_modelVideoList[dataIndex].ThumbnailPath))
- {
- continue;
- }
- videoItem = new Uc_VideoItem(_modelVideoList[dataIndex]) { Tag = _modelVideoList[dataIndex].FileGuid };
- videoItem.Click_refreshVideoList += LoadUploadInitData;
- videoItem.Click_UploadLogin += Login;
- videoItem.Width = _controlWidth;
- videoItem.Height = _controlHeight;
- videoItem.HorizontalAlignment = HorizontalAlignment.Left;
- videoItem.VerticalAlignment = VerticalAlignment.Top;
- GridMyVideo.Children.Add(videoItem);
- _videoControlList.Add(videoItem);
- }
- videoItem.Margin = new Thickness
- (
- w,
- h,
- 0,
- 0
- );
- videoItem.Visibility = Visibility.Visible;
- if (w + _controlWidth + _controlWidth > _pageW)
- {
- w = _intervalX;
- h += _controlHeight + _intervalY;
- }
- else
- {
- w += _controlWidth + _intervalX;
- }
- //Uc_VideoItem videoItem = new Uc_VideoItem();
- //return;
- }
- }
-
- /// <summary>
- /// 初始化加载上传页面数据
- /// </summary>
- private void LoadUploadInitData()
- {
- App.myloading.Show();
- //加载视频列表
- LoadingVideoList();
- if (_modelVideoList.Count > 0)
- {
- LblVideoMess.Visibility = Visibility.Hidden;
- BtnVideoUpPage.Visibility = Visibility.Visible;
- LblVideoPageNum.Visibility = Visibility.Visible;
- BtnVideoDownPage.Visibility = Visibility.Visible;
- if (GridMyVideo.ActualHeight > 0)
- {
- _pageW = GridMyVideo.ActualWidth;
- _pageH = GridMyVideo.ActualHeight;
- }
- else
- {
- _pageW = GridRecordingArea.ActualWidth;
- _pageH = GridRecordingArea.ActualHeight;
- }
- //获取设置控件大小 新增 页面原始1061 911
- //ControlWidth = 250.00 * PropWid;
- //ControlHeight = 260.00 * PropHei;
- //ControlWidth=
- //ControlHeight=
- //根据页面大小获取每页显示的数量 H260W250
- int videoRow = (int)((_pageH - 50) / _controlHeight);
- int videColumn = (int)(_pageW / _controlWidth);
- //横向间隔
- _intervalX = (_pageW - (videColumn * _controlWidth)) / (videColumn + 1);
- _intervalY = (_pageH - 50 - (videoRow * _controlHeight)) / (videoRow + 1);
- _pageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
- //获取总页数
- _totalPage = _modelVideoList.Count / _pageShowNum + (_modelVideoList.Count % _pageShowNum > 0 ? 1 : 0);
- //如果当前页大于总页数 总页数为当前页
- if (_totalPage < _currentPage)
- {
- _currentPage = _totalPage;
- }
- LoadCurrentPageData();
- }
- else
- {
- LblVideoMess.Visibility = Visibility.Visible;
- BtnVideoUpPage.Visibility = Visibility.Hidden;
- LblVideoPageNum.Visibility = Visibility.Hidden;
- BtnVideoDownPage.Visibility = Visibility.Hidden;
- //隐藏显示的控件
- if (_videoControlList.Count > 0)
- {
- foreach (Uc_VideoItem item in _videoControlList)
- {
- if (item.Visibility != Visibility.Hidden)
- {
- item.Visibility = Visibility.Hidden;
- }
- }
- }
- }
- App.myloading.Hide();
- }
-
- #region 分页
-
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
- {
- if (_currentPage < _totalPage)
- {
- _currentPage++;
- LoadCurrentPageData();
- }
- }
-
- /// <summary>
- /// 上一页
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
- {
- if (_currentPage > 1)
- {
- _currentPage--;
- LoadCurrentPageData();
- }
- }
-
- #endregion 分页
-
- #endregion 新上传 显示缩略图
-
- #region 录屏
-
- /// <summary>
- /// 录屏事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
- {
- _luoBoPenUtil.lb_device_mouse();
- if (!_microphoneGood)
- {
- MessageWindow.Show("麦克风不可用");
- return;
- }
- if (!_loudspeakerGood)
- {
- MessageWindow.Show("扬声器不可用");
- return;
- }
- PrepareRecord();
- _kHook.Stop();
- if (App.W_ScreenRecordingToolbarWindow == null)
- {
- App.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow { Topmost = true };
- App.W_ScreenRecordingToolbarWindow.Initialize();
- }
- else
- {
- App.W_ScreenRecordingToolbarWindow.Initialize();
- }
- App.W_ScreenRecordingToolbarWindow.ClickStopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
- //显示在右下角
- App.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
- Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
- float dip = graphics.DpiX;
- App.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Width;
- App.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (dip / 96) - App.W_ScreenRecordingToolbarWindow.Height - 100;
- App.W_ScreenRecordingToolbarWindow.Topmost = true;
- App.W_ScreenRecordingToolbarWindow.Show();
- Hide();
- }
-
- /// <summary>
- /// 保存录屏中
- /// </summary>
- private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
- {
- TxbTime.Text = "00:00";
- TxbType.Text = "保存中";
- _recordType = 4;
- RecordBtnStatus();
- new Thread
- (
- () =>
- {
- while (FileToolsCommon.IsExistDirectory(App.WKData.WkPath + "_temppath/"))
- {
- Thread.Sleep(100);
- }
- Thread.Sleep(100);
- Dispatcher.Invoke
- (
- () =>
- {
- _recordType = 0;
- RecordBtnStatus();
- }
- );
- }
- ).Start();
- }
-
- #endregion 录屏
-
- #region 录制窗口
-
- #region 变量
-
- /// <summary>
- /// 录制大小
- /// </summary>
- private int _gridActHeight = 898;
-
- /// <summary>
- /// 录制大小
- /// </summary>
- private int _gridActWidth = 1276;
-
- /// <summary>
- /// 录制类型 0停止,1录制中,2暂停中 3倒计时 4合并中
- /// </summary>
- private int _recordType;
-
- /// <summary>
- /// 录制计时
- /// </summary>
- private DateTime _srTime = DateTime.Now;
-
- /// <summary>
- /// 音频保存路径名
- /// </summary>
- private string _tempAudioPathName;
-
- /// <summary>
- /// 视频合成前路径名
- /// </summary>
- private string _tempVideoPathName;
-
- /// <summary>
- /// 截图定时器
- /// </summary>
- private Timer _timer;
-
- /// <summary>
- /// 视频保存路径名
- /// </summary>
- private string _videoSavePathName;
-
- #endregion 变量
-
- private bool _isPressButton;
-
- //视频写入
- private readonly VideoFileWriter _videoWriter = new VideoFileWriter();
-
- //录制麦克风的声音
- private WaveInEvent _waveIn;
-
- private bool _waveInRuning;
-
- //音频写入
- private WaveFileWriter _writer;
-
- /// <summary>
- /// 录制窗口内容
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void BtnRecord_Click(object sender, RoutedEventArgs e)
- {
- RecordAction();
- }
-
- private async void RecordAction()
- {
- #region 防止连击
-
- if (_isPressButton)
- {
- return;
- }
- _isPressButton = true;
- new Thread
- (
- () =>
- {
- Thread.Sleep(500);
- _isPressButton = false;
- }
- ).Start();
-
- #endregion 防止连击
-
- if (_recordType == 4)
- {
- return;
- }
- if (_recordType != 0)
- {
- if (_recordType == 1)
- {
- //录制中暂停
- _recordType = 2;
- RecordBtnStatus();
- }
- else if (_recordType == 2)
- {
- //暂停中继续录制
- _recordType = 1;
- RecordBtnStatus();
- }
- }
- else
- {
- if (App.PageContextData.currpage == 0)
- {
- MessageWindow.Show("请先导入文档或截图!");
- return;
- }
- StartPauseGrid.Visibility = Visibility.Hidden;
- StopGrid.Visibility = Visibility.Hidden;
- CloseGrid.Visibility = Visibility.Hidden;
- if (!_microphoneGood)
- {
- StartPauseGrid.Visibility = Visibility.Visible;
- StopGrid.Visibility = Visibility.Visible;
- CloseGrid.Visibility = Visibility.Visible;
- MessageWindow.Show("麦克风不可用");
- return;
- }
- BlackboardCanvas.Visibility = Visibility.Visible;
- if (RectImgBorder.Visibility != Visibility.Hidden)
- {
- HideAngleBorder();
- }
- PrepareRecord();
- BtnPrint.IsEnabled = false;
- BtnScreenshot.IsEnabled = false;
- BtnImport.IsEnabled = false;
- BtnScreenRecording.IsEnabled = false;
- BtnUpload.IsEnabled = false;
- BtnSetUp.IsEnabled = false;
- BtnDevice.IsEnabled = false;
- BtnLoginType.IsEnabled = false;
- BlackboardCanvas.Visibility = Visibility.Visible;
- TxbType.Text = "准备录制";
- BtnRecord.Visibility = Visibility.Collapsed;
- BtnRecordSuspend.Visibility = Visibility.Visible;
- BtnRecord.IsEnabled = true;
- BtnStop.IsEnabled = true;
-
- #region 录像倒计时
-
- if (App.W_CountdownWindow == null)
- {
- App.W_CountdownWindow = new CountdownWindow();
- }
- App.W_CountdownWindow.InitAndShow();
-
- #endregion 录像倒计时
-
- await Task.Delay(3000);
- //停止中开始录制
- CloseGrid.Visibility = Visibility.Visible;
- _recordType = 1;
- RecordBtnStatus();
- await StartRecord();
- StartPauseGrid.Visibility = Visibility.Visible;
- StopGrid.Visibility = Visibility.Visible;
- }
- RecordBtnStatus();
- }
-
- private void RecordBtnStatus()
- {
- if (_recordType == 0)
- {
- StartPauseGrid.Visibility = Visibility.Visible;
- TxbType.Text = "准备录制";
- BtnRecord.Visibility = Visibility.Visible;
- BtnRecordSuspend.Visibility = Visibility.Collapsed;
- BtnScreenRecording.IsEnabled = true;
- BtnRecord.IsEnabled = true;
- BtnStop.IsEnabled = false;
- }
- else if (_recordType == 1)
- {
- StartPauseGrid.Visibility = Visibility.Visible;
- TxbType.Text = "录制中";
- BtnRecord.Visibility = Visibility.Collapsed;
- BtnRecordSuspend.Visibility = Visibility.Visible;
- }
- else if (_recordType == 2)
- {
- StartPauseGrid.Visibility = Visibility.Visible;
- TxbType.Text = "暂停中";
- BtnRecord.Visibility = Visibility.Visible;
- BtnRecordSuspend.Visibility = Visibility.Collapsed;
- }
- else if (_recordType == 3)
- {
- TxbType.Text = "倒计时";
- }
- else if (_recordType == 4)
- {
- TxbType.Text = "合并中";
- StartPauseGrid.Visibility = Visibility.Hidden;
- BtnScreenRecording.IsEnabled = false;
- }
- }
-
- /// <summary>
- /// 停止录制窗口内容
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private async void BtnStop_Click(object sender, RoutedEventArgs e)
- {
- #region 防止连击
-
- if (_isPressButton)
- {
- return;
- }
- else
- {
- _isPressButton = true;
- new Thread
- (
- () =>
- {
- Thread.Sleep(500);
- _isPressButton = false;
- }
- ).Start();
- }
-
- #endregion 防止连击
-
- if (_recordType != 0)
- {
- _recordType = 4;
- BlackboardCanvas.Visibility = Visibility.Collapsed;
- RecordBtnStatus();
- //鼠标模式
- _luoBoPenUtil.lb_device_mouse();
- await EndRecord();
- _recordType = 0;
- RecordBtnStatus();
- }
- }
-
- /// <summary>
- /// 停止录制并生成录制文件
- /// </summary>
- private async Task EndRecord()
- {
- #region 恢复被禁用的按钮
-
- BtnScreenshot.IsEnabled = true;
- BtnImport.IsEnabled = true;
- BtnScreenRecording.IsEnabled = true;
- BtnUpload.IsEnabled = true;
- BtnSetUp.IsEnabled = true;
- BtnDevice.IsEnabled = true;
- BtnLoginType.IsEnabled = true;
-
- #endregion 恢复被禁用的按钮
-
- App.PageContextData.currpage = 0;
- App.PageContextData.pagenum = 0;
- myblackboard.clear();
- App.PageDrawList.Clear();
- ImgCanvas.Source = null;
- ImgDocumentation.Source = null;
- ImgPpt.Source = null;
- GridPage.Visibility = Visibility.Collapsed;
- BtnRecord.IsEnabled = false;
- BtnStop.IsEnabled = false;
- BtnScreenRecording.IsEnabled = false;
- _timer.Change(-1, 0);
- _timer.Dispose();
- TxbTime.Text = "00:00";
- TxbType.Text = "保存中";
- _recordType = 4;
- RecordBtnStatus();
- await Task.Run
- (
- () =>
- {
- try
- {
- _videoWriter.Close();
- _waveIn.StopRecording();
-
- //等待音频结束回调
- while (_waveInRuning)
- {
- Thread.Sleep(300);
- }
- Process[] killProcessArray = Process.GetProcessesByName("ffmpeg");
- foreach (Process killProcess in killProcessArray)
- {
- killProcess.Kill();
- }
- FFMpegConverter ffMpeg = new FFMpegConverter();
- FFMpegInput[] input =
- {
- new FFMpegInput(_tempVideoPathName),
- new FFMpegInput(_tempAudioPathName)
- };
-
- // 音视频合并
- ffMpeg.ConvertMedia
- (
- input,
- _videoSavePathName,
- "mp4",
- new OutputSettings()
- );
-
- //生成缩略图
- string thumbnailPath = FileToolsCommon.GetDirectoryName(_videoSavePathName) + "ThumbnailPath/";
- FileToolsCommon.CreateDirectory(thumbnailPath);
- //缩略图存储位置
- string thumbnailPathName = thumbnailPath + FileToolsCommon.GetIOFileName(_videoSavePathName).Replace(".", "") + ".JPG";
- FileToolsCommon.DeleteFile(thumbnailPathName);
- _videoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- _videoInfo.VideoPath = _videoSavePathName;
- _videoInfo.ThumbnailPath = thumbnailPathName;
- _videoInfo.FileGuid = Guid.NewGuid().ToString();
- _videoInfo.IsUpload = false;
- _videoInfo.Uploaded = 0;
- try
- {
- ZVideoRecordHelper.GetVideoPic(_tempVideoPathName, thumbnailPathName);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("录制生成缩略图", ex);
- }
- if (!App.VideoList.Exists(x => x.FileGuid == _videoInfo.FileGuid) || !App.VideoList.Exists(x => x.VideoPath == _videoInfo.VideoPath))
- {
- App.VideoList.Add(_videoInfo);
- //保存数据
- App.SaveWkData();
- }
- try
- {
- FileToolsCommon.DeleteFile(_tempVideoPathName);
- FileToolsCommon.DeleteFile(_tempAudioPathName);
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("删除录制临时文件", ex);
- }
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show(ex.Message);
- }
- );
- }
- }
- );
- BtnRecord.IsEnabled = true;
- BtnStop.IsEnabled = false;
- BtnPrint.IsEnabled = false;
- BtnScreenRecording.IsEnabled = true;
- TxbType.Text = "准备就绪";
- _recordType = 0;
- RecordBtnStatus();
- }
-
- /// <summary>
- /// 录制保存图片
- /// </summary>
- private void RecordSaveImage()
- {
- try
- {
- //保存图片
- try
- {
- Dispatcher.Invoke
- (
- () =>
- {
- Bitmap bm = ImageHelper.SaveUI2Bitmap
- (
- GridMain,
- _gridActWidth,
- _gridActHeight
- );
- _videoWriter.WriteVideoFrame(bm);
- bm.Dispose();
- }
- );
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
- }
- }
-
- //new WaveInEvent();
- /// <summary>
- /// 开始录制和暂停录制
- /// </summary>
- private async Task StartRecord()
- {
- await Task.Run
- (
- () =>
- {
- //电子版切换笔模式
- _luoBoPenUtil.lb_device_hand();
- _videoInfo = new Model_Video
- {
- VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
- WkType = Enum_WKVidetype.RecordingLessons
- };
- FileToolsCommon.DeleteDirectory(App.WKData.WkPath + "temp/");
- FileToolsCommon.CreateDirectory(App.WKData.WkPath);
- _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制." + _videoInfo.VideoType.ToString();
- _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn.avi";
- int num = 1;
- while (FileToolsCommon.IsExistFile(_videoSavePathName))
- {
- _videoSavePathName = App.WKData.WkPath + App.WKData.WkName + "_录制_" + num + "." + _videoInfo.VideoType.ToString();
- _tempVideoPathName = App.WKData.WkPath + App.WKData.WkName + "_录制Syn_" + num + ".avi";
- num++;
- }
- _tempAudioPathName = _tempVideoPathName.Replace(".avi", ".mp3");
- _gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f) / 2) * 2;
- _gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f) / 2) * 2;
- lock (this)
- {
- _videoWriter.Open
- (
- _tempVideoPathName,
- _gridActWidth,
- _gridActHeight,
- 5,
- VideoCodec.MPEG4,
- _gridActWidth * _gridActHeight * 10
- );
- _waveIn = new WaveInEvent();
- _waveInRuning = true;
- _writer = new WaveFileWriter(_tempAudioPathName, _waveIn.WaveFormat);
- //开始录音,写数据
- _waveIn.DataAvailable += (s, a) =>
- {
- if (_recordType == 1)
- {
- _writer.Write
- (
- a.Buffer,
- 0,
- a.BytesRecorded
- );
- }
- };
-
- //结束录音
- _waveIn.RecordingStopped += (s, a) =>
- {
- _writer.Dispose();
- _writer = null;
- _waveIn.Dispose();
- _waveInRuning = false;
- };
- _waveIn.StartRecording();
- }
- }
- );
- _srTime = Convert.ToDateTime("2020-01-01 00:00:00");
- //启动截图
- _timer = new Timer
- (
- Timer_Elapsed,
- null,
- 0,
- 200
- );
- }
-
- /// <summary>
- /// 录制保存图片计时器
- /// </summary>
- /// <param name="sender">
- /// </param>
- private void Timer_Elapsed(object sender)
- {
- if (_recordType == 1)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- _srTime = _srTime.AddMilliseconds(200);
- if (_srTime.Hour > 0)
- {
- TxbTime.Text = _srTime.ToString("HH:mm:ss");
- }
- else
- {
- TxbTime.Text = _srTime.ToString("mm:ss");
- }
- }
- );
- ThreadPool.QueueUserWorkItem
- (
- o =>
- {
- RecordSaveImage();
- }
- );
- }
- }
-
- #endregion 录制窗口
-
- #region 分页
-
- private void ImgXy()
- {
- ImgCanvas.Width = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterX;
- ImgCanvas.Height = App.PageDrawList[App.PageContextData.currpage - 1].ImageSizes.CenterY;
- ImgCanvas.Margin = new Thickness
- (
- App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X,
- App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.Y,
- 0,
- 0
- );
- }
-
- /// <summary>
- /// 跳转
- /// </summary>
- private void JumpPageClick()
- {
- myblackboard.changepage(App.PageContextData.currpage - 1);
- ScroMain.ScrollToVerticalOffset(0);
- if (BtnImport.IsEnabled)
- {
- //截图可用
- BtnScreenshot.IsEnabled = true;
- }
- if (App.PageContextData.currpage <= App.PageDrawList.Count)
- {
- if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null)
- {
- App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = true;
- }
- if (!string.IsNullOrWhiteSpace(TxbCurrpage.Text) && App.PageContextData.currpage <= App.PageDrawList.Count && App.PageContextData.currpage > 0 && !string.IsNullOrWhiteSpace(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath))
- {
- if (App.PageDrawList[App.PageContextData.currpage - 1].ImgDocumentation)
- {
- if ("ppt".Equals(App.PageDrawList[App.PageContextData.currpage - 1].Type))
- {
- ImgCanvas.Source = null;
- ImgDocumentation.Source = null;
- ImgPpt.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
- BtnScreenshot.IsEnabled = false;
- }
- else
- {
- ImgPpt.Source = null;
- ImgCanvas.Source = null;
- ImgDocumentation.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
- BtnScreenshot.IsEnabled = false;
- }
- }
- else
- {
- ImgPpt.Source = null;
- ImgDocumentation.Source = null;
- ImgCanvas.Source = new BitmapImage(new Uri(App.PageDrawList[App.PageContextData.currpage - 1].PageImagePath));
- App.PageDrawList[App.PageContextData.currpage - 1].IsImageLocation = false;
- if (App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation != null && App.PageDrawList[App.PageContextData.currpage - 1].ImageLocation.X > 0)
- {
- _mouseDown = false;
- _imageOperationUtil.setMouseDown(_mouseDown);
- ImgXy();
- }
- }
- }
- else
- {
- ImgPpt.Source = null;
- ImgCanvas.Source = null;
- ImgDocumentation.Source = null;
- }
- }
- }
-
- // 上一页
- private void last_button_Click(object sender, RoutedEventArgs e)
- {
- if (App.PageContextData.currpage > 1)
- {
- _mouseDown = false;
- _imageOperationUtil.setMouseDown(_mouseDown);
- HideAngleBorder();
- App.PageContextData.currpage -= 1;
- JumpPageClick();
- }
- }
-
- /// <summary>
- /// 下一页
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void next_btn_Click(object sender, RoutedEventArgs e)
- {
- if (App.PageContextData.currpage < App.PageContextData.pagenum)
- {
- _mouseDown = false;
- _imageOperationUtil.setMouseDown(_mouseDown);
- HideAngleBorder();
- App.PageContextData.currpage += 1;
- JumpPageClick();
- }
- }
-
- #endregion 分页
-
- #region 图像缩放,移动
-
- private bool _mouseDown;
-
- #endregion 图像缩放,移动
-
- #region 更改设备连接状态
-
- /// <summary>
- /// 更新设备状态显示
- /// </summary>
- public void UpdateDevStatus()
- {
- if (App.BoardStatus && (App.PenStatus || App.TQLPenStatus))
- {
- Dispatcher.Invoke
- (
- () =>
- {
- TxbNotConnected.Text = "笔/板已连接";
- TxbNotConnecteds.Text = "笔/板已连接";
- }
- );
- }
- else if (App.BoardStatus)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- TxbNotConnected.Text = "手写板已连接";
- TxbNotConnecteds.Text = "手写板已连接";
- }
- );
- }
- else if (App.PenStatus)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- TxbNotConnected.Text = "智能笔已连接";
- TxbNotConnecteds.Text = "智能笔已连接";
- }
- );
- }
- else if (App.TQLPenStatus)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- TxbNotConnected.Text = "智能笔已连接";
- TxbNotConnecteds.Text = "智能笔已连接";
- }
- );
- }
- else
- {
- Dispatcher.Invoke
- (
- () =>
- {
- TxbNotConnected.Text = "未连接";
- TxbNotConnecteds.Text = "未连接";
- }
- );
- }
- }
-
- #endregion 更改设备连接状态
-
- #region 腾千里手写笔
-
- private const float TQLA4_HEIGHT = 1.0f * 3509 / 300 * (float)25.4 / (float)1.524;
-
- /// <summary>
- /// TQL点阵笔宽高
- /// </summary>
- private const float TQLA4_WIDTH = 1.0f * 2480 / 300 * (float)25.4 / (float)1.524;
-
- /// <summary>
- /// 是否在书写
- /// </summary>
- private bool _isTqlPenDown;
-
- //(float)1075 / (float)150 * (float)25.4 / (float)1.524; //OID4
-
- //(float)1512 / (float)150 * (float)25.4 / (float)1.524;
-
- /// <summary>
- /// TQL初始化
- /// </summary>
- public void InitTqlpPen()
- {
- if (App.TQLPenevents == null)
- {
- App.TQLPenevents = new PenEvents(1);
- }
- else
- {
- App.TQLPenevents.InToType = 1;
- }
- }
-
- /// <summary>
- /// 笔落下
- /// </summary>
- public void TqlDown()
- {
- _isTqlPenDown = true;
- if (App.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- myblackboard.changepages
- (
- 0,
- 0,
- true,
- _color,
- _penSize,
- App.PageContextData.currpage - 1,
- 0
- );
- }
- );
- }
- }
-
- /// <summary>
- /// 笔书写
- /// </summary>
- /// <param name="cx">
- /// </param>
- /// <param name="cy">
- /// </param>
- /// <param name="force">
- /// </param>
- public void TqlPenWrite
- (
- double cx,
- double cy,
- int force
- )
- {
- //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
- if (!_isTqlPenDown)
- {
- return;
- }
- double propW = BlackboardCanvas.ActualWidth / TQLA4_WIDTH;
- double propH = BlackboardCanvas.ActualHeight / TQLA4_HEIGHT;
- //点
- double tempX = cx * propW;
- double tempY = cy * propH;
- if (App.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- //0~1023,亦即有 1024 阶供应用软件后续应用之用,如笔锋笔触,暂无用
- float pressure = 1.0f * force / 1023f;
- myblackboard.changepages
- (
- tempX,
- tempY,
- false,
- _color,
- _penSize,
- App.PageContextData.currpage - 1,
- pressure
- );
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (tempY < ScroMain.VerticalOffset)
- {
- //滚动条当前位置
- double rollCurrentLocation = ScroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double rollLocation = rollCurrentLocation - upRoll;
- if (rollLocation < 0)
- {
- rollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- ScroMain.ScrollToVerticalOffset(rollLocation);
- }
- //点在显示页面下方
- if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
- {
- //滚动条当前位置
- double rollCurrentLocation = ScroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double downRoll = (tempY - 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 设置滚动条位置
-
- if (tempX > 0 && tempY > 0)
- {
- System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }
- );
- }
- }
-
- /// <summary>
- /// 笔抬起
- /// </summary>
- public void TqlUp()
- {
- _isTqlPenDown = false;
- //stroke.Clear();
- if (App.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- myblackboard.changepages
- (
- 0,
- 0,
- true,
- _color,
- _penSize,
- App.PageContextData.currpage - 1,
- 0
- );
- }
- );
- }
- }
-
- #endregion 腾千里手写笔
-
- #region 图片拉伸移动
-
- /// <summary>
- /// 隐藏图片四个点和线
- /// </summary>
- private void HideAngleBorder()
- {
- _imageOperationUtil.HideAngleBorder();
- }
-
- private void imgCanvas_MouseMove(object sender, MouseEventArgs e)
- {
- _imageOperationUtil.imgCanvas_MouseMove(sender, e);
- }
-
- private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
- {
- _imageOperationUtil.imgCanvas_MouseUp();
- }
-
- private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
- {
- _imageOperationUtil.PicEMap_MouseDown(sender, e);
- }
-
- private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
- {
- _imageOperationUtil.RectRightUp_DragCompleted();
- }
-
- private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
- {
- _imageOperationUtil.RectRightUp_DragDelta(sender, e);
- }
-
- private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
- {
- _imageOperationUtil.RectRightUp_DragStarted(sender, e);
- }
-
- /// <summary>
- /// 鼠标左键点击事件
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
- {
- _imageOperationUtil.Window_MouseLeftButtonDown_1();
- }
-
- #endregion 图片拉伸移动
-
- #region 录屏 录制 截图 导入文档 增加 主页面显示
-
- /// <summary>
- /// 录屏 录制 截图 导入文档 增加 主页面显示
- /// </summary>
- private void PrepareRecord()
- {
- PageHide();
- GridMain.Visibility = Visibility.Visible;
- GridRecordingTitle.Visibility = Visibility.Visible;
- if (App.PageContextData.pagenum > 0)
- {
- GridPage.Visibility = Visibility.Visible;
- }
- DataContext = App.PageContextData;
- }
-
- #endregion 录屏 录制 截图 导入文档 增加 主页面显示
-
- #region 页码跳转
-
- #endregion 页码跳转
-
- #region TQL打印
-
- public static string gPrintFileName;
-
- private iTextSharp.text.Document _document;
-
- private bool _gbInitDone;
-
- /// <summary>
- /// 授权码
- /// </summary>
- private string _gKeyStr;
-
- private readonly TmatrixClass _tmc = new TmatrixClass();
-
- /// <summary>
- /// 授权文件位置
- /// </summary>
- private string _tqlAuthorizationPath;
-
- /// <summary>
- /// 铺码
- /// </summary>
- private bool GenerateCode(string pdfPath)
- {
- try
- {
- if (_gbInitDone == false)
- {
- MessageWindow.Show("打印功能无法使用,无效授权。");
- return false;
- }
- try
- {
- string directoryPath = FileToolsCommon.GetDirectoryName(pdfPath);
- FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Images/");
- FileToolsCommon.DeleteDirectory(directoryPath + "Bg with Vector Images/");
- FileToolsCommon.DeleteDirectory(directoryPath + "Bg without Vector Images/");
- FileToolsCommon.DeleteDirectory(directoryPath + "Vector Images/");
- }
- catch (Exception)
- {
- // ignored
- }
- pdfPath = pdfPath.Replace("/", "\\");
-
- //初始页
- bool[] bPublishImageType = new bool[4];
- bPublishImageType[0] = false;
- bPublishImageType[1] = false;
- bPublishImageType[2] = false;
- bPublishImageType[3] = true;
- int[] gPointType =
- {
- 0,
- 0,
- 0,
- 0,
- 1
- };
- int[] gPointDpi =
- {
- 0,
- 0,
- 0,
- 0,
- 1
- };
- string sGenerateResult = _tmc.GenerateTmatrixCode_OID4
- (
- _gKeyStr,
- pdfPath,
- 0,
- gPointType,
- bPublishImageType,
- gPointDpi
- );
- if (sGenerateResult.Substring(0, 1) == "1")
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show("打印功能无法使用,无效授权。");
- }
- );
- return false;
- }
- return true;
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show("打印失败:" + ex.Message);
- }
- );
- return false;
- }
- }
-
- /// <summary>
- /// TQL初始化打印
- /// </summary>
- private void TqlPrintInit()
- {
- //初始化
- if (_tmc.TmatrixInitialize() == false)
- {
- }
- else
- {
- _gbInitDone = true;
- }
- _document = new iTextSharp.text.Document
- (
- iTextSharp.text.PageSize.A4,
- 0,
- 0,
- 0,
- 0
- );
- try
- {
- _tqlAuthorizationPath = FileToolsCommon.GetFileAbsolutePath("/LatticeXML/S0_O000_B0000_P000-255.tmx");
- StreamReader gsr = new StreamReader(_tqlAuthorizationPath);
- _gKeyStr = gsr.ReadLine();
- gsr.Close();
- string keyCheckResult = _tmc.TmatrixKeyCheck_OID4(_gKeyStr);
- if (keyCheckResult.Substring(0, 1) == "1")
- {
- MessageWindow.Show("打印服务授权过期,请联系厂家更换授权!");
- LogHelper.WriteErrLog("打印服务授权过期:" + keyCheckResult, null);
- _gbInitDone = false;
- }
- else if (keyCheckResult.Substring(0, 1) == "0")
- {
- }
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("打印服务授权失败:" + ex.Message, ex);
- MessageWindow.Show("打印服务授权失败,请联系厂家!");
- _gbInitDone = false;
- }
- }
-
- #endregion TQL打印
-
- #region 打印界面
-
- private double _hei;
-
- private int _msgnum;
-
- private int _num;
-
- /// <summary>
- /// 打印状态消息
- /// </summary>
- private string _printMsg = "打印中";
-
- /// <summary>
- /// 打印进度
- /// </summary>
- private System.Timers.Timer _timesPrint;
-
- /// <summary>
- /// 打印消息
- /// </summary>
- private System.Timers.Timer _timesPrintMsg;
-
- private double _wit;
-
- /// <summary>
- /// 初始化页面
- /// </summary>
- /// <param name="imgPath">
- /// </param>
- /// <param name="wit">
- /// </param>
- /// <param name="hei">
- /// </param>
- public void InitializePrint
- (
- string imgPath,
- double wit,
- double hei
- )
- {
- this._wit = wit;
- this._hei = hei;
- if (!string.IsNullOrWhiteSpace(imgPath))
- {
- ImgPri.Source = new BitmapImage(new Uri(imgPath));
- }
- else
- {
- ImgPri.Source = null;
- }
- GridPrintMask.Visibility = Visibility.Collapsed;
- }
-
- /// <summary>
- /// 打印初始化
- /// </summary>
- public void InitPrint()
- {
- ResizeMode = ResizeMode.NoResize;
- TqlPrintInit();
- }
-
- /// <summary>
- /// 生成图片
- /// </summary>
- /// <param name="path">
- /// 图片地址
- /// </param>
- /// <param name="saveimg">
- /// 保存位置
- /// </param>
- /// <param name="rectangle">
- /// 图片位置
- /// </param>
- /// <returns>
- /// </returns>
- private bool MergerPrintImg
- (
- string path,
- string saveimg,
- RectangleF rectangle
- )
- {
- try
- {
- Bitmap bitmap = null;
-
- //创建要显示的图片对象,根据参数的个数设置宽度
- Bitmap backgroudImg = new Bitmap((int) /*GridM.ActualWidth*/_wit, (int) /*GridM.ActualHeight*/_hei);
- Graphics g = Graphics.FromImage(backgroudImg);
- //清除画布,背景设置为白色
- g.Clear(System.Drawing.Color.White);
- if (!string.IsNullOrWhiteSpace(path))
- {
- bitmap = ImageHelper.ReadBitmapFile(path);
- g.DrawImage(bitmap, rectangle);
- }
-
- #region 添加箭头
-
- string str = "↑";
- SolidBrush mybrush = new SolidBrush(System.Drawing.Color.Black); //设置默认画刷颜色
- Font myfont = new Font("黑体", 14); //设置默认字体格式
- g.DrawString
- (
- str,
- myfont,
- mybrush,
- new Rectangle
- (
- (int)_wit - 50,
- 20,
- 50,
- 50
- )
- );
-
- #endregion 添加箭头
-
- backgroudImg.Save(saveimg);
- g.Dispose();
- backgroudImg.Dispose();
- if (bitmap != null)
- {
- bitmap.Dispose();
- }
- GC.Collect();
- return true;
- }
- catch (Exception ex)
- {
- LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
- return false;
- }
- }
-
- /// <summary>
- /// 开始打印
- /// </summary>
- private void StartPrint(PrintModel printModel)
- {
- try
- {
- _document = new iTextSharp.text.Document
- (
- iTextSharp.text.PageSize.A4,
- 0f,
- 0f,
- 0f,
- 0f
- );
- _printMsg = "生成文件";
- _msgnum = 0;
- string sourcePath1 = printModel.filepath;
- try
- {
- sourcePath1 = sourcePath1.Replace("/", "\\");
- FileStream fs = new FileStream
- (
- sourcePath1,
- FileMode.Create,
- FileAccess.ReadWrite
- );
- _document.AddAuthor("星火微课"); //作者
- _document.AddCreationDate(); //创建时候
- _document.AddCreator("星火微课"); //创建者
- _document.AddSubject("点阵文件"); //主题
- _document.AddTitle("PrintTmatrixCode"); //标题
- _document.AddKeywords("Print");
- _document.AddHeader("TmatrixCode", "0");
- iTextSharp.text.pdf.PdfWriter.GetInstance(_document, fs);
- }
- catch (Exception)
- {
- // ignored
- }
- _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();
- MergerPrintImg
- (
- "",
- filePathOutPut,
- rectangleFs
- );
- image = iTextSharp.text.Image.GetInstance(filePathOutPut);
- if (string.IsNullOrEmpty(App.PageDrawList[i].PageImagePath)) //没有图片
- {
- }
- else if (App.PageDrawList[i].ImgDocumentation && !App.PageDrawList[i].Type.Equals("ppt"))
- {
- image = iTextSharp.text.Image.GetInstance(App.PageDrawList[i].PageImagePath);
- }
- else
- {
- RectangleF rectangleF = new RectangleF
- (
- 0,
- 0,
- 0,
- 0
- );
- var i1 = i;
- Dispatcher.Invoke
- (
- () =>
- {
- rectangleF = new RectangleF
- {
- Width = (float)App.PageDrawList[i1].ImageSizes.CenterX,
- Height = (float)App.PageDrawList[i1].ImageSizes.CenterY,
- X = (float)App.PageDrawList[i1].ImageLocation.X,
- Y = (float)App.PageDrawList[i1].ImageLocation.Y
- };
- }
- );
- bool isImg = MergerPrintImg
- (
- App.PageDrawList[i].PageImagePath,
- filePathOutPut,
- rectangleF
- );
- 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)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
- }
- else if (image.Width > iTextSharp.text.PageSize.A4.Width)
- {
- image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
- }
- image.Alignment = iTextSharp.text.Element.ALIGN_MIDDLE;
- _document.NewPage();
- _document.Add(image);
- }
- _document.Close();
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- BtnPrint.IsEnabled = true;
- _timesPrint.Stop();
- _timesPrintMsg.Stop();
- GridPrintMask.Visibility = Visibility.Collapsed;
- MessageWindow.Show(ex.Message);
- }
- );
- LogHelper.WriteErrLog("打印转换PDF失败,原因:" + ex.Message, ex);
- }
- //PDF位置
- string sourcePath = printModel.filepath;
- if (_isHasCode)
- {
- _printMsg = "铺码中";
- _msgnum = 0;
- Thread.Sleep(500);
-
- //腾千里生成点阵文件
- if (GenerateCode(sourcePath))
- {
- //打印机名称
- string directoryPath = FileToolsCommon.GetDirectoryName(sourcePath) + "Bg with Images/";
- string[] strs = FileToolsCommon.GetFileNames(directoryPath);
- try
- {
- // 腾千里会根据原PDF的页数生成多个PDF文件
- for (int i = 0; i < strs.Count(); i++)
- {
- _timesPrint.Stop();
- _printMsg = "正在打印第" + (i + 1) + "/" + strs.Count() + "页中";
- _msgnum = 0;
- _num = 0;
- _timesPrint.Interval = 100;
- _timesPrint.Start();
- string fileName = strs[i];
-
- //打印文件
- ZPrintUtils.Print2(fileName);
- }
- Dispatcher.Invoke
- (
- () =>
- {
- BtnPrint.IsEnabled = true;
- _num = 99;
- _timesPrint.Stop();
- PgbProcess.Value = 100;
- LbProcess.Content = "100%";
- GridPrintMask.Visibility = Visibility.Collapsed;
- //MessageWindow.Show("已加入打印机队列,打印中。");
- }
- );
- }
- catch (Exception ex)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- MessageWindow.Show("打印失败:" + ex.Message);
- BtnPrint.IsEnabled = true;
- _timesPrint.Stop();
- GridPrintMask.Visibility = Visibility.Collapsed;
- }
- );
- }
- }
- else
- {
- Dispatcher.Invoke
- (
- () =>
- {
- BtnPrint.IsEnabled = true;
- _timesPrint.Stop();
- _timesPrintMsg.Stop();
- GridPrintMask.Visibility = Visibility.Collapsed;
- }
- );
- }
- }
- else
- {
- //打印文件
- ZPrintUtils.Print2(sourcePath);
- Dispatcher.Invoke
- (
- () =>
- {
- BtnPrint.IsEnabled = true;
- _num = 99;
- _timesPrint.Stop();
- PgbProcess.Value = 100;
- LbProcess.Content = "100%";
- GridPrintMask.Visibility = Visibility.Collapsed;
- //MessageWindow.Show("已加入打印机队列,打印中。");
- }
- );
- }
- }
-
- /// <summary>
- /// 计时器
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void Times_ElapsedClick(object sender, System.Timers.ElapsedEventArgs e)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- PgbProcess.Value = _num;
- LbProcess.Content = _num + "%";
- if (_num < 99)
- {
- _num++;
- _timesPrint.Interval += 1.0 * _num / 2;
- }
- else
- {
- _timesPrint.Stop();
- }
- }
- );
- }
-
- /// <summary>
- /// 消息
- /// </summary>
- /// <param name="sender">
- /// </param>
- /// <param name="e">
- /// </param>
- private void TimesPrintMsg_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- if (_msgnum > 5)
- _msgnum = 0;
- else
- _msgnum++;
- string point = "";
- point = point.PadRight(_msgnum, '.');
- Dispatcher.Invoke
- (
- () =>
- {
- LabPrintMessage.Content = _printMsg + point;
- }
- );
- }
-
- #endregion 打印界面
-
- #region 笔事件回调
-
- public void penPointEvent
- (
- byte bIndex,
- byte bPenStatus,
- short bx,
- short by,
- short bPress,
- int mNDeviceW,
- int mNDeviceH
- )
- {
- //17是按下,16是抬起
- if (bPenStatus == 16 || bPenStatus == 0)
- {
- //stroke.Clear();
- if (App.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- myblackboard.changepages
- (
- 0,
- 0,
- true,
- _color,
- _penSize,
- App.PageContextData.currpage - 1,
- 0
- );
- }
- );
- }
- }
- double propW = BlackboardCanvas.ActualWidth / mNDeviceH;
- double propH = BlackboardCanvas.ActualHeight / mNDeviceW;
- //点
- double tempY = (mNDeviceW - bx) * propH;
- double tempX = by * propW;
- //pageSerial //点阵IP地址 与打印的页面关联
- if (App.PageContextData.currpage > 0)
- {
- Dispatcher.Invoke
- (
- () =>
- {
- float pressure = bPress / 100f;
- if (bPress > 0)
- {
- myblackboard.changepages
- (
- tempX,
- tempY,
- false,
- _color,
- _penSize,
- App.PageContextData.currpage - 1,
- pressure
- );
- }
-
- #region 设置滚动条位置
-
- //点在显示页面上方
- if (tempY < ScroMain.VerticalOffset)
- {
- //滚动条当前位置
- double rollCurrentLocation = ScroMain.VerticalOffset;
- //向上滚动至以点为中心需要滚动的距离
- double upRoll = (rollCurrentLocation - tempY) + (ScroMain.ActualHeight / 2);
- //如果小于0则等于0
- double rollLocation = rollCurrentLocation - upRoll;
- if (rollLocation < 0)
- {
- rollLocation = 0;
- }
- ////滚动条实际偏移量
- //double RollOffset = RollCurrentLocation - RollLocation;
- ScroMain.ScrollToVerticalOffset(rollLocation);
- }
- //点在显示页面下方
- if (tempY > ScroMain.VerticalOffset + ScroMain.ActualHeight)
- {
- //滚动条当前位置
- double rollCurrentLocation = ScroMain.VerticalOffset;
- //向下滚动至以点为中心需要滚动的距离
- double downRoll = (tempY - 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 设置滚动条位置
-
- if (tempX > 0 && tempY > 0)
- {
- //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
- System.Windows.Point getP = ScroMain.PointToScreen(new System.Windows.Point(tempX, tempY - ScroMain.VerticalOffset));
- SetCursorPos((int)getP.X, (int)getP.Y);
- }
- }
- );
- }
- }
-
- public void penStatusEvent()
- {
- UpdateDevStatus();
- }
-
- #endregion 笔事件回调
-
- private void Window_Closed(object sender, EventArgs e)
- {
- Environment.Exit(0);
- }
- }
- }
|