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

XHMicroLessonSystemWindow.xaml.cs 232KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249
  1. using Aspose.Slides;
  2. using Aspose.Words;
  3. using Aspose.Words.Saving;
  4. using ComeCapture;
  5. using Common.system;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Controls.Primitives;
  19. using System.Windows.Forms;
  20. using System.Windows.Ink;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Threading;
  25. using TStudyDigitalPen.HID;
  26. using XHWK.Model;
  27. using XHWK.WKTool.DAL;
  28. using XHWK.WKTool.UControl;
  29. namespace XHWK.WKTool
  30. {
  31. /// <summary>
  32. /// 主页面
  33. /// </summary>
  34. public partial class XHMicroLessonSystemWindow : Window
  35. {
  36. #region 字段
  37. /// <summary>
  38. /// 页码下拉列表
  39. /// </summary>
  40. List<PageData> PageData =null;
  41. private FolderBrowserDialog Ofd;
  42. private DialogResult Result;
  43. public BlackboardNew myblackboard;
  44. private System.Windows.Forms.DialogResult result;
  45. private System.Windows.Forms.OpenFileDialog ofd;
  46. //声明一个 DrawingAttributes 类型的变量
  47. private DrawingAttributes drawingAttributes;
  48. private Model_Video VideoInfo = null;
  49. ////定义事件
  50. //public event ChangeTextHandler ChangeTextEvent;
  51. //定义委托
  52. public delegate void ChangeTextHandler(string text);
  53. //定义委托
  54. public delegate void ChangeTextHandlers(string text, int i);
  55. /// <summary>
  56. /// 图片
  57. /// </summary>
  58. private string[] ImgPDFPath = new string[300];
  59. /// <summary>
  60. /// 当前颜色
  61. /// </summary>
  62. private System.Windows.Media.Color Color = System.Windows.Media.Colors.Red;
  63. /// <summary>
  64. /// 笔迹粗细
  65. /// </summary>
  66. private int PenSize = 2;
  67. //private DispatcherTimer t = null;
  68. /// <summary>
  69. /// 计时器状态
  70. /// </summary>
  71. private enum State
  72. {
  73. Start,
  74. Pause,
  75. End
  76. }
  77. /// <summary>
  78. /// 状态
  79. /// </summary>
  80. private State _state = State.End;
  81. /// <summary>
  82. /// 计时用
  83. /// </summary>
  84. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  85. #region 上传
  86. /// <summary>
  87. /// 视频模型
  88. /// </summary>
  89. private List<Model_Video> model_VideoList = null;
  90. /// <summary>
  91. /// 数据列表
  92. /// </summary>
  93. internal FileDirectoryData pageData = new FileDirectoryData();
  94. /// <summary>
  95. /// 下标
  96. /// </summary>
  97. private int Subscript = 0;
  98. /// <summary>
  99. /// 是否是修改状态
  100. /// </summary>
  101. private bool IsModify = false;
  102. #endregion
  103. private double screeHeight = SystemParameters.FullPrimaryScreenHeight;
  104. private double screeWidth = SystemParameters.FullPrimaryScreenWidth;
  105. /// <summary>
  106. /// 键盘钩子
  107. /// </summary>
  108. private KeyboardHookCommon k_hook;
  109. #endregion
  110. #region 初始化
  111. /// <summary>
  112. /// 主页面
  113. /// </summary>
  114. public XHMicroLessonSystemWindow()
  115. {
  116. new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  117. new Aspose.Pdf.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  118. new Aspose.Slides.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4xOTA4MjYwODA3NTM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+M2U0NGRlMzAtZmNkMi00MTA2LWIzNWQtNDZjNmEzNzE1ZmMyPC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjAwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT53UGJtNUt3ZTYvRFZXWFNIY1o4d2FiVEFQQXlSR0pEOGI3L00zVkV4YWZpQnd5U2h3YWtrNGI5N2c2eGtnTjhtbUFGY3J0c0cwd1ZDcnp6MytVYk9iQjRYUndTZWxsTFdXeXNDL0haTDNpN01SMC9jZUFxaVZFOU0rWndOQkR4RnlRbE9uYTFQajhQMzhzR1grQ3ZsemJLZFZPZXk1S3A2dDN5c0dqYWtaL1E9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
  119. InitializeComponent();
  120. float WorkW = PrimaryScreen.ScaleWorkingAreaSize.Width;
  121. float WorkH = PrimaryScreen.ScaleWorkingAreaSize.Height;
  122. double proportion = 1036.0 / 1290.0;
  123. //限制大小 确保大屏幕下录制不会卡死 暂时
  124. if (WorkW > 1920.0)
  125. {
  126. Width = 1920;
  127. Height = 1036;
  128. }
  129. else
  130. {
  131. Width = (PrimaryScreen.ScaleWorkingAreaSize.Height) / proportion - (BorderThickness.Left + BorderThickness.Right);
  132. Height = PrimaryScreen.ScaleWorkingAreaSize.Height - (BorderThickness.Top + BorderThickness.Bottom);
  133. }
  134. GridContent.Width = Width - 14;
  135. GridContent.Height = Height;
  136. #region 读取本地配置
  137. if (File.Exists(APP.dataPath + "interfaceAddress.txt")) //若不为空
  138. {
  139. APP.apiUrl = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default);
  140. }
  141. if (File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若不为空
  142. {
  143. APP.uploadUrl = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default);
  144. }
  145. if (File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若不为空
  146. {
  147. APP.showImageUrl = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default);
  148. }
  149. #endregion
  150. //GridMain.Height= PrimaryScreen.ScaleScreenSize().Height - 40;
  151. //this.Top = (screeHeight - this.Height) / 2;
  152. //this.Left = (screeWidth - this.Width) / 2;
  153. ResizeMode = System.Windows.ResizeMode.CanMinimize;
  154. btnPrint.IsEnabled = false;
  155. myblackboard = new BlackboardNew(blackboard_canvas);
  156. APP.pageData.pagenum = 0;
  157. APP.pageData.currpage = 0;
  158. DataContext = APP.pageData;
  159. //APP.SaveDraw();//画板模型第一页初始化
  160. APP.PageDrawList = new List<Model_DrawData>();
  161. Model_DrawData model_DrawData = new Model_DrawData
  162. {
  163. PageNum = APP.pageData.currpage
  164. };
  165. APP.PageDrawList.Add(model_DrawData);
  166. txbv.Text = "v" + FileToolsCommon.GetConfigValue("VersionName");
  167. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoType");
  168. if (FileToolsCommon.GetConfigValue("IsSound").Equals("true"))
  169. {
  170. rbnY.IsChecked = true;
  171. }
  172. else
  173. {
  174. rbnN.IsChecked = true;
  175. }
  176. txbStoragePath.Content = FileToolsCommon.GetConfigValue("VideoSavePath");
  177. Initialize();
  178. InitPen();
  179. }
  180. /// <summary>
  181. /// 初始化
  182. /// </summary>
  183. public void Initialize()
  184. {
  185. if (APP.isDebug)
  186. {
  187. txbVersion.Text = "测试版:";
  188. }
  189. else
  190. {
  191. txbVersion.Text = "正式版:";
  192. }
  193. #region 数据初始化
  194. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  195. FileToolsCommon.CreateDirectory(pathTemp);
  196. APP.pageData.pagenum = 0;
  197. APP.pageData.currpage = APP.pageData.pagenum;
  198. btnStop.IsEnabled = false;//停止录制按钮不可点击
  199. #endregion
  200. k_hook = new KeyboardHookCommon();
  201. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  202. k_hook.Start();//安装键盘钩子
  203. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  204. //创建 DrawingAttributes 类的一个实例
  205. drawingAttributes = new DrawingAttributes();
  206. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  207. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  208. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  209. blackboard_canvas.UseCustomCursor = true;
  210. drawingAttributes.FitToCurve = true;
  211. drawingAttributes.IgnorePressure = false;
  212. drawingAttributes.Width = PenSize;
  213. drawingAttributes.Height = PenSize;
  214. drawingAttributes.Color = Color;
  215. blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  216. //wfhCamera.Visibility = Visibility.Hidden;
  217. ImgPDFPath = null;
  218. ImgPDFPath = new string[300];
  219. //gridM.Height = gridM.ActualWidth / proportion;
  220. //gridM.Height = gridM.Width / proportion;
  221. }
  222. /// <summary>
  223. /// 初始化快捷键
  224. /// </summary>
  225. public void InitializeKeyDownEvent()
  226. {
  227. k_hook.Start();//安装键盘钩子
  228. }
  229. /// <summary>
  230. /// 快捷键
  231. /// </summary>
  232. /// <param name="sender"></param>
  233. /// <param name="e"></param>
  234. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  235. {
  236. if (e.KeyValue == (int)System.Windows.Forms.Keys.Left)
  237. {
  238. if (APP.pageData.currpage > 1)
  239. {
  240. //上一页
  241. last_button_Click(null, null);
  242. }
  243. }
  244. if (e.KeyValue == (int)System.Windows.Forms.Keys.Right)
  245. {
  246. if (APP.pageData.currpage < APP.pageData.pagenum)
  247. {
  248. //下一页
  249. next_btn_Click(null, null);
  250. }
  251. }
  252. if (e.KeyValue == (int)System.Windows.Forms.Keys.Delete)
  253. {
  254. if (RectImgBorder.Visibility != Visibility.Hidden)
  255. {
  256. HideAngleBorder();
  257. imgCanvas.Source = null;
  258. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = null;
  259. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = null;
  260. }
  261. }
  262. }
  263. #endregion
  264. #region 事件
  265. /// <summary>
  266. /// 窗体移动
  267. /// </summary>
  268. /// <param name="sender"></param>
  269. /// <param name="e"></param>
  270. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  271. {
  272. DragMove();
  273. }
  274. #region 摄像头
  275. private System.Timers.Timer times;
  276. private List<string> RbnOpen;
  277. private bool IsRbnOpen = false;
  278. /// <summary>
  279. /// 摄像头打开事件
  280. /// </summary>
  281. /// <param name="sender"></param>
  282. /// <param name="e"></param>
  283. private void RbnOpen_Click(object sender, RoutedEventArgs e)
  284. {
  285. if (!IsRbnOpen)
  286. {
  287. #region 防止连击
  288. if (IsPressButton)
  289. {
  290. return;
  291. }
  292. else
  293. {
  294. IsPressButton = true;
  295. new Thread(new ThreadStart(new Action(() =>
  296. {
  297. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = false; }));
  298. Thread.Sleep(500);
  299. //Dispatcher.Invoke(new Action(() => { rbnTurnOff.IsEnabled = true; }));
  300. IsPressButton = false;
  301. }))).Start();
  302. }
  303. #endregion
  304. CameraHelper.UpdateCameraDevices();
  305. if (CameraHelper.CameraDevices.Count > 0)
  306. {
  307. CameraHelper.SetCameraDevice(0);
  308. RbnOpen = new List<string>();
  309. times = new System.Timers.Timer(200)//初始值为300
  310. {
  311. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  312. };//设置执行一次(false)还是一直执行(true)
  313. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  314. times.Enabled = true; //启动计时器
  315. IsRbnOpen = true;
  316. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  317. FileToolsCommon.CreateDirectory(imgPath);
  318. }
  319. }
  320. }
  321. private int I = 9999;
  322. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  323. {
  324. if (IsRbnOpen)
  325. {
  326. try
  327. {
  328. Dispatcher.Invoke(() =>
  329. {
  330. if (I > 10010)
  331. {
  332. long time = Timestamp();
  333. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayer");
  334. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  335. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  336. if (!string.IsNullOrWhiteSpace(path))
  337. {
  338. RbnOpen.Add(path);
  339. imgPlayerRight.Visibility = Visibility.Visible;
  340. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  341. if ("1".Equals(APP.CameraPosition))
  342. {
  343. imgPlayerRight.Visibility = Visibility.Visible;
  344. imgPlayerLeft.Visibility = Visibility.Collapsed;
  345. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  346. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  347. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  348. }
  349. else if ("2".Equals(APP.CameraPosition))
  350. {
  351. imgPlayerRight.Visibility = Visibility.Collapsed;
  352. imgPlayerLeft.Visibility = Visibility.Visible;
  353. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  354. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  355. imgPlayerLeft.Source = new BitmapImage(new Uri(path));
  356. }
  357. else if ("3".Equals(APP.CameraPosition))
  358. {
  359. imgPlayerRight.Visibility = Visibility.Collapsed;
  360. imgPlayerLeft.Visibility = Visibility.Collapsed;
  361. imgPlayerRightUnder.Visibility = Visibility.Visible;
  362. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  363. imgPlayerRightUnder.Source = new BitmapImage(new Uri(path));
  364. }
  365. else if ("4".Equals(APP.CameraPosition))
  366. {
  367. imgPlayerRight.Visibility = Visibility.Collapsed;
  368. imgPlayerLeft.Visibility = Visibility.Collapsed;
  369. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  370. imgPlayerLeftUnder.Visibility = Visibility.Visible;
  371. imgPlayerLeftUnder.Source = new BitmapImage(new Uri(path));
  372. }
  373. else
  374. {
  375. imgPlayerLeft.Visibility = Visibility.Collapsed;
  376. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  377. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  378. imgPlayerRight.Source = new BitmapImage(new Uri(path));
  379. }
  380. }
  381. }
  382. I++;
  383. });
  384. }
  385. catch (Exception ex)
  386. {
  387. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  388. }
  389. }
  390. }
  391. /// <summary>
  392. /// 摄像头关闭事件
  393. /// </summary>
  394. /// <param name="sender"></param>
  395. /// <param name="e"></param>
  396. private void RbnTurnOff_Click(object sender, RoutedEventArgs e)
  397. {
  398. if (IsRbnOpen)
  399. {
  400. #region 防止连击
  401. if (IsPressButton)
  402. {
  403. return;
  404. }
  405. else
  406. {
  407. IsPressButton = true;
  408. new Thread(new ThreadStart(new Action(() =>
  409. {
  410. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = false; }));
  411. Thread.Sleep(500);
  412. //Dispatcher.Invoke(new Action(() => { rbnOpen.IsEnabled = true; }));
  413. IsPressButton = false;
  414. }))).Start();
  415. }
  416. #endregion
  417. IsRbnOpen = false;
  418. imgPlayerRight.Visibility = Visibility.Collapsed;
  419. imgPlayerLeft.Visibility = Visibility.Collapsed;
  420. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  421. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  422. CameraHelper.CloseDevice();
  423. I = 9999;
  424. }
  425. }
  426. #endregion
  427. #endregion
  428. /// <summary>
  429. /// 关闭事件
  430. /// </summary>
  431. /// <param name="sender"></param>
  432. /// <param name="e"></param>
  433. private void BtnDown_Click(object sender, RoutedEventArgs e)
  434. {
  435. if (IsFirstR)
  436. {
  437. MessageBoxResult br = MessageWindow.Show("确定退出系统?", "退出", MessageBoxButton.OKCancel);
  438. if (br == MessageBoxResult.OK)
  439. {
  440. APP.Killffmpeg();
  441. APP.SaveWkData();
  442. APP.SaveDraw();
  443. Thread.Sleep(100);
  444. System.Environment.Exit(0);
  445. }
  446. }
  447. else
  448. {
  449. MessageWindow.Show("当前正在录制,请先停止录制。");
  450. return;
  451. //MessageBoxResult dr = MessageWindow.Show("当前正在录制,是否停止录制?", "提示", MessageBoxButton.OKCancel);
  452. //if (dr == MessageBoxResult.OK)
  453. //{
  454. // APP.SaveWkData();
  455. // APP.SaveDraw();
  456. // BtnStop_Click(null, null);
  457. // while (!IsFirstR)
  458. // {
  459. // Thread.Sleep(100);
  460. // }
  461. // System.Environment.Exit(0);
  462. //}
  463. //else
  464. //{
  465. // return;
  466. //}
  467. }
  468. }
  469. #region 设置
  470. /// <summary>
  471. /// 设置事件
  472. /// </summary>
  473. /// <param name="sender"></param>
  474. /// <param name="e"></param>
  475. private void BtnSetUp_Click(object sender, RoutedEventArgs e)
  476. {
  477. if (!TxbRecordingWord.Text.Equals("暂停"))
  478. {
  479. if (gridSetUp.Visibility == Visibility.Collapsed)
  480. {
  481. GridMain.Visibility = Visibility.Collapsed;
  482. gridSetUp.Visibility = Visibility.Visible;
  483. //gridUpload.Visibility = Visibility.Collapsed;
  484. GridMyVideo.Visibility = Visibility.Collapsed;
  485. txbStoragePath.Content = APP.WKData.WkPath;
  486. GridMyVideo.Visibility = Visibility.Collapsed;
  487. #region 读取用户配置
  488. //接口地址
  489. if (!File.Exists(APP.dataPath + "interfaceAddress.txt")) //若为空
  490. {
  491. txbInterfaceAddress.Text = APP.apiUrl.Replace("http://", "").Trim();
  492. }
  493. else
  494. {
  495. txbInterfaceAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "interfaceAddress.txt", Encoding.Default).Replace("http://", "").Trim();
  496. }
  497. //上传地址
  498. if (!File.Exists(APP.dataPath + "imageUploadAddress.txt")) //若为空
  499. {
  500. txbImageUploadAddress.Text = APP.uploadUrl.Replace("http://", "").Replace("/", "").Trim();
  501. }
  502. else
  503. {
  504. txbImageUploadAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "imageUploadAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Trim();
  505. }
  506. //下载地址
  507. if (!File.Exists(APP.dataPath + "pictureShowsAddress.txt")) //若为空
  508. {
  509. txbPictureShowsAddress.Text = APP.showImageUrl.Replace("http://", "").Replace("/", "").Replace("static", "").Trim();
  510. }
  511. else
  512. {
  513. txbPictureShowsAddress.Text = System.IO.File.ReadAllText(APP.dataPath + "pictureShowsAddress.txt", Encoding.Default).Replace("http://", "").Replace("/", "").Replace("static", "").Trim();
  514. }
  515. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  516. if ("1".Equals(APP.CameraPosition))
  517. {
  518. rbnRight.IsChecked = true;
  519. }
  520. else if ("2".Equals(APP.CameraPosition))
  521. {
  522. rbnLeft.IsChecked = true;
  523. }
  524. else if ("3".Equals(APP.CameraPosition))
  525. {
  526. rbnRightUnder.IsChecked = true;
  527. }
  528. else if ("4".Equals(APP.CameraPosition))
  529. {
  530. rbnLeftUnder.IsChecked = true;
  531. }
  532. string type = FileToolsCommon.GetConfigValue("VideoType");//<!--视频格式 1、MP4 2、FlV 3、AVI-->
  533. if ("1".Equals(type))
  534. {
  535. rbnMP4.IsChecked = true;
  536. }
  537. else if ("2".Equals(type))
  538. {
  539. rbnFLV.IsChecked = true;
  540. }
  541. else if ("3".Equals(type))
  542. {
  543. rbnAVI.IsChecked = true;
  544. }
  545. string isSound = FileToolsCommon.GetConfigValue("IsSound");//<!--声音 true 有 false 无-->
  546. if (isSound == "true")
  547. {
  548. rbnY.IsChecked = true;
  549. }
  550. else
  551. {
  552. rbnN.IsChecked = true;
  553. }
  554. #endregion
  555. }
  556. else
  557. {
  558. GridMain.Visibility = Visibility.Visible;
  559. gridSetUp.Visibility = Visibility.Collapsed;
  560. //gridUpload.Visibility = Visibility.Collapsed;
  561. GridMyVideo.Visibility = Visibility.Collapsed;
  562. if (APP.pageData.pagenum > 0)
  563. {
  564. gridPage.Visibility = Visibility.Visible;
  565. }
  566. DataContext = APP.pageData;
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// 设置 保存事件
  572. /// </summary>
  573. /// <param name="sender"></param>
  574. /// <param name="e"></param>
  575. private void BtnSave_Click(object sender, RoutedEventArgs e)
  576. {
  577. try
  578. {
  579. ImgRecord.Visibility = Visibility.Visible;//设置结束时可录制
  580. ImgRecordTwo.Visibility = Visibility.Collapsed;//设置结束时可录制
  581. BtnRecord.IsEnabled = true;//设置结束时可录制
  582. if (!string.IsNullOrWhiteSpace(txbInterfaceAddress.Text))
  583. {
  584. string ApplicationData = APP.dataPath + "interfaceAddress.txt";
  585. string temp = "http://" + txbInterfaceAddress.Text;
  586. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  587. }
  588. else
  589. {
  590. MessageWindow.Show("请输入接口地址");
  591. return;
  592. }
  593. if (!string.IsNullOrWhiteSpace(txbImageUploadAddress.Text))//图片上传地址
  594. {
  595. string ApplicationData = APP.dataPath + "imageUploadAddress.txt";
  596. string temp = "http://" + txbImageUploadAddress.Text + "/";
  597. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  598. }
  599. else
  600. {
  601. MessageWindow.Show("请输入上传地址");
  602. return;
  603. }
  604. if (!string.IsNullOrWhiteSpace(txbPictureShowsAddress.Text))
  605. {
  606. string ApplicationData = APP.dataPath + "pictureShowsAddress.txt";
  607. string temp = "http://" + txbPictureShowsAddress.Text + "/static/";
  608. System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  609. }
  610. else
  611. {
  612. MessageWindow.Show("请输入下载地址");
  613. return;
  614. }
  615. if (!APP.apiUrl.Equals("http://" + txbInterfaceAddress.Text))
  616. {
  617. APP.apiUrl = "http://" + txbInterfaceAddress.Text;
  618. if (!txbLoginType.Text.Equals("未登录"))
  619. {
  620. LoginType();
  621. MessageWindow.Show("接口地址已修改,请重新登陆!");
  622. }
  623. }
  624. if (!APP.uploadUrl.Equals(txbImageUploadAddress.Text))
  625. {
  626. APP.uploadUrl = "http://" + txbImageUploadAddress.Text + "/";
  627. }
  628. if (!APP.showImageUrl.Equals(txbPictureShowsAddress.Text))
  629. {
  630. APP.showImageUrl = "http://" + txbPictureShowsAddress.Text + "/static/";
  631. }
  632. if (rbnMP4.IsChecked == true)
  633. {
  634. //存储文件
  635. FileToolsCommon.SetConfigValue("VideoType", "1");
  636. }
  637. else if (rbnFLV.IsChecked == true)
  638. {
  639. FileToolsCommon.SetConfigValue("VideoType", "2");
  640. }
  641. else
  642. {
  643. FileToolsCommon.SetConfigValue("VideoType", "3");
  644. }
  645. if (rbnY.IsChecked == true)
  646. {
  647. FileToolsCommon.SetConfigValue("IsSound", "true");
  648. }
  649. else
  650. {
  651. FileToolsCommon.SetConfigValue("IsSound", "false");
  652. }
  653. /// < !--摄像头位置 1.右上 2.左上 3.右下 4.左下-- >
  654. if (rbnRight.IsChecked == true)
  655. {
  656. FileToolsCommon.SetConfigValue("CameraPosition", "1");
  657. }
  658. else if (rbnLeft.IsChecked == true)
  659. {
  660. FileToolsCommon.SetConfigValue("CameraPosition", "2");
  661. }
  662. else if (rbnRightUnder.IsChecked == true)
  663. {
  664. FileToolsCommon.SetConfigValue("CameraPosition", "3");
  665. }
  666. else if (rbnLeftUnder.IsChecked == true)
  667. {
  668. FileToolsCommon.SetConfigValue("CameraPosition", "4");
  669. }
  670. if (rbnMP4.IsChecked == true)
  671. {
  672. FileToolsCommon.SetConfigValue("VideoType", "1");
  673. }
  674. else if (rbnFLV.IsChecked == true)
  675. {
  676. FileToolsCommon.SetConfigValue("VideoType", "2");
  677. }
  678. else if (rbnAVI.IsChecked == true)
  679. {
  680. FileToolsCommon.SetConfigValue("VideoType", "3");
  681. }
  682. APP.CameraPosition = FileToolsCommon.GetConfigValue("CameraPosition");
  683. GridMain.Visibility = Visibility.Visible;
  684. gridSetUp.Visibility = Visibility.Collapsed;
  685. imgPlayerRight.Visibility = Visibility.Collapsed;
  686. imgPlayerLeft.Visibility = Visibility.Collapsed;
  687. imgPlayerRightUnder.Visibility = Visibility.Collapsed;
  688. imgPlayerLeftUnder.Visibility = Visibility.Collapsed;
  689. if (!txbStoragePath.Content.ToString().Equals(APP.WKData.WkPath))
  690. {
  691. //存储文件
  692. FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Content.ToString());
  693. MessageWindow.Show("路径已变更,下次创建微课时自动生效。");
  694. }
  695. }
  696. catch (Exception ex)
  697. {
  698. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(设置保存事件报错:)" + ex.Message, ex);
  699. }
  700. }
  701. /// <summary>
  702. /// 设置 浏览事件
  703. /// </summary>
  704. /// <param name="sender"></param>
  705. /// <param name="e"></param>
  706. private void BtnBrowse_Click(object sender, RoutedEventArgs e)
  707. {
  708. //System.Diagnostics.Process.Start(APP.WKData.WkPath);
  709. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  710. Ofd = new System.Windows.Forms.FolderBrowserDialog();
  711. Result = Ofd.ShowDialog();
  712. if (Result == System.Windows.Forms.DialogResult.OK)
  713. {
  714. if (Ofd.SelectedPath != "")
  715. {
  716. txbStoragePath.Content = Ofd.SelectedPath;
  717. //string ApplicationData = ZConfig.dataPath + "fileStorageAddress.txt";
  718. //string temp = ofd.SelectedPath;
  719. //System.IO.File.WriteAllText(ApplicationData, temp, Encoding.Default);
  720. }
  721. }
  722. }
  723. #endregion
  724. #region 画笔
  725. /// <summary>
  726. /// 画笔颜色事件 白色
  727. /// </summary>
  728. /// <param name="sender"></param>
  729. /// <param name="e"></param>
  730. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  731. {
  732. ////创建 DrawingAttributes 类的一个实例
  733. //drawingAttributes = new DrawingAttributes();
  734. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  735. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  736. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  737. ////设置 DrawingAttributes 的 Color 属性设置颜色
  738. drawingAttributes.Color = Colors.White;
  739. Color = Colors.White;
  740. }
  741. /// <summary>
  742. /// 画笔颜色事件 红色
  743. /// </summary>
  744. /// <param name="sender"></param>
  745. /// <param name="e"></param>
  746. private void BtnRed_Click(object sender, RoutedEventArgs e)
  747. {
  748. //设置 DrawingAttributes 的 Color 属性设置颜色
  749. drawingAttributes.Color = Colors.Red;
  750. Color = Colors.Red;
  751. imgRed.Visibility = Visibility.Visible;
  752. imgGray.Visibility = Visibility.Collapsed;
  753. imgCyanBlue.Visibility = Visibility.Collapsed;
  754. imgYellow.Visibility = Visibility.Collapsed;
  755. imgBlue.Visibility = Visibility.Collapsed;
  756. }
  757. /// <summary>
  758. /// 画笔颜色事件 黑色
  759. /// </summary>
  760. /// <param name="sender"></param>
  761. /// <param name="e"></param>
  762. private void BtnGray_Click(object sender, RoutedEventArgs e)
  763. {
  764. drawingAttributes.Color = Colors.Black;
  765. Color = Colors.Black;
  766. imgRed.Visibility = Visibility.Collapsed;
  767. imgGray.Visibility = Visibility.Visible;
  768. imgCyanBlue.Visibility = Visibility.Collapsed;
  769. imgYellow.Visibility = Visibility.Collapsed;
  770. imgBlue.Visibility = Visibility.Collapsed;
  771. }
  772. /// <summary>
  773. /// 画笔颜色事件 青色
  774. /// </summary>
  775. /// <param name="sender"></param>
  776. /// <param name="e"></param>
  777. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  778. {
  779. drawingAttributes.Color = Colors.LimeGreen;
  780. Color = Colors.LimeGreen;
  781. imgRed.Visibility = Visibility.Collapsed;
  782. imgGray.Visibility = Visibility.Collapsed;
  783. imgCyanBlue.Visibility = Visibility.Visible;
  784. imgYellow.Visibility = Visibility.Collapsed;
  785. imgBlue.Visibility = Visibility.Collapsed;
  786. }
  787. /// <summary>
  788. /// 画笔颜色事件 黄色
  789. /// </summary>
  790. /// <param name="sender"></param>
  791. /// <param name="e"></param>
  792. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  793. {
  794. drawingAttributes.Color = Colors.Gold;
  795. Color = Colors.Gold;
  796. imgRed.Visibility = Visibility.Collapsed;
  797. imgGray.Visibility = Visibility.Collapsed;
  798. imgCyanBlue.Visibility = Visibility.Collapsed;
  799. imgYellow.Visibility = Visibility.Visible;
  800. imgBlue.Visibility = Visibility.Collapsed;
  801. }
  802. /// <summary>
  803. /// 画笔颜色事件 蓝色
  804. /// </summary>
  805. /// <param name="sender"></param>
  806. /// <param name="e"></param>
  807. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  808. {
  809. drawingAttributes.Color = Colors.DeepSkyBlue;
  810. Color = Colors.DeepSkyBlue;
  811. imgRed.Visibility = Visibility.Collapsed;
  812. imgGray.Visibility = Visibility.Collapsed;
  813. imgCyanBlue.Visibility = Visibility.Collapsed;
  814. imgYellow.Visibility = Visibility.Collapsed;
  815. imgBlue.Visibility = Visibility.Visible;
  816. }
  817. /// <summary>
  818. /// 画笔粗细事件 细
  819. /// </summary>
  820. /// <param name="sender"></param>
  821. /// <param name="e"></param>
  822. private void RbnFine_Click(object sender, RoutedEventArgs e)
  823. {
  824. drawingAttributes.Width = 1;
  825. drawingAttributes.Height = 1;
  826. PenSize = 1;
  827. }
  828. /// <summary>
  829. /// 画笔粗细事件 中
  830. /// </summary>
  831. /// <param name="sender"></param>
  832. /// <param name="e"></param>
  833. private void RbnIn_Click(object sender, RoutedEventArgs e)
  834. {
  835. drawingAttributes.Width = 3;
  836. drawingAttributes.Height = 3;
  837. PenSize = 3;
  838. }
  839. /// <summary>
  840. /// 画笔粗细事件 粗
  841. /// </summary>
  842. /// <param name="sender"></param>
  843. /// <param name="e"></param>
  844. private void RbnCrude_Click(object sender, RoutedEventArgs e)
  845. {
  846. drawingAttributes.Width = 5;
  847. drawingAttributes.Height = 5;
  848. PenSize = 5;
  849. }
  850. #endregion
  851. #region 导入截图
  852. /// <summary>
  853. /// 截图事件
  854. /// </summary>
  855. /// <param name="sender"></param>
  856. /// <param name="e"></param>
  857. private void BtnScreenshot_Click(object sender, RoutedEventArgs e)
  858. {
  859. Record();
  860. HideAngleBorder();
  861. imgCanvas.Margin = new Thickness(0, 0, 0, 0);
  862. APP.ImgPath = string.Empty;
  863. string time = GetTimeStamp();
  864. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + time + ".jpg";
  865. APP.ImgPath = desktopPath;
  866. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), desktopPath, false, out BitmapImage bitmap);
  867. k_hook.Stop();
  868. if (WindowState == WindowState.Normal)//截图隐藏窗口
  869. {
  870. WindowState = WindowState.Minimized;
  871. }
  872. if (APP.W_JieTuWindow != null)
  873. {
  874. APP.W_JieTuWindow.initialization();
  875. APP.W_JieTuWindow.Screenshot();
  876. APP.W_JieTuWindow.InitializeKeyDownEvent();
  877. APP.W_JieTuWindow.WindowState = WindowState.Maximized;
  878. APP.W_JieTuWindow.Visibility = Visibility.Visible;
  879. }
  880. else
  881. {
  882. APP.W_JieTuWindow = new JieTuWindow();
  883. APP.W_JieTuWindow.InitializeKeyDownEvent();
  884. // 订阅事件
  885. APP.W_JieTuWindow.ChangeTextEvent += new ChangeTextHandler(frm_ChangeTextEvent);
  886. APP.W_JieTuWindow.click_closeJietuWindowClick += JietuWindow_click_closeJietuWindowClick;
  887. APP.W_JieTuWindow.Show();
  888. }
  889. //imgCanvas.Source = new BitmapImage(new Uri(desktopPath));
  890. }
  891. public void WindowType()
  892. {
  893. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  894. {
  895. Topmost = true;
  896. WindowState = WindowState.Normal;
  897. }
  898. }
  899. /// <summary>
  900. /// 截图关闭窗口
  901. /// </summary>
  902. /// <param name="text"></param>
  903. private void frm_ChangeTextEvent(string text)
  904. {
  905. if ("关闭窗口".Equals(text))
  906. {
  907. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  908. {
  909. Topmost = true;
  910. WindowState = WindowState.Normal;
  911. }
  912. InitializeKeyDownEvent();
  913. if (!string.IsNullOrWhiteSpace(APP.ImgPath) && File.Exists(APP.ImgPath))
  914. {
  915. if (APP.pageData.currpage == 0)
  916. {
  917. APP.pageData.pagenum += 1;
  918. APP.pageData.currpage = APP.pageData.pagenum;
  919. myblackboard.changepage(APP.pageData.currpage - 1);
  920. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  921. #region 插入页码
  922. PageData = new List<PageData>();
  923. for (int i = 1; i <= APP.pageData.pagenum; i++)
  924. {
  925. PageData pd = new PageData();
  926. pd.PageName = i.ToString();// + "页";
  927. pd.PageCode = i;
  928. PageData.Add(pd);
  929. }
  930. CbxPageList.ItemsSource = PageData;
  931. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  932. #endregion
  933. }
  934. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  935. {
  936. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  937. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  938. }
  939. else
  940. {
  941. Model_DrawData model_DrawData = new Model_DrawData
  942. {
  943. PageImagePath = APP.ImgPath,
  944. PdfImagePath = APP.ImgPath
  945. };
  946. APP.PageDrawList.Add(model_DrawData);
  947. }
  948. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  949. {
  950. imgDocumentation.Source = null;
  951. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  952. mouseDown = false;
  953. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  954. {
  955. X = 0.1,
  956. Y = 0.1
  957. };
  958. APP.PageDrawList[APP.pageData.currpage - 1].Type = "截图";
  959. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  960. imgCanvas.Source = bitImg;
  961. imgCanvas.Width = bitImg.Width;
  962. imgCanvas.Height = bitImg.Height;
  963. scroMain.ScrollToVerticalOffset(0);
  964. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  965. {
  966. CenterX = imgCanvas.Width,
  967. CenterY = imgCanvas.Height
  968. };
  969. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  970. ImgPrintTwo.Visibility = Visibility.Collapsed;
  971. btnPrint.IsEnabled = true;
  972. }
  973. }
  974. Topmost = false;
  975. }
  976. }
  977. /// <summary>
  978. /// 截图关闭 非正常关闭截图时,截图清空
  979. /// </summary>
  980. private void JietuWindow_click_closeJietuWindowClick()
  981. {
  982. if (WindowState == WindowState.Minimized)//截图完恢复窗口
  983. {
  984. WindowState = WindowState.Normal;
  985. }
  986. APP.W_JieTuWindow = null;
  987. }
  988. /// 截图的图片鼠标右键事件
  989. /// </summary>
  990. /// <param name="sender"></param>
  991. /// <param name="e"></param>
  992. private void imgCanvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
  993. {
  994. imgCanvas.Source = null;
  995. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = null;
  996. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = null;
  997. }
  998. /// <summary>
  999. /// 导入事件
  1000. /// </summary>
  1001. /// <param name="sender"></param>
  1002. /// <param name="e"></param>
  1003. private void BtnImport_Click(object sender, RoutedEventArgs e)
  1004. {
  1005. try
  1006. {
  1007. Record();
  1008. HideAngleBorder();
  1009. string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  1010. ofd = new System.Windows.Forms.OpenFileDialog
  1011. {
  1012. //Filter = "文档|*.docx;*.doc;*.ppt;*.pptx",
  1013. //增加导入图片
  1014. Filter = "文档|*.docx;*.doc;*.ppt;*.pptx;*.pdf|图片|*.jpg;*.jpeg;*.png;*.bmp",
  1015. InitialDirectory = desktopPath,
  1016. Multiselect = false,
  1017. AddExtension = true,
  1018. DereferenceLinks = true
  1019. };
  1020. //APP.myloading.Show();
  1021. APP.BackgroundWorkerHelper.RunWorkerAsync(InvokeServering, InvokeServerCompate);
  1022. //new Thread(
  1023. // o =>
  1024. // {
  1025. // Thread.Sleep(400);
  1026. // Dispatcher.Invoke(new Action(() =>
  1027. // {
  1028. // OpenDialog();
  1029. // }
  1030. // ));
  1031. // })
  1032. //{
  1033. // IsBackground = true
  1034. //}.Start();
  1035. }
  1036. catch (Exception ex)
  1037. {
  1038. LogHelper.WriteErrLog("【导入(BtnImport_Click)" + ex.Message, ex);
  1039. }
  1040. }
  1041. /// <summary>
  1042. /// 导入-开始
  1043. /// </summary>
  1044. /// <returns></returns>
  1045. private object InvokeServering()
  1046. {
  1047. Dispatcher.Invoke(new Action(() =>
  1048. {
  1049. result = ofd.ShowDialog();
  1050. }));
  1051. if (result == System.Windows.Forms.DialogResult.OK)
  1052. {
  1053. if (ofd.FileName != "")
  1054. {
  1055. List<string> imagelist = new List<string>() { "jpg", "jpeg", "png", "bmp" };
  1056. Dispatcher.Invoke(new Action(() =>
  1057. {
  1058. APP.myloading.Show();
  1059. myblackboard.changepage(APP.pageData.pagenum);
  1060. }));
  1061. string filepath = ofd.FileName;
  1062. string filesuff = filepath.Substring(filepath.LastIndexOf(".") + 1).ToLower();
  1063. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1064. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1065. if (type.Contains("typezsygppt"))//ppt
  1066. {
  1067. try
  1068. {
  1069. #region PPT转PDF
  1070. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1071. path = pathTemp + path + ".pdf";
  1072. FileToolsCommon.CreateDirectory(pathTemp);
  1073. //PPT转PDF
  1074. Presentation ppt = new Presentation(filepath);
  1075. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1076. #endregion
  1077. #region PDF转图片
  1078. // 图片绝对路径集合
  1079. List<string> images = new List<string>();
  1080. string directoryPath = pathTemp;
  1081. //aspose许可证
  1082. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1083. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1084. //l.SetLicense(licenseName);
  1085. //定义Jpeg转换设备
  1086. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1087. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1088. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1089. //directoryPath += quality;
  1090. Directory.CreateDirectory(directoryPath);
  1091. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1092. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1093. //遍历每一页转为jpg
  1094. for (int i = 1; i <= document.Pages.Count; i++)
  1095. {
  1096. long ii = Timestamp();
  1097. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1098. images.Add(filePathOutPut);
  1099. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1100. try
  1101. {
  1102. device.Process(document.Pages[i], fs);
  1103. fs.Close();
  1104. }
  1105. catch (Exception)
  1106. {
  1107. fs.Close();
  1108. File.Delete(filePathOutPut);
  1109. }
  1110. }
  1111. #endregion
  1112. Dispatcher.Invoke(new Action(() =>
  1113. {
  1114. string[] page = images.ToArray();
  1115. int num = 0;
  1116. int iStart = APP.pageData.pagenum;//导入文档的开始下标
  1117. int iEnd = page.Length + APP.pageData.pagenum;//导入文档的结束下标
  1118. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1119. {
  1120. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1121. {
  1122. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1123. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1124. APP.PageDrawList[i].PageNum = i + 1;
  1125. APP.PageDrawList[i].ImgDocumentation = true;
  1126. APP.PageDrawList[i].Type = "ppt";
  1127. }
  1128. else
  1129. {
  1130. Model_DrawData model_DrawData = new Model_DrawData
  1131. {
  1132. PageImagePath = page[i - APP.pageData.pagenum],
  1133. PdfImagePath = page[i - APP.pageData.pagenum],
  1134. PageNum = i + 1,
  1135. ImgDocumentation = true,
  1136. Type = "ppt"
  1137. };
  1138. APP.PageDrawList.Add(model_DrawData);
  1139. }
  1140. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1141. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1142. btnPrint.IsEnabled = true;
  1143. APP.SaveDraw();
  1144. num++;
  1145. }
  1146. if (num > 0)
  1147. {
  1148. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1149. APP.pageData.pagenum += num;
  1150. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1151. }
  1152. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1153. {
  1154. imgCanvas.Source = null;
  1155. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1156. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1157. btnScreenshot.IsEnabled = false;
  1158. imgDocumentation.Source = null;
  1159. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1160. scroMain.ScrollToVerticalOffset(0);
  1161. for (int i = iStart; i < iEnd; i++)
  1162. {
  1163. APP.PageDrawList[i].ImageLocation = new TranslateTransform
  1164. {
  1165. X = 0.1,
  1166. Y = 0.1
  1167. };
  1168. APP.PageDrawList[i].IsImageLocation = true;
  1169. APP.PageDrawList[i].ImageSizes = new ScaleTransform
  1170. {
  1171. CenterX = imgCanvas.Width,
  1172. CenterY = imgCanvas.Height
  1173. };
  1174. }
  1175. }
  1176. else
  1177. {
  1178. imgDocumentation.Source = null;
  1179. imgCanvas.Source = null;
  1180. imgPPT.Source = null;
  1181. ///截图可用
  1182. ImgScreenshot.Visibility = Visibility.Visible;
  1183. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1184. btnScreenshot.IsEnabled = true;
  1185. }
  1186. }));
  1187. }
  1188. catch (Exception ex)
  1189. {
  1190. Dispatcher.Invoke(new Action(() =>
  1191. {
  1192. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1193. }));
  1194. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1195. }
  1196. }
  1197. else if (type.Contains("typepdf"))
  1198. {
  1199. try
  1200. {
  1201. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1202. #region PDF转图片
  1203. // 图片绝对路径集合
  1204. List<string> images = new List<string>();
  1205. string directoryPath = pathTemp;
  1206. //aspose许可证
  1207. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1208. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1209. //l.SetLicense(licenseName);
  1210. //定义Jpeg转换设备
  1211. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1212. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1213. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1214. //directoryPath += quality;
  1215. Directory.CreateDirectory(directoryPath);
  1216. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1217. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1218. //遍历每一页转为jpg
  1219. for (int i = 1; i <= document.Pages.Count; i++)
  1220. {
  1221. long ii = Timestamp();
  1222. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1223. images.Add(filePathOutPut);
  1224. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1225. try
  1226. {
  1227. device.Process(document.Pages[i], fs);
  1228. fs.Close();
  1229. }
  1230. catch (Exception)
  1231. {
  1232. fs.Close();
  1233. File.Delete(filePathOutPut);
  1234. }
  1235. }
  1236. #endregion
  1237. string[] page = images.ToArray();
  1238. int num = 0;
  1239. int iStart = APP.pageData.pagenum;//导入文档的开始下标
  1240. int iEnd = page.Length + APP.pageData.pagenum;//导入文档的结束下标
  1241. Dispatcher.Invoke(new Action(() =>
  1242. {
  1243. for (int i = APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1244. {
  1245. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1246. {
  1247. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1248. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1249. APP.PageDrawList[i].PageNum = i + 1;
  1250. APP.PageDrawList[i].ImgDocumentation = true;
  1251. APP.PageDrawList[i].Type = "word";
  1252. }
  1253. else
  1254. {
  1255. Model_DrawData model_DrawData = new Model_DrawData
  1256. {
  1257. PageImagePath = page[i - APP.pageData.pagenum],
  1258. PdfImagePath = page[i - APP.pageData.pagenum],
  1259. PageNum = i + 1,
  1260. ImgDocumentation = true,
  1261. Type = "word"
  1262. };
  1263. APP.PageDrawList.Add(model_DrawData);
  1264. }
  1265. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1266. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1267. btnPrint.IsEnabled = true;
  1268. APP.SaveDraw();
  1269. num++;
  1270. }
  1271. if (num > 0)
  1272. {
  1273. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1274. APP.pageData.pagenum += num;
  1275. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1276. }
  1277. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1278. {
  1279. imgCanvas.Source = null;
  1280. imgPPT.Source = null;
  1281. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1282. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1283. btnScreenshot.IsEnabled = false;
  1284. imgDocumentation.Visibility = Visibility.Visible;
  1285. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1286. scroMain.ScrollToVerticalOffset(0);
  1287. }
  1288. else
  1289. {
  1290. imgDocumentation.Source = null;
  1291. imgCanvas.Source = null;
  1292. imgPPT.Source = null;
  1293. ///截图可用
  1294. ImgScreenshot.Visibility = Visibility.Visible;
  1295. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1296. btnScreenshot.IsEnabled = true;
  1297. }
  1298. }));
  1299. }
  1300. catch (Exception ex)
  1301. {
  1302. Dispatcher.Invoke(new Action(() =>
  1303. {
  1304. MessageWindow.Show(ex.Message);
  1305. }));
  1306. LogHelper.WriteErrLog("【打开pdf】(OpenDialog pdf)" + ex.Message, ex);
  1307. }
  1308. }
  1309. else if(imagelist.Contains(filesuff))///导入图片
  1310. {
  1311. string imagepath = AppDomain.CurrentDomain.BaseDirectory + "temp";
  1312. if (!Directory.Exists(imagepath))
  1313. {
  1314. Directory.CreateDirectory(imagepath);
  1315. }
  1316. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  1317. string timestr = Convert.ToInt64(ts.TotalMilliseconds).ToString();
  1318. string filepathCopy = Path.Combine(imagepath, timestr + ofd.SafeFileName);
  1319. System.IO.File.Copy(filepath, filepathCopy);
  1320. filepath = filepathCopy;
  1321. APP.ImgPath = filepath;
  1322. Dispatcher.Invoke(new Action(() =>
  1323. {
  1324. if (APP.pageData.currpage == 0)
  1325. {
  1326. APP.pageData.pagenum += 1;
  1327. APP.pageData.currpage = APP.pageData.pagenum;
  1328. myblackboard.changepage(APP.pageData.currpage - 1);
  1329. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1330. #region 插入页码
  1331. PageData = new List<PageData>();
  1332. for (int i = 1; i <= APP.pageData.pagenum; i++)
  1333. {
  1334. PageData pd = new PageData();
  1335. pd.PageName = i.ToString();// + "页";
  1336. pd.PageCode = i;
  1337. PageData.Add(pd);
  1338. }
  1339. CbxPageList.ItemsSource = PageData;
  1340. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  1341. #endregion
  1342. }
  1343. else
  1344. {
  1345. APP.pageData.pagenum += 1;
  1346. APP.pageData.currpage = APP.pageData.pagenum;
  1347. myblackboard.changepage(APP.pageData.currpage - 1);
  1348. }
  1349. if (APP.PageDrawList.Count >= APP.pageData.currpage)
  1350. {
  1351. APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath = APP.ImgPath;//zxycs
  1352. APP.PageDrawList[APP.pageData.currpage - 1].PdfImagePath = APP.ImgPath;
  1353. }
  1354. else
  1355. {
  1356. Model_DrawData model_DrawData = new Model_DrawData
  1357. {
  1358. PageImagePath = APP.ImgPath,
  1359. PdfImagePath = APP.ImgPath
  1360. };
  1361. APP.PageDrawList.Add(model_DrawData);
  1362. }
  1363. if (APP.PageDrawList.Count >= APP.pageData.currpage && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  1364. {
  1365. imgDocumentation.Source = null;
  1366. BitmapImage bitImg = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  1367. mouseDown = false;
  1368. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  1369. {
  1370. X = 0.1,
  1371. Y = 0.1
  1372. };
  1373. APP.PageDrawList[APP.pageData.currpage - 1].Type = "截图";
  1374. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  1375. imgCanvas.Source = bitImg;
  1376. imgCanvas.Width = bitImg.Width;
  1377. imgCanvas.Height = bitImg.Height;
  1378. scroMain.ScrollToVerticalOffset(0);
  1379. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  1380. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  1381. {
  1382. CenterX = imgCanvas.Width,
  1383. CenterY = imgCanvas.Height
  1384. };
  1385. ImgPrint.Visibility = Visibility.Visible;//截图成功可打印
  1386. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1387. btnPrint.IsEnabled = true;
  1388. }
  1389. }));
  1390. }
  1391. else//word
  1392. {
  1393. try
  1394. {
  1395. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1396. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1397. int num = 0;
  1398. Dispatcher.Invoke(new Action(() =>
  1399. {
  1400. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1401. {
  1402. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1403. {
  1404. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1405. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1406. APP.PageDrawList[i].PageNum = i + 1;
  1407. APP.PageDrawList[i].ImgDocumentation = true;
  1408. APP.PageDrawList[i].Type = "word";
  1409. }
  1410. else
  1411. {
  1412. Model_DrawData model_DrawData = new Model_DrawData
  1413. {
  1414. PageImagePath = page[i - APP.pageData.pagenum],
  1415. PdfImagePath = page[i - APP.pageData.pagenum],
  1416. PageNum = i + 1,
  1417. ImgDocumentation = true,
  1418. Type = "word"
  1419. };
  1420. APP.PageDrawList.Add(model_DrawData);
  1421. }
  1422. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1423. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1424. btnPrint.IsEnabled = true;
  1425. APP.SaveDraw();
  1426. num++;
  1427. }
  1428. if (num > 0)
  1429. {
  1430. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1431. APP.pageData.pagenum += num;
  1432. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1433. }
  1434. if (APP.pageData.currpage > 0 && APP.pageData.currpage <= APP.PageDrawList.Count)
  1435. {
  1436. imgCanvas.Source = null;
  1437. imgPPT.Source = null;
  1438. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1439. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1440. btnScreenshot.IsEnabled = false;
  1441. imgDocumentation.Visibility = Visibility.Visible;
  1442. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1443. scroMain.ScrollToVerticalOffset(0);
  1444. }
  1445. else
  1446. {
  1447. imgDocumentation.Source = null;
  1448. imgCanvas.Source = null;
  1449. imgPPT.Source = null;
  1450. ///截图可用
  1451. ImgScreenshot.Visibility = Visibility.Visible;
  1452. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1453. btnScreenshot.IsEnabled = true;
  1454. }
  1455. }));
  1456. }
  1457. catch (Exception ex)
  1458. {
  1459. Dispatcher.Invoke(new Action(() =>
  1460. {
  1461. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1462. }));
  1463. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1464. }
  1465. }
  1466. #region 插入页码
  1467. Dispatcher.Invoke(new Action(() =>
  1468. {
  1469. PageData = new List<PageData>();
  1470. for (int i = 1; i <= APP.pageData.pagenum; i++)
  1471. {
  1472. PageData pd = new PageData();
  1473. pd.PageName = i.ToString();//+ "页";
  1474. pd.PageCode = i;
  1475. PageData.Add(pd);
  1476. }
  1477. CbxPageList.ItemsSource = PageData;
  1478. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  1479. }));
  1480. #endregion
  1481. }
  1482. }
  1483. //OpenDialog();
  1484. return "";
  1485. }
  1486. /// <summary>
  1487. /// 导入-结束
  1488. /// </summary>
  1489. /// <returns></returns>
  1490. public void InvokeServerCompate(object obj)
  1491. {
  1492. //APP.myloading.Hide();
  1493. APP.myloading.Hide();
  1494. }
  1495. /// <summary>
  1496. /// 导入文档
  1497. /// </summary>
  1498. private void OpenDialog()
  1499. {
  1500. Dispatcher.Invoke(new Action(() =>
  1501. {
  1502. result = ofd.ShowDialog();
  1503. if (result == System.Windows.Forms.DialogResult.OK)
  1504. {
  1505. if (ofd.FileName != "")
  1506. {
  1507. APP.myloading.Show();
  1508. myblackboard.changepage(APP.pageData.pagenum);
  1509. #region PPT转PDF
  1510. string filepath = ofd.FileName;
  1511. string path = ofd.SafeFileName.Replace(".ppt", "").Replace(".pptx", "").Trim();
  1512. string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Replace(".pptx", "typezsygppt").Replace(".pdf", "typepdf").Trim();
  1513. if (type.Contains("typezsygppt"))//ppt
  1514. {
  1515. try
  1516. {
  1517. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1518. path = pathTemp + path + ".pdf";
  1519. FileToolsCommon.CreateDirectory(pathTemp);
  1520. //PPT转PDF
  1521. Presentation ppt = new Presentation(filepath);
  1522. ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
  1523. #endregion
  1524. #region PDF转图片
  1525. // 图片绝对路径集合
  1526. List<string> images = new List<string>();
  1527. string directoryPath = pathTemp;
  1528. //aspose许可证
  1529. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1530. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1531. //l.SetLicense(licenseName);
  1532. //定义Jpeg转换设备
  1533. Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
  1534. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1535. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1536. //directoryPath += quality;
  1537. Directory.CreateDirectory(directoryPath);
  1538. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1539. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1540. //遍历每一页转为jpg
  1541. for (int i = 1; i <= document.Pages.Count; i++)
  1542. {
  1543. long ii = Timestamp();
  1544. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1545. images.Add(filePathOutPut);
  1546. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1547. try
  1548. {
  1549. device.Process(document.Pages[i], fs);
  1550. fs.Close();
  1551. }
  1552. catch (Exception)
  1553. {
  1554. fs.Close();
  1555. File.Delete(filePathOutPut);
  1556. }
  1557. }
  1558. #endregion
  1559. string[] page = images.ToArray();
  1560. int num = 0;
  1561. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1562. {
  1563. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1564. {
  1565. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1566. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1567. APP.PageDrawList[i].PageNum = i + 1;
  1568. APP.PageDrawList[i].ImgDocumentation = true;
  1569. }
  1570. else
  1571. {
  1572. Model_DrawData model_DrawData = new Model_DrawData
  1573. {
  1574. PageImagePath = page[i - APP.pageData.pagenum],
  1575. PdfImagePath = page[i - APP.pageData.pagenum],
  1576. PageNum = i + 1,
  1577. ImgDocumentation = true
  1578. };
  1579. APP.PageDrawList.Add(model_DrawData);
  1580. }
  1581. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1582. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1583. btnPrint.IsEnabled = true;
  1584. APP.SaveDraw();
  1585. num++;
  1586. }
  1587. if (num > 0)
  1588. {
  1589. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1590. APP.pageData.pagenum += num;
  1591. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1592. }
  1593. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1594. {
  1595. imgCanvas.Source = null;
  1596. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1597. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1598. btnScreenshot.IsEnabled = false;
  1599. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1600. }
  1601. else
  1602. {
  1603. imgDocumentation.Source = null;
  1604. imgCanvas.Source = null;
  1605. ///截图可用
  1606. ImgScreenshot.Visibility = Visibility.Visible;
  1607. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1608. btnScreenshot.IsEnabled = true;
  1609. }
  1610. APP.myloading.Hide();
  1611. }
  1612. catch (Exception ex)
  1613. {
  1614. APP.myloading.Hide();
  1615. MessageWindow.Show("无法访问文件,请检查文件是否有效或解除文件占用!");
  1616. LogHelper.WriteErrLog("【打开ppt】(OpenDialog PPT)" + ex.Message, ex);
  1617. }
  1618. }
  1619. else if (type.Contains("typepdf"))
  1620. {
  1621. string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1622. #region PDF转图片
  1623. // 图片绝对路径集合
  1624. List<string> images = new List<string>();
  1625. string directoryPath = pathTemp;
  1626. //aspose许可证
  1627. //Aspose.Pdf.License l = new Aspose.Pdf.License();
  1628. //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
  1629. //l.SetLicense(licenseName);
  1630. //定义Jpeg转换设备
  1631. Aspose.Pdf.Document document = new Aspose.Pdf.Document(filepath);
  1632. Aspose.Pdf.Devices.JpegDevice device = new Aspose.Pdf.Devices.JpegDevice();
  1633. //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
  1634. //directoryPath += quality;
  1635. Directory.CreateDirectory(directoryPath);
  1636. //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
  1637. device = new Aspose.Pdf.Devices.JpegDevice(100);
  1638. //遍历每一页转为jpg
  1639. for (int i = 1; i <= document.Pages.Count; i++)
  1640. {
  1641. long ii = Timestamp();
  1642. string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
  1643. images.Add(filePathOutPut);
  1644. FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
  1645. try
  1646. {
  1647. device.Process(document.Pages[i], fs);
  1648. fs.Close();
  1649. }
  1650. catch (Exception)
  1651. {
  1652. fs.Close();
  1653. File.Delete(filePathOutPut);
  1654. }
  1655. }
  1656. #endregion
  1657. string[] page = images.ToArray();
  1658. int num = 0;
  1659. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1660. {
  1661. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1662. {
  1663. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1664. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1665. APP.PageDrawList[i].PageNum = i + 1;
  1666. APP.PageDrawList[i].ImgDocumentation = true;
  1667. }
  1668. else
  1669. {
  1670. Model_DrawData model_DrawData = new Model_DrawData
  1671. {
  1672. PageImagePath = page[i - APP.pageData.pagenum],
  1673. PdfImagePath = page[i - APP.pageData.pagenum],
  1674. PageNum = i + 1,
  1675. ImgDocumentation = true
  1676. };
  1677. APP.PageDrawList.Add(model_DrawData);
  1678. }
  1679. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1680. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1681. btnPrint.IsEnabled = true;
  1682. APP.SaveDraw();
  1683. num++;
  1684. }
  1685. if (num > 0)
  1686. {
  1687. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1688. APP.pageData.pagenum += num;
  1689. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1690. }
  1691. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1692. {
  1693. imgCanvas.Source = null;
  1694. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1695. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1696. btnScreenshot.IsEnabled = false;
  1697. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1698. }
  1699. else
  1700. {
  1701. imgDocumentation.Source = null;
  1702. imgCanvas.Source = null;
  1703. ///截图可用
  1704. ImgScreenshot.Visibility = Visibility.Visible;
  1705. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1706. btnScreenshot.IsEnabled = true;
  1707. }
  1708. APP.myloading.Hide();
  1709. }
  1710. else//word
  1711. {
  1712. try
  1713. {
  1714. string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  1715. string[] page = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
  1716. int num = 0;
  1717. for (int i = 0 + APP.pageData.pagenum; i < page.Length + APP.pageData.pagenum; i++)//给画板模型加图片路径
  1718. {
  1719. if (APP.PageDrawList != null && APP.PageDrawList.Count > i)
  1720. {
  1721. APP.PageDrawList[i].PageImagePath = page[i - APP.pageData.pagenum]; //zxycs
  1722. APP.PageDrawList[i].PdfImagePath = page[i - APP.pageData.pagenum];
  1723. APP.PageDrawList[i].PageNum = i + 1;
  1724. APP.PageDrawList[i].ImgDocumentation = true;
  1725. }
  1726. else
  1727. {
  1728. Model_DrawData model_DrawData = new Model_DrawData
  1729. {
  1730. PageImagePath = page[i - APP.pageData.pagenum],
  1731. PdfImagePath = page[i - APP.pageData.pagenum],
  1732. PageNum = i + 1,
  1733. ImgDocumentation = true
  1734. };
  1735. APP.PageDrawList.Add(model_DrawData);
  1736. }
  1737. ImgPrint.Visibility = Visibility.Visible;//导入成功可打印
  1738. ImgPrintTwo.Visibility = Visibility.Collapsed;
  1739. btnPrint.IsEnabled = true;
  1740. APP.SaveDraw();
  1741. num++;
  1742. }
  1743. if (num > 0)
  1744. {
  1745. APP.pageData.currpage = APP.pageData.pagenum + 1;
  1746. APP.pageData.pagenum += num;
  1747. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  1748. }
  1749. if (APP.pageData.currpage > 0 && APP.pageData.currpage < APP.PageDrawList.Count)
  1750. {
  1751. imgCanvas.Source = null;
  1752. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  1753. ImgScreenshotTwo.Visibility = Visibility.Visible;
  1754. btnScreenshot.IsEnabled = false;
  1755. imgDocumentation.Visibility = Visibility.Visible;
  1756. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));//给当前页面展示图片
  1757. }
  1758. else
  1759. {
  1760. imgDocumentation.Source = null;
  1761. imgCanvas.Source = null;
  1762. ///截图可用
  1763. ImgScreenshot.Visibility = Visibility.Visible;
  1764. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  1765. btnScreenshot.IsEnabled = true;
  1766. }
  1767. APP.myloading.Hide();
  1768. }
  1769. catch (Exception ex)
  1770. {
  1771. APP.myloading.Hide();
  1772. LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog 导入文档)" + ex.Message, ex);
  1773. }
  1774. }
  1775. }
  1776. }
  1777. }
  1778. ));
  1779. }
  1780. #endregion
  1781. #region 上传 列表
  1782. /// <summary>
  1783. /// 上传事件
  1784. /// </summary>
  1785. /// <param name="sender"></param>
  1786. /// <param name="e"></param>
  1787. private void BtnUpload_Click(object sender, RoutedEventArgs e)
  1788. {
  1789. //if (gridUpload.Visibility == Visibility.Visible)
  1790. //{
  1791. // gridUpload.Visibility = Visibility.Collapsed;
  1792. // GridMain.Visibility = Visibility.Visible;
  1793. // //ImgRecord.Visibility = Visibility.Visible;//上传结束时可录制
  1794. // //ImgRecordTwo.Visibility = Visibility.Collapsed;//上传结束时可录制
  1795. // //BtnRecord.IsEnabled = true;//设置结束时可录制
  1796. // if (APP.pageData.pagenum > 0)
  1797. // {
  1798. // gridPage.Visibility = Visibility.Visible;
  1799. // }
  1800. // DataContext = APP.pageData;
  1801. //}
  1802. //else
  1803. //{
  1804. // gridPage.Visibility = Visibility.Collapsed;
  1805. // gridUpload.Visibility = Visibility.Visible;
  1806. // GridMain.Visibility = Visibility.Collapsed;
  1807. // //ImgRecord.Visibility = Visibility.Collapsed;//上传时不可录制
  1808. // //ImgRecordTwo.Visibility = Visibility.Visible;//上传时不可录制
  1809. // //BtnRecord.IsEnabled = false;//上传时不可录制
  1810. // InitializeUpload();
  1811. //}
  1812. if (GridMyVideo.Visibility == Visibility.Visible)
  1813. {
  1814. GridMyVideo.Visibility = Visibility.Collapsed;
  1815. GridMain.Visibility = Visibility.Visible;
  1816. if (APP.pageData.pagenum > 0)
  1817. {
  1818. gridPage.Visibility = Visibility.Visible;
  1819. }
  1820. DataContext = APP.pageData;
  1821. }
  1822. else
  1823. {
  1824. gridSetUp.Visibility = Visibility.Collapsed;
  1825. gridPage.Visibility = Visibility.Collapsed;
  1826. GridMyVideo.Visibility = Visibility.Visible;
  1827. GridMain.Visibility = Visibility.Collapsed;
  1828. LoadUploadInitData();
  1829. }
  1830. //btnStop.IsEnabled = true;//停止录制按钮可点击
  1831. }
  1832. /// <summary>
  1833. /// 初始化上传
  1834. /// </summary>
  1835. public void InitializeUpload()
  1836. {
  1837. APP.myloading.Show();
  1838. MouseNumber = 0;
  1839. IsModify = false;
  1840. //加载视频列表
  1841. LoadingVideoList();
  1842. int i = 1;
  1843. bool isColour = true;
  1844. pageData.menuList.Clear();
  1845. //显示视频
  1846. foreach (Model_Video videoinfo in model_VideoList)
  1847. {
  1848. //是否已上传
  1849. //videoinfo.IsUpload;
  1850. //录制时间
  1851. //videoinfo.RSTime;
  1852. //文件大小
  1853. //videoinfo.VideoSize;
  1854. //文件缩略图路径
  1855. //videoinfo.ThumbnailPath;
  1856. //文件唯一标示 上传事件筛选需要上传的视频
  1857. //videoinfo.FileGuid;
  1858. //文件存储路径
  1859. //videoinfo.VidePath;
  1860. string colour = "#FFFFFF";
  1861. if (isColour == true)
  1862. {
  1863. colour = "#FFFFFF";
  1864. isColour = false;
  1865. }
  1866. else
  1867. {
  1868. colour = "#E6F1FF";
  1869. isColour = true;
  1870. }
  1871. string vis = "Visible";
  1872. string cos = "Collapsed";
  1873. if (!videoinfo.IsUpload)
  1874. {
  1875. vis = "Collapsed";
  1876. cos = "Visible";
  1877. }
  1878. //if(i==1)//ceshi
  1879. //{
  1880. // vis = "Visible";
  1881. // cos = "Collapsed";
  1882. //}
  1883. if (i <= 16)
  1884. {
  1885. pageData.menuList.Add(new FileDirectoryModel()
  1886. {
  1887. SerialNumber = i,
  1888. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1889. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  1890. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  1891. VideoDuration = 0,
  1892. VideoSize = videoinfo.VideoSize,
  1893. VideoTime = videoinfo.RSTime,
  1894. IsEnabled = false,
  1895. Path = videoinfo.VideoPath,
  1896. Colour = colour,
  1897. Visi = vis,
  1898. Coll = cos,
  1899. FileGuid = videoinfo.FileGuid,
  1900. VideoType = videoinfo.VideoType.ToString(),
  1901. VideoSizes = videoinfo.VideoSizebyte
  1902. }); ;
  1903. }
  1904. i++;
  1905. }
  1906. Currpage = 0;
  1907. PageNum = 0;
  1908. if (pageData.menuList.Count > 0)
  1909. {
  1910. Currpage = 1;
  1911. txbCurrpageTwo.Text = Currpage.ToString();
  1912. stpUp.Visibility = Visibility.Visible;
  1913. }
  1914. else
  1915. {
  1916. stpUp.Visibility = Visibility.Hidden;
  1917. }
  1918. PageNum = model_VideoList.Count;
  1919. if (PageNum > 0)
  1920. {
  1921. int t = 1;
  1922. while (PageNum > 16 * t)
  1923. {
  1924. t++;
  1925. }
  1926. PageNum = t;
  1927. }
  1928. else
  1929. {
  1930. PageNum = 0;
  1931. }
  1932. txbPageNumTwo.Text = PageNum.ToString();
  1933. APP.myloading.Hide();
  1934. DataContext = pageData;
  1935. }
  1936. /// <summary>
  1937. /// 当前页
  1938. /// </summary>
  1939. private int Currpage = 0;
  1940. /// <summary>
  1941. /// 总页码
  1942. /// </summary>
  1943. private int PageNum = 0;
  1944. /// <summary>
  1945. /// 加载视频列表
  1946. /// </summary>
  1947. public void LoadingVideoList()
  1948. {
  1949. try
  1950. {
  1951. model_VideoList = new List<Model_Video>();
  1952. foreach (Model_WKData Vdata in APP.WKDataList)
  1953. {
  1954. #region 计时器初始化
  1955. if (Vdata.VideoList == null)
  1956. {
  1957. continue;
  1958. }
  1959. foreach (Model_Video videoinfo in Vdata.VideoList)
  1960. {
  1961. try
  1962. {
  1963. if (string.IsNullOrWhiteSpace(videoinfo.VideoPath))
  1964. {
  1965. continue;
  1966. }
  1967. if (string.IsNullOrWhiteSpace(videoinfo.VideoSize) || videoinfo.VideoSize == "0 MB")
  1968. {
  1969. videoinfo.VideoSize = FileToolsCommon.GetFileSizeByMB(videoinfo.VideoPath).ToString() + " MB";
  1970. videoinfo.VideoSizebyte = FileToolsCommon.GetFileSize(videoinfo.VideoPath);
  1971. }
  1972. model_VideoList.Add(videoinfo);
  1973. }
  1974. catch (Exception ex)
  1975. {
  1976. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1977. }
  1978. }
  1979. #endregion
  1980. }
  1981. //翻转
  1982. if (model_VideoList.Count > 1)
  1983. {
  1984. model_VideoList.Reverse();
  1985. }
  1986. }
  1987. catch (Exception ex)
  1988. {
  1989. LogHelper.WriteErrLog("【加载视频列表】(LoadingVideoList)" + ex.Message, ex);
  1990. }
  1991. }
  1992. ////定义事件
  1993. //public event ChangeTextHandler ChangeTextEvents;
  1994. /// <summary>
  1995. /// 上传
  1996. /// </summary>
  1997. /// <param name="sender"></param>
  1998. /// <param name="e"></param>
  1999. private void BtnUploads_Click(object sender, RoutedEventArgs e)
  2000. {
  2001. if (APP.IsLoginType == false)
  2002. {
  2003. Login();
  2004. return;
  2005. }
  2006. pageData.menuList[Subscript].IsEnabled = false;
  2007. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnUpload");
  2008. for (int i = 0; i < buttons.Count; i++)
  2009. {
  2010. if (buttons[i] == sender)
  2011. {
  2012. DAL_Upload dAL_Upload = new DAL_Upload();
  2013. if (dAL_Upload.UploadVideo(pageData.menuList[i].FileGuid, out string ErrMessage))
  2014. {
  2015. //MessageWindow.Show("视频上传服务器成功!");
  2016. if (APP.W_UploadWindow == null)
  2017. {
  2018. APP.W_UploadWindow = new UploadWindow
  2019. {
  2020. Owner = this
  2021. };
  2022. APP.W_UploadWindow.ChangeTextEvents += new ChangeTextHandlers(frm_ChangeTextEvents);
  2023. }
  2024. //long size = Convert.ToInt64(FileToolsCommon.GetFileSizeByMB(pageData.menuList[i].FilePath));
  2025. APP.W_UploadWindow.Initialize(pageData.menuList[i].VideoName, pageData.menuList[i].VideoSizes, pageData.menuList[i].VideoType, pageData.menuList[i].FileGuid, i);
  2026. APP.W_UploadWindow.ShowDialog();
  2027. }
  2028. else
  2029. {
  2030. MessageWindow.Show(ErrMessage);
  2031. }
  2032. }
  2033. }
  2034. }
  2035. /// <summary>
  2036. /// 上传返回事件
  2037. /// </summary>
  2038. /// <param name="text"></param>
  2039. private void frm_ChangeTextEvents(string text, int i)
  2040. {
  2041. if ("上传成功".Equals(text))
  2042. {
  2043. pageData.menuList[i].Visi = "Visible";
  2044. pageData.menuList[i].Coll = "Collapsed";
  2045. DataContext = pageData;
  2046. }
  2047. }
  2048. /// <summary>
  2049. /// 删除
  2050. /// </summary>
  2051. /// <param name="sender"></param>
  2052. /// <param name="e"></param>
  2053. private void BtnDelete_Click(object sender, RoutedEventArgs e)
  2054. {
  2055. MessageBoxResult dr = MessageWindow.Show("确定删除该视频?", "提示", MessageBoxButton.OKCancel);
  2056. if (dr == MessageBoxResult.OK)
  2057. {
  2058. pageData.menuList[Subscript].IsEnabled = false;
  2059. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnDelete");
  2060. for (int i = 0; i < buttons.Count; i++)
  2061. {
  2062. if (buttons[i] == sender)
  2063. {
  2064. //if (APP.W_PromptWindow == null)
  2065. //{
  2066. // APP.W_PromptWindow = new PromptWindow();
  2067. // APP.W_PromptWindow.Owner = this;
  2068. //}
  2069. //APP.W_PromptWindow.Initialize(pageData.menuList[i].VideoName);
  2070. //APP.W_PromptWindow.ShowDialog();
  2071. foreach (Model_WKData wKData in APP.WKDataList)
  2072. {
  2073. if (wKData.VideoList == null)
  2074. {
  2075. continue;
  2076. }
  2077. if (wKData.VideoList.Exists(x => x.FileGuid == pageData.menuList[i].FileGuid))
  2078. {
  2079. try
  2080. {
  2081. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).VideoPath);
  2082. FileToolsCommon.DeleteFile(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid).ThumbnailPath);
  2083. wKData.VideoList.Remove(wKData.VideoList.Find(x => x.FileGuid == pageData.menuList[i].FileGuid));
  2084. InitializeUpload();
  2085. return;
  2086. }
  2087. catch (Exception ex)
  2088. {
  2089. MessageWindow.Show("无法删除视频!" + ex.Message);
  2090. return;
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. /// <summary>
  2099. /// 播放
  2100. /// </summary>
  2101. /// <param name="sender"></param>
  2102. /// <param name="e"></param>
  2103. private void BtnPlay_Click(object sender, RoutedEventArgs e)
  2104. {
  2105. pageData.menuList[Subscript].IsEnabled = false;
  2106. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnPlay");
  2107. for (int i = 0; i < buttons.Count; i++)
  2108. {
  2109. if (buttons[i] == sender)
  2110. {
  2111. try
  2112. {
  2113. ProcessStartInfo psi = new ProcessStartInfo(pageData.menuList[i].Path);
  2114. Process pro = new Process
  2115. {
  2116. StartInfo = psi
  2117. };
  2118. pro.Start();
  2119. }
  2120. catch (Exception ex)
  2121. {
  2122. LogHelper.WriteErrLog("FileDirectoryWindow【BtnPlay_Click】" + ex.Message, ex);
  2123. System.Windows.MessageBox.Show(ex.Message);
  2124. return;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. /// <summary>
  2130. /// 搜索集合匹配的索引
  2131. /// </summary>
  2132. /// <typeparam name="T"></typeparam>
  2133. /// <param name="parent"></param>
  2134. /// <param name="childName"></param>
  2135. /// <returns></returns>
  2136. public static List<T> FindChilds<T>(DependencyObject parent, string childName)
  2137. where T : DependencyObject
  2138. {
  2139. List<T> list = new List<T>();
  2140. if (parent == null)
  2141. {
  2142. return list;
  2143. }
  2144. int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
  2145. for (int i = 0; i < childrenCount; i++)
  2146. {
  2147. DependencyObject child = VisualTreeHelper.GetChild(parent, i);
  2148. // 如果子控件不是需查找的控件类型
  2149. T childType = child as T;
  2150. if (childType == null)
  2151. {
  2152. // 在下一级控件中递归查找
  2153. List<T> findChildList = FindChilds<T>(child, childName);
  2154. for (int j = 0; j < findChildList.Count; j++)
  2155. {
  2156. }
  2157. list.AddRange(FindChilds<T>(child, childName));
  2158. }
  2159. else if (!string.IsNullOrEmpty(childName))
  2160. {
  2161. FrameworkElement frameworkElement = child as FrameworkElement;
  2162. // 如果控件名称符合参数条件
  2163. if (frameworkElement != null && frameworkElement.Name == childName)
  2164. {
  2165. list.Add((T)child);
  2166. }
  2167. }
  2168. else
  2169. {
  2170. // 查找到了控件
  2171. list.Add((T)child);
  2172. }
  2173. }
  2174. return list;
  2175. }
  2176. /// <summary>
  2177. /// 修改
  2178. /// </summary>
  2179. /// <param name="sender"></param>
  2180. /// <param name="e"></param>
  2181. private void BtnModify_Click(object sender, RoutedEventArgs e)
  2182. {
  2183. if (IsModify)
  2184. {
  2185. try
  2186. {
  2187. string newName = pageData.menuList[Subscript].VideoName + "." + pageData.menuList[Subscript].VideoType;
  2188. bool isName = ModifyPathName(pageData.menuList[Subscript].FileGuid, newName, out string Errmessage);
  2189. if (!isName)
  2190. {
  2191. MessageWindow.Show(Errmessage);
  2192. }
  2193. }
  2194. catch (Exception ex)
  2195. {
  2196. LogHelper.WriteErrLog("XHMicroLessonSystemWindow(BtnModify_Click)" + ex.Message, ex);
  2197. }
  2198. IsModify = false;
  2199. pageData.menuList[Subscript].IsEnabled = false;
  2200. listView1.DataContext = pageData;
  2201. }
  2202. else
  2203. {
  2204. List<System.Windows.Controls.Button> buttons = FindChilds<System.Windows.Controls.Button>(listView1, "btnModify");
  2205. for (int i = 0; i < buttons.Count; i++)
  2206. {
  2207. if (buttons[i] == sender)
  2208. {
  2209. pageData.menuList[i].IsEnabled = true;
  2210. Subscript = i;
  2211. IsModify = true;
  2212. }
  2213. }
  2214. }
  2215. }
  2216. private int MouseNumber = 0;
  2217. /// <summary>
  2218. /// 上传 上页
  2219. /// </summary>
  2220. /// <param name="sender"></param>
  2221. /// <param name="e"></param>
  2222. private void BtnLastPage_Click(object sender, RoutedEventArgs e)
  2223. {
  2224. if (Currpage > 1)
  2225. {
  2226. Currpage -= 1;
  2227. txbCurrpageTwo.Text = Currpage.ToString();
  2228. int i = 1;
  2229. bool isColour = true;
  2230. pageData.menuList.Clear();
  2231. //显示视频
  2232. foreach (Model_Video videoinfo in model_VideoList)
  2233. {
  2234. //是否已上传
  2235. //videoinfo.IsUpload;
  2236. //录制时间
  2237. //videoinfo.RSTime;
  2238. //文件大小
  2239. //videoinfo.VideoSize;
  2240. //文件缩略图路径
  2241. //videoinfo.ThumbnailPath;
  2242. //文件唯一标示 上传事件筛选需要上传的视频
  2243. //videoinfo.FileGuid;
  2244. //文件存储路径
  2245. //videoinfo.VidePath;
  2246. string colour = "#FFFFFF";
  2247. if (isColour == true)
  2248. {
  2249. colour = "#FFFFFF";
  2250. isColour = false;
  2251. }
  2252. else
  2253. {
  2254. colour = "#E6F1FF";
  2255. isColour = true;
  2256. }
  2257. string vis = "Visible";
  2258. string cos = "Collapsed";
  2259. if (!videoinfo.IsUpload)
  2260. {
  2261. vis = "Collapsed";
  2262. cos = "Visible";
  2263. }
  2264. if (i <= Currpage * 16 && i >= (Currpage - 1) * 16)
  2265. {
  2266. pageData.menuList.Add(new FileDirectoryModel()
  2267. {
  2268. SerialNumber = i,
  2269. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2270. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2271. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2272. VideoDuration = 0,
  2273. VideoSize = videoinfo.VideoSize,
  2274. VideoTime = videoinfo.RSTime,
  2275. IsEnabled = false,
  2276. Path = videoinfo.VideoPath,
  2277. Colour = colour,
  2278. Visi = vis,
  2279. Coll = cos,
  2280. FileGuid = videoinfo.FileGuid,
  2281. VideoType = videoinfo.VideoType.ToString()
  2282. }); ;
  2283. }
  2284. i++;
  2285. }
  2286. APP.myloading.Hide();
  2287. }
  2288. }
  2289. /// <summary>
  2290. /// 上传 下页
  2291. /// </summary>
  2292. /// <param name="sender"></param>
  2293. /// <param name="e"></param>
  2294. private void BtnNextPage_Click(object sender, RoutedEventArgs e)
  2295. {
  2296. if (Currpage < PageNum)
  2297. {
  2298. Currpage += 1;
  2299. txbCurrpageTwo.Text = Currpage.ToString();
  2300. int i = 1;
  2301. bool isColour = true;
  2302. pageData.menuList.Clear();
  2303. //显示视频
  2304. foreach (Model_Video videoinfo in model_VideoList)
  2305. {
  2306. //是否已上传
  2307. //videoinfo.IsUpload;
  2308. //录制时间
  2309. //videoinfo.RSTime;
  2310. //文件大小
  2311. //videoinfo.VideoSize;
  2312. //文件缩略图路径
  2313. //videoinfo.ThumbnailPath;
  2314. //文件唯一标示 上传事件筛选需要上传的视频
  2315. //videoinfo.FileGuid;
  2316. //文件存储路径
  2317. //videoinfo.VidePath;
  2318. string colour = "#FFFFFF";
  2319. if (isColour == true)
  2320. {
  2321. colour = "#FFFFFF";
  2322. isColour = false;
  2323. }
  2324. else
  2325. {
  2326. colour = "#E6F1FF";
  2327. isColour = true;
  2328. }
  2329. string vis = "Visible";
  2330. string cos = "Collapsed";
  2331. if (!videoinfo.IsUpload)
  2332. {
  2333. vis = "Collapsed";
  2334. cos = "Visible";
  2335. }
  2336. if (i <= Currpage * 16 && i > (Currpage - 1) * 16)
  2337. {
  2338. pageData.menuList.Add(new FileDirectoryModel()
  2339. {
  2340. SerialNumber = i,
  2341. VideoName = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2342. Name = Common.system.FileToolsCommon.GetIOFileName(videoinfo.VideoPath).Replace(".MP4", "").Replace(".FLV", "").Replace(".AVI", "").Trim(),
  2343. FilePath = videoinfo.VideoPath.Replace(FileToolsCommon.GetIOFileName(videoinfo.VideoPath), "").Trim(),
  2344. VideoDuration = 0,
  2345. VideoSize = videoinfo.VideoSize,
  2346. VideoTime = videoinfo.RSTime,
  2347. IsEnabled = false,
  2348. Path = videoinfo.VideoPath,
  2349. Colour = colour,
  2350. Visi = vis,
  2351. Coll = cos,
  2352. FileGuid = videoinfo.FileGuid,
  2353. VideoType = videoinfo.VideoType.ToString()
  2354. }); ;
  2355. }
  2356. i++;
  2357. }
  2358. APP.myloading.Hide();
  2359. }
  2360. }
  2361. /// <summary>
  2362. /// 修改文件名
  2363. /// </summary>
  2364. /// <param name="Guid">唯一编号</param>
  2365. /// <param name="NewName">新文件名带后缀 不带路径</param>
  2366. /// <param name="Errmessage">错误信息</param>
  2367. /// <returns></returns>
  2368. private bool ModifyPathName(string FileGuid, string NewName, out string Errmessage)
  2369. {
  2370. Errmessage = "";
  2371. foreach (Model_WKData WKData in APP.WKDataList)
  2372. {
  2373. if (WKData.VideoList.Exists(x => x.FileGuid == FileGuid))
  2374. {
  2375. Model_Video model_Video = WKData.VideoList.Find(x => x.FileGuid == FileGuid);
  2376. string filePathName = model_Video.VideoPath;
  2377. string filePath = FileToolsCommon.GetDirectoryName(filePathName);
  2378. string newFilePathName = filePath + NewName;
  2379. //缩略图
  2380. string ThumbnailPath = filePath + "ThumbnailPath/";
  2381. FileToolsCommon.CreateDirectory(ThumbnailPath);
  2382. //缩略图存储位置
  2383. string ThumbnailPathName = ThumbnailPath + NewName.Replace(".", "") + ".JPG";
  2384. if (FileToolsCommon.IsExistFile(newFilePathName))
  2385. {
  2386. Errmessage = "文件已存在,请重新修改文件名!";
  2387. return false;
  2388. }
  2389. else
  2390. {
  2391. //修改文件名
  2392. FileToolsCommon.Copy(filePathName, newFilePathName);
  2393. model_Video.VideoPath = newFilePathName;
  2394. //修改缩略图名
  2395. FileToolsCommon.DeleteFile(ThumbnailPathName);
  2396. FileToolsCommon.Copy(model_Video.ThumbnailPath, ThumbnailPathName);
  2397. model_Video.ThumbnailPath = ThumbnailPathName;
  2398. APP.SaveWkData();
  2399. return true;
  2400. }
  2401. }
  2402. else
  2403. {
  2404. continue;
  2405. }
  2406. }
  2407. Errmessage = "视频文件有改动,当前文件不存在,请关闭后重新打开“我的”";
  2408. return false;
  2409. }
  2410. #endregion
  2411. #region 新上传 显示缩略图
  2412. #region 初始值
  2413. /// <summary>
  2414. /// 总页数
  2415. /// </summary>
  2416. private int TotalPage = 0;
  2417. /// <summary>
  2418. /// 当前页
  2419. /// </summary>
  2420. private int CurrentPage = 1;
  2421. /// <summary>
  2422. /// 每页显示的视频数
  2423. /// </summary>
  2424. private int PageShowNum = 0;
  2425. /// <summary>
  2426. /// 视频信息列表
  2427. /// </summary>
  2428. private List<Uc_VideoItem> VideoControlList = new List<Uc_VideoItem>();
  2429. /// <summary>
  2430. /// 横向间隔
  2431. /// </summary>
  2432. private double IntervalX = 0;
  2433. /// <summary>
  2434. /// 纵向间隔
  2435. /// </summary>
  2436. private double IntervalY = 0;
  2437. #endregion
  2438. /// <summary>
  2439. /// 初始化加载上传页面数据
  2440. /// </summary>
  2441. private void LoadUploadInitData()
  2442. {
  2443. APP.myloading.Show();
  2444. //加载视频列表
  2445. LoadingVideoList();
  2446. if (model_VideoList.Count > 0)
  2447. {
  2448. lblVideoMess.Visibility = Visibility.Hidden;
  2449. BtnVideoUpPage.Visibility = Visibility.Visible;
  2450. lblVideoPageNum.Visibility = Visibility.Visible;
  2451. BtnVideoDownPage.Visibility = Visibility.Visible;
  2452. //根据页面大小获取每页显示的数量 H300W250
  2453. int videoRow = (int)((GridMyVideo.ActualHeight - 50) / 300);
  2454. int videColumn = (int)(GridMyVideo.ActualWidth / 250);
  2455. PageShowNum = (videoRow == 0 ? 1 : videoRow) * (videColumn == 0 ? 1 : videColumn);
  2456. //获取总页数
  2457. TotalPage = model_VideoList.Count / PageShowNum + (model_VideoList.Count % PageShowNum > 0 ? 1 : 0);
  2458. //如果当前页大于总页数 总页数为当前页
  2459. if (TotalPage < CurrentPage)
  2460. {
  2461. CurrentPage = TotalPage;
  2462. }
  2463. //横向间隔
  2464. IntervalX = (GridMyVideo.ActualWidth - (videColumn * 250)) / (videColumn + 1);
  2465. IntervalY = (GridMyVideo.ActualHeight - 50 - (videoRow * 300)) / (videoRow + 1);
  2466. LoadCurrentPageData();
  2467. }
  2468. else
  2469. {
  2470. lblVideoMess.Visibility = Visibility.Visible;
  2471. BtnVideoUpPage.Visibility = Visibility.Hidden;
  2472. lblVideoPageNum.Visibility = Visibility.Hidden;
  2473. BtnVideoDownPage.Visibility = Visibility.Hidden;
  2474. //隐藏显示的控件
  2475. if (VideoControlList.Count > 0)
  2476. {
  2477. foreach (Uc_VideoItem item in VideoControlList)
  2478. {
  2479. if (item.Visibility != Visibility.Hidden)
  2480. {
  2481. item.Visibility = Visibility.Hidden;
  2482. }
  2483. }
  2484. }
  2485. }
  2486. APP.myloading.Hide();
  2487. }
  2488. /// <summary>
  2489. /// 加载当前页数据
  2490. /// </summary>
  2491. private void LoadCurrentPageData()
  2492. {
  2493. lblVideoPageNum.Content = CurrentPage + "/" + TotalPage;
  2494. //隐藏显示的控件
  2495. if (VideoControlList.Count > 0)
  2496. {
  2497. foreach (Uc_VideoItem item in VideoControlList)
  2498. {
  2499. if (item.Visibility != Visibility.Hidden)
  2500. {
  2501. item.Visibility = Visibility.Hidden;
  2502. }
  2503. }
  2504. }
  2505. double W = IntervalX;//每次增加250
  2506. double H = IntervalY;//每次增加300
  2507. //加载控件
  2508. for (int i = 0; i < PageShowNum; i++)
  2509. {
  2510. int DataIndex = (CurrentPage - 1) * PageShowNum + i;
  2511. if (DataIndex == model_VideoList.Count)
  2512. {
  2513. return;
  2514. }
  2515. Uc_VideoItem videoItem;
  2516. if (VideoControlList.Exists(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid))
  2517. {
  2518. videoItem = VideoControlList.Find(x => x.Tag.ToString() == model_VideoList[DataIndex].FileGuid);
  2519. }
  2520. else
  2521. {
  2522. if (!FileToolsCommon.IsExistFile(model_VideoList[DataIndex].ThumbnailPath))
  2523. {
  2524. continue;
  2525. }
  2526. videoItem = new Uc_VideoItem(model_VideoList[DataIndex])
  2527. {
  2528. Tag = model_VideoList[DataIndex].FileGuid
  2529. };
  2530. videoItem.Click_refreshVideoList += LoadUploadInitData;
  2531. videoItem.Click_UploadLogin += Login;
  2532. videoItem.Width = 250;
  2533. videoItem.Height = 300;
  2534. videoItem.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
  2535. videoItem.VerticalAlignment = System.Windows.VerticalAlignment.Top;
  2536. GridMyVideo.Children.Add(videoItem);
  2537. VideoControlList.Add(videoItem);
  2538. }
  2539. videoItem.Margin = new Thickness(W, H, 0, 0);
  2540. videoItem.Visibility = Visibility.Visible;
  2541. if (W + 250 + 250 > GridMyVideo.ActualWidth)
  2542. {
  2543. W = IntervalX;
  2544. H += 300 + IntervalY;
  2545. }
  2546. else
  2547. {
  2548. W += 250 + IntervalX;
  2549. }
  2550. //Uc_VideoItem videoItem = new Uc_VideoItem();
  2551. //return;
  2552. }
  2553. }
  2554. #region 分页
  2555. /// <summary>
  2556. /// 上一页
  2557. /// </summary>
  2558. /// <param name="sender"></param>
  2559. /// <param name="e"></param>
  2560. private void BtnVideoUpPage_Click(object sender, RoutedEventArgs e)
  2561. {
  2562. if (CurrentPage > 1)
  2563. {
  2564. CurrentPage--;
  2565. LoadCurrentPageData();
  2566. }
  2567. }
  2568. /// <summary>
  2569. /// 下一页
  2570. /// </summary>
  2571. /// <param name="sender"></param>
  2572. /// <param name="e"></param>
  2573. private void BtnVideoDownPage_Click(object sender, RoutedEventArgs e)
  2574. {
  2575. if (CurrentPage < TotalPage)
  2576. {
  2577. CurrentPage++;
  2578. LoadCurrentPageData();
  2579. }
  2580. }
  2581. #endregion
  2582. #endregion
  2583. #region 录制窗口
  2584. #region 变量
  2585. /// <summary>
  2586. /// 视频保存路径
  2587. /// </summary>
  2588. //string RecordingPath;
  2589. /// <summary>
  2590. /// 图片保存路径
  2591. /// </summary>
  2592. private string ImgPath;
  2593. /// <summary>
  2594. /// 音频保存路径名
  2595. /// </summary>
  2596. private string AudioPathName;
  2597. /// <summary>
  2598. /// 视频保存路径名
  2599. /// </summary>
  2600. private string VideoSavePathName;
  2601. /// <summary>
  2602. /// 视频合成路径名
  2603. /// </summary>
  2604. private string VideoSynthesisPathName;
  2605. /// <summary>
  2606. /// 暂停录制
  2607. /// </summary>
  2608. private bool IsSuspendR = true;
  2609. /// <summary>
  2610. /// 录制是否已停止
  2611. /// </summary>
  2612. private bool IsFirstR = true;
  2613. /// <summary>
  2614. /// 图片
  2615. /// </summary>
  2616. private List<string> RsImgName = null;
  2617. /// <summary>
  2618. /// 是否开始截图计数
  2619. /// </summary>
  2620. private bool IsStartCount = false;
  2621. /// <summary>
  2622. /// 是否录制了音频
  2623. /// </summary>
  2624. private bool IsRecordAudio = false;
  2625. /// <summary>
  2626. /// 截图定时器
  2627. /// </summary>
  2628. private System.Threading.Timer timer;
  2629. /// <summary>
  2630. /// 录制计时
  2631. /// </summary>
  2632. private DateTime SRTime = DateTime.Now;
  2633. /// <summary>
  2634. /// 录制大小
  2635. /// </summary>
  2636. private int gridActWidth = 1276;
  2637. /// <summary>
  2638. /// 录制大小
  2639. /// </summary>
  2640. private int gridActHeight = 898;
  2641. #endregion
  2642. #region 录屏
  2643. /// <summary>
  2644. /// 录屏事件
  2645. /// </summary>
  2646. /// <param name="sender"></param>
  2647. /// <param name="e"></param>
  2648. private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
  2649. {
  2650. Record();
  2651. if (!APP.CheckScreenCapturerRecorder())
  2652. {
  2653. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  2654. APP.InstallScreenCapturerRecorder();
  2655. return;
  2656. }
  2657. #region 限制只允许录制一个录屏 废弃
  2658. //string RecordScreenPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  2659. //if (FileToolsCommon.IsExistFile(RecordScreenPathName))
  2660. //{
  2661. // MessageBoxResult dr = MessageWindow.Show("已存在录屏,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  2662. // if (dr == MessageBoxResult.OK)
  2663. // {
  2664. // try
  2665. // {
  2666. // FileToolsCommon.DeleteFile(RecordScreenPathName);
  2667. // APP.VideoList.RemoveAll(x => x.VideoPath == RecordScreenPathName);
  2668. // }
  2669. // catch (Exception ex)
  2670. // {
  2671. // LogHelper.WriteErrLog("【录屏】(BtnRecordingScreen_Click)无法移除视频," + ex.Message, ex);
  2672. // }
  2673. // }
  2674. // else
  2675. // {
  2676. // return;
  2677. // }
  2678. //}
  2679. #endregion
  2680. k_hook.Stop();
  2681. if (APP.W_ScreenRecordingToolbarWindow == null)
  2682. {
  2683. APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow
  2684. {
  2685. Topmost = true
  2686. };
  2687. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2688. }
  2689. else
  2690. {
  2691. APP.W_ScreenRecordingToolbarWindow.Initialize();
  2692. }
  2693. APP.W_ScreenRecordingToolbarWindow.Click_stopRecordingScreen += W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen;
  2694. //显示在右下角
  2695. APP.W_ScreenRecordingToolbarWindow.WindowStartupLocation = WindowStartupLocation.Manual;
  2696. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  2697. float DIP = graphics.DpiX;
  2698. float DIPY = graphics.DpiY;
  2699. APP.W_ScreenRecordingToolbarWindow.Left = PrimaryScreen.WorkingArea.Width / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Width - 60;
  2700. APP.W_ScreenRecordingToolbarWindow.Top = PrimaryScreen.WorkingArea.Height / (DIP / 96) - APP.W_ScreenRecordingToolbarWindow.Height - 30;
  2701. APP.W_ScreenRecordingToolbarWindow.Topmost = true;
  2702. APP.W_ScreenRecordingToolbarWindow.Show();
  2703. Hide();
  2704. }
  2705. /// <summary>
  2706. /// 保存录屏中
  2707. /// </summary>
  2708. private void W_ScreenRecordingToolbarWindow_Click_stopRecordingScreen()
  2709. {
  2710. txbTime.Text = "";
  2711. txbTime.Visibility = Visibility.Hidden;
  2712. txbType.Visibility = Visibility.Visible;
  2713. txbType.Text = "保存中";
  2714. btnScreenRecording.IsEnabled = false;
  2715. new Thread(new ThreadStart(new Action(() =>
  2716. {
  2717. while (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath + "temprs/"))
  2718. {
  2719. Thread.Sleep(100);
  2720. }
  2721. Thread.Sleep(100);
  2722. Dispatcher.Invoke(() =>
  2723. {
  2724. btnScreenRecording.IsEnabled = true;
  2725. txbType.Visibility = Visibility.Hidden;
  2726. //TxbRecordScreenWord.Text = "录屏";
  2727. });
  2728. }))).Start();
  2729. }
  2730. #endregion
  2731. private bool IsPressButton = false;
  2732. /// <summary>
  2733. /// 录制窗口内容
  2734. /// </summary>
  2735. /// <param name="sender"></param>
  2736. /// <param name="e"></param>
  2737. private void BtnRecord_Click(object sender, RoutedEventArgs e)
  2738. {
  2739. #region 防止连击
  2740. if (IsPressButton)
  2741. {
  2742. return;
  2743. }
  2744. else
  2745. {
  2746. IsPressButton = true;
  2747. new Thread(new ThreadStart(new Action(() =>
  2748. {
  2749. Thread.Sleep(500);
  2750. IsPressButton = false;
  2751. }))).Start();
  2752. }
  2753. #endregion
  2754. Record();
  2755. if (!APP.CheckScreenCapturerRecorder())
  2756. {
  2757. MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
  2758. APP.InstallScreenCapturerRecorder();
  2759. return;
  2760. }
  2761. if (APP.pageData.currpage > 0)
  2762. {
  2763. blackboard_canvas.Visibility = Visibility.Visible;
  2764. }
  2765. else
  2766. {
  2767. MessageWindow.Show("请先导入文档或截图!");
  2768. return;
  2769. }
  2770. if (RectImgBorder.Visibility != Visibility.Hidden)
  2771. {
  2772. HideAngleBorder();
  2773. }
  2774. //btnStop.IsEnabled = true;//停止录制按钮可点击
  2775. StartRecord();
  2776. }
  2777. /// <summary>
  2778. /// 停止录制窗口内容
  2779. /// </summary>
  2780. /// <param name="sender"></param>
  2781. /// <param name="e"></param>
  2782. private void BtnStop_Click(object sender, RoutedEventArgs e)
  2783. {
  2784. #region 防止连击
  2785. if (IsPressButton)
  2786. {
  2787. return;
  2788. }
  2789. else
  2790. {
  2791. IsPressButton = true;
  2792. new Thread(new ThreadStart(new Action(() =>
  2793. {
  2794. Thread.Sleep(500);
  2795. IsPressButton = false;
  2796. }))).Start();
  2797. }
  2798. #endregion
  2799. blackboard_canvas.Visibility = Visibility.Collapsed;
  2800. EndRecord();
  2801. }
  2802. /// <summary>
  2803. /// 设置录屏文件地址
  2804. /// </summary>
  2805. private void SetUpVideoPathName()
  2806. {
  2807. }
  2808. /// <summary>
  2809. /// 开始录制和暂停录制
  2810. /// </summary>
  2811. private void StartRecord()
  2812. {
  2813. if (IsSuspendR)
  2814. {
  2815. if (IsFirstR)//是否第一次录制 初始化录制
  2816. {
  2817. #region 检测麦克风扬声器是否可用
  2818. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  2819. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  2820. try
  2821. {
  2822. FileToolsCommon.DeleteFile(audioSpeakerPath);
  2823. FileToolsCommon.DeleteFile(audioMicrophonePath);
  2824. }
  2825. catch (Exception)
  2826. {
  2827. }
  2828. //扬声器
  2829. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  2830. {
  2831. APP.FFmpeg.StopRecordAudio(2);
  2832. //Thread.Sleep(500);
  2833. //麦克风
  2834. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  2835. {
  2836. }
  2837. else
  2838. {
  2839. //无法录制麦克风
  2840. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  2841. if (Res == MessageBoxResult.Cancel)
  2842. {
  2843. return;
  2844. }
  2845. }
  2846. APP.FFmpeg.StopRecordAudio(1);
  2847. }
  2848. else
  2849. {
  2850. //无法录制扬声器音频
  2851. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  2852. if (Res == MessageBoxResult.Cancel)
  2853. {
  2854. return;
  2855. }
  2856. }
  2857. #endregion
  2858. txbTime.Visibility = Visibility.Visible;
  2859. VideoInfo = new Model_Video
  2860. {
  2861. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  2862. WkType = Enum_WKVidetype.RecordingLessons
  2863. };
  2864. ImgPath = APP.WKData.WkPath + "temp/Image/";
  2865. AudioPathName = APP.WKData.WkPath + "temp/audio/";
  2866. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  2867. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  2868. FileToolsCommon.CreateDirectory(ImgPath);
  2869. FileToolsCommon.CreateDirectory(AudioPathName);
  2870. AudioPathName += APP.WKData.WkName + ".MP3";
  2871. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制." + VideoInfo.VideoType.ToString();
  2872. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn." + VideoInfo.VideoType.ToString();
  2873. int num = 1;
  2874. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  2875. {
  2876. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制_" + num + "." + VideoInfo.VideoType.ToString();
  2877. VideoSynthesisPathName = APP.WKData.WkPath + APP.WKData.WkName + "_录制Syn_" + num + "." + VideoInfo.VideoType.ToString();
  2878. num++;
  2879. }
  2880. #region 设置录屏唯一 废弃
  2881. //if (FileToolsCommon.IsExistFile(VideoSavePathName))
  2882. //{
  2883. // MessageBoxResult dr = MessageWindow.Show("课程已录制,是否覆盖?", "提示", MessageBoxButton.OKCancel);
  2884. // if (dr == MessageBoxResult.OK)
  2885. // {
  2886. // try
  2887. // {
  2888. // FileToolsCommon.DeleteFile(VideoSavePathName);
  2889. // APP.VideoList.RemoveAll(x => x.VideoPath == VideoSavePathName);
  2890. // }
  2891. // catch (Exception ex)
  2892. // {
  2893. // LogHelper.WriteErrLog("【录制】(StartRecord)无法移除视频," + ex.Message, ex);
  2894. // }
  2895. // }
  2896. // else
  2897. // {
  2898. // return;
  2899. // }
  2900. //}
  2901. #endregion
  2902. #region 禁用按钮
  2903. ImgPrint.Visibility = Visibility.Collapsed;//录制中不可打印
  2904. ImgPrintTwo.Visibility = Visibility.Visible;
  2905. btnPrint.IsEnabled = false;
  2906. ImgScreenshot.Visibility = Visibility.Collapsed;//录制中不可截图
  2907. ImgScreenshotTwo.Visibility = Visibility.Visible;
  2908. btnScreenshot.IsEnabled = false;
  2909. ImgImport.Visibility = Visibility.Collapsed;//录制中不可导入文档
  2910. ImgImportTwo.Visibility = Visibility.Visible;
  2911. btnImport.IsEnabled = false;
  2912. ImgScreenRecording.Visibility = Visibility.Collapsed;//录制中不可录屏
  2913. ImgScreenRecordingTwo.Visibility = Visibility.Visible;
  2914. btnScreenRecording.IsEnabled = false;
  2915. ImgUpload.Visibility = Visibility.Collapsed;//录制中不可上传
  2916. ImgUploadTwo.Visibility = Visibility.Visible;
  2917. btnUpload.IsEnabled = false;
  2918. ImgSetUp.Visibility = Visibility.Collapsed;//录制中不可设置
  2919. ImgSetUpTwo.Visibility = Visibility.Visible;
  2920. btnSetUp.IsEnabled = false;
  2921. btnLoginType.IsEnabled = false;
  2922. blackboard_canvas.Visibility = Visibility.Visible;//zxyceshi
  2923. //myblackboard = new BlackboardNew(blackboard_canvas);
  2924. //DataContext = APP.pageData;
  2925. //drawingAttributes = new DrawingAttributes();
  2926. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  2927. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  2928. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  2929. //blackboard_canvas.UseCustomCursor = true;
  2930. //drawingAttributes.FitToCurve = true;
  2931. //drawingAttributes.IgnorePressure = false;
  2932. //drawingAttributes.Width = PenSize;
  2933. //drawingAttributes.Height = PenSize;
  2934. //drawingAttributes.Color = Color;
  2935. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  2936. #endregion
  2937. #region 设置录制大小
  2938. //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
  2939. //gridActHeight = (int)GridMain.ActualHeight==0?898: (int)GridMain.ActualHeight;
  2940. gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  2941. gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  2942. gridActWidth = gridActWidth % 2 > 0 ? gridActWidth - 1 : gridActWidth;
  2943. gridActHeight = gridActHeight % 2 > 0 ? gridActHeight - 1 : gridActHeight;
  2944. #endregion
  2945. #region 录像倒计时
  2946. if (APP.W_CountdownWindow == null)
  2947. {
  2948. APP.W_CountdownWindow = new CountdownWindow();
  2949. APP.W_CountdownWindow.Initialize();
  2950. //APP.W_CountdownWindow.Topmost = true;
  2951. }
  2952. else
  2953. {
  2954. APP.W_CountdownWindow.Initialize();
  2955. //APP.W_CountdownWindow.Topmost = true;
  2956. }
  2957. APP.W_CountdownWindow.Show();
  2958. #endregion
  2959. IsFirstR = false;
  2960. RsImgName = new List<string>();
  2961. SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
  2962. txbTime.Visibility = Visibility.Visible;
  2963. ///启动截图
  2964. timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
  2965. //{
  2966. // AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  2967. //};//设置执行一次(false)还是一直执行(true)
  2968. //timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
  2969. //timer.Enabled = true; //启动计时器
  2970. }
  2971. //继续录制
  2972. IsSuspendR = false;
  2973. //BtnRecording.Content = "暂停录制";
  2974. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
  2975. TxbRecordingWord.Text = "暂停";
  2976. #region 4秒内不可点击
  2977. //new Thread(new ThreadStart(new Action(() =>
  2978. //{
  2979. // Dispatcher.Invoke(() =>
  2980. // {
  2981. // BtnRecord.IsEnabled = false;
  2982. // btnStop.IsEnabled = false;
  2983. // ImgStop.Visibility = Visibility.Visible;
  2984. // ImgStopTwo.Visibility = Visibility.Collapsed;
  2985. // });
  2986. //}))).Start();
  2987. new Thread(new ThreadStart(new Action(() =>
  2988. {
  2989. //Thread.Sleep(4000);
  2990. Dispatcher.Invoke(() =>
  2991. {
  2992. BtnRecord.IsEnabled = true;
  2993. btnStop.IsEnabled = true;
  2994. ImgStop.Visibility = Visibility.Collapsed;
  2995. ImgStopTwo.Visibility = Visibility.Visible;
  2996. });
  2997. }))).Start();
  2998. #endregion
  2999. try
  3000. {
  3001. new Thread(new ThreadStart(new Action(() =>
  3002. {
  3003. Thread.Sleep(1000);
  3004. IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName, out string ErrMessage);
  3005. Thread.Sleep(1000);
  3006. Dispatcher.Invoke(() =>
  3007. {
  3008. if (!IsRecordAudio)
  3009. {
  3010. MessageWindow.Show(ErrMessage);
  3011. }
  3012. Recorddt = DateTime.Now;
  3013. IsStartCount = true;
  3014. //Stack();
  3015. //timer.Start();
  3016. });
  3017. }))).Start();
  3018. }
  3019. catch (Exception ex)
  3020. {
  3021. MessageWindow.Show(ex.Message);
  3022. }
  3023. }
  3024. else
  3025. {
  3026. //暂停
  3027. IsSuspendR = true;
  3028. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3029. ImgStop.Visibility = Visibility.Collapsed;
  3030. ImgStopTwo.Visibility = Visibility.Visible;
  3031. TxbRecordingWord.Text = "继续";
  3032. //TimeOut();
  3033. #region 2秒内不可点击
  3034. new Thread(new ThreadStart(new Action(() =>
  3035. {
  3036. Dispatcher.Invoke(() =>
  3037. {
  3038. BtnRecord.IsEnabled = false;
  3039. btnStop.IsEnabled = false;
  3040. });
  3041. Thread.Sleep(2000);
  3042. Dispatcher.Invoke(() =>
  3043. {
  3044. BtnRecord.IsEnabled = true;
  3045. btnStop.IsEnabled = true;
  3046. });
  3047. }))).Start();
  3048. #endregion
  3049. try
  3050. {
  3051. APP.FFmpeg.SuspendFFmpeg();
  3052. new Thread(new ThreadStart(new Action(() =>
  3053. {
  3054. while (APP.FFmpeg.myProcess != null)
  3055. {
  3056. Thread.Sleep(100);
  3057. }
  3058. IsStartCount = false;
  3059. }))).Start();
  3060. }
  3061. catch (Exception ex)
  3062. {
  3063. MessageWindow.Show(ex.Message);
  3064. }
  3065. }
  3066. }
  3067. /// <summary>
  3068. /// 记录上次截图时间
  3069. /// </summary>
  3070. private DateTime Recorddt = DateTime.Now;
  3071. /// <summary>
  3072. /// 录制保存图片计时器
  3073. /// </summary>
  3074. /// <param name="sender"></param>
  3075. private void Timer_Elapsed(object sender)
  3076. {
  3077. if (IsStartCount)
  3078. {
  3079. DateTime dt = DateTime.Now;
  3080. TimeSpan ts = dt.Subtract(Recorddt);//时间差
  3081. double tsmi = ts.TotalMilliseconds;
  3082. if (tsmi > 200.0)
  3083. {
  3084. Recorddt = Recorddt.AddMilliseconds(200);
  3085. Thread thread = new Thread(RecordSaveImage);
  3086. //开启线程
  3087. thread.Start();
  3088. }
  3089. }
  3090. }
  3091. /// <summary>
  3092. /// 录制保存图片
  3093. /// </summary>
  3094. private void RecordSaveImage()
  3095. {
  3096. try
  3097. {
  3098. if (IsStartCount)
  3099. {
  3100. string FilePathName = ImgPath + RsImgName.Count + ".png";
  3101. RsImgName.Add(FilePathName);
  3102. #region 设置大小
  3103. double RsW = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
  3104. double RsH = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
  3105. if (RsW > 1266)
  3106. {
  3107. double Proportion = RsH / RsW;
  3108. RsW = 1266;
  3109. RsH = RsW * Proportion;
  3110. RsH = ((int)RsH) % 2 > 0 ? (int)RsH - 1 : (int)RsH;
  3111. //RsH = 898;
  3112. }
  3113. #endregion
  3114. //System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new ThreadStart(delegate
  3115. //{
  3116. //}));
  3117. Dispatcher.Invoke(() =>
  3118. {
  3119. //保存图片
  3120. ImageHelper.SaveUI(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  3121. //ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, (int)RsW, (int)RsH);
  3122. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f)), 0, 0);
  3123. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW, (int)RsH);
  3124. //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
  3125. SRTime = SRTime.AddMilliseconds(200);
  3126. if (txbTime.Visibility == Visibility.Hidden)
  3127. {
  3128. txbTime.Visibility = Visibility.Visible;
  3129. }
  3130. if (SRTime.Hour > 0)
  3131. {
  3132. //Dispatcher.Invoke(() =>
  3133. //{
  3134. txbTime.Text = SRTime.ToString("HH:mm:ss");
  3135. //});
  3136. }
  3137. else
  3138. {
  3139. //Dispatcher.Invoke(() =>
  3140. //{
  3141. txbTime.Text = SRTime.ToString("mm:ss");
  3142. //});
  3143. }
  3144. });
  3145. }
  3146. }
  3147. catch (Exception ex)
  3148. {
  3149. LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
  3150. }
  3151. }
  3152. /// <summary>
  3153. /// 停止录制并生成录制文件
  3154. /// </summary>
  3155. private void EndRecord()
  3156. {
  3157. if (!IsFirstR)
  3158. {
  3159. #region 恢复被禁用的按钮
  3160. ImgPrint.Visibility = Visibility.Visible;
  3161. ImgPrintTwo.Visibility = Visibility.Collapsed;
  3162. btnPrint.IsEnabled = true;
  3163. ImgScreenshot.Visibility = Visibility.Visible;
  3164. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3165. btnScreenshot.IsEnabled = true;
  3166. ImgImport.Visibility = Visibility.Visible;
  3167. ImgImportTwo.Visibility = Visibility.Collapsed;
  3168. btnImport.IsEnabled = true;
  3169. ImgScreenRecording.Visibility = Visibility.Visible;
  3170. ImgScreenRecordingTwo.Visibility = Visibility.Collapsed;
  3171. btnScreenRecording.IsEnabled = true;
  3172. ImgUpload.Visibility = Visibility.Visible;
  3173. ImgUploadTwo.Visibility = Visibility.Collapsed;
  3174. btnUpload.IsEnabled = true;
  3175. ImgSetUp.Visibility = Visibility.Visible;
  3176. ImgSetUpTwo.Visibility = Visibility.Collapsed;
  3177. btnSetUp.IsEnabled = true;
  3178. btnLoginType.IsEnabled = true;
  3179. //btnStop.IsEnabled = false;//停止录制按钮不可点击
  3180. #endregion
  3181. IsSuspendR = true;
  3182. ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
  3183. ImgStop.Visibility = Visibility.Visible;
  3184. ImgStopTwo.Visibility = Visibility.Collapsed;
  3185. //TimeOut();
  3186. try
  3187. {
  3188. #region 清空画板数据
  3189. APP.pageData.currpage = 0;
  3190. APP.pageData.pagenum = 0;
  3191. myblackboard.clear();
  3192. //myblackboard = new BlackboardNew(blackboard_canvas);
  3193. //DataContext = APP.pageData;
  3194. //drawingAttributes = new DrawingAttributes();
  3195. ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  3196. ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  3197. //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  3198. //blackboard_canvas.UseCustomCursor = true;
  3199. //drawingAttributes.FitToCurve = true;
  3200. //drawingAttributes.IgnorePressure = false;
  3201. //drawingAttributes.Width = PenSize;
  3202. //drawingAttributes.Height = PenSize;
  3203. //drawingAttributes.Color = Color;
  3204. //blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
  3205. APP.PageDrawList.Clear();
  3206. imgCanvas.Source = null;
  3207. imgDocumentation.Source = null;
  3208. imgPPT.Source = null;
  3209. gridPage.Visibility = Visibility.Collapsed;
  3210. #endregion
  3211. //根据录制时间长度确定是否保存
  3212. if (SRTime.Hour > 0 || SRTime.Minute > 0 || SRTime.Second > 3)
  3213. {
  3214. #region 2秒内不可点击
  3215. new Thread(new ThreadStart(new Action(() =>
  3216. {
  3217. Dispatcher.Invoke(() =>
  3218. {
  3219. BtnRecord.IsEnabled = false;
  3220. btnStop.IsEnabled = false;
  3221. });
  3222. }))).Start();
  3223. #endregion
  3224. //缩略图
  3225. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  3226. FileToolsCommon.CreateDirectory(ThumbnailPath);
  3227. //缩略图存储位置
  3228. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  3229. APP.FFmpeg.StopFFmpeg(AudioPathName);
  3230. new Thread(new ThreadStart(new Action(() =>
  3231. {
  3232. IsStartCount = false;
  3233. //停止截图
  3234. while (APP.FFmpeg.myProcess != null)
  3235. {
  3236. Thread.Sleep(100);
  3237. }
  3238. Dispatcher.Invoke(() =>
  3239. {
  3240. timer.Change(-1, 0);
  3241. timer.Dispose();
  3242. //End();
  3243. txbTime.Text = "";
  3244. txbTime.Visibility = Visibility.Hidden;
  3245. txbType.Visibility = Visibility.Visible;
  3246. txbType.Text = "保存中";
  3247. });
  3248. //}))).Start();
  3249. //new Thread(new ThreadStart(new Action(() =>
  3250. //{
  3251. //判断音频是否存在 判断音频临时文件夹是否存在
  3252. if (IsRecordAudio)
  3253. {
  3254. if (!FileToolsCommon.IsExistFile(AudioPathName))
  3255. {
  3256. Thread.Sleep(100);
  3257. }
  3258. if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
  3259. {
  3260. Thread.Sleep(100);
  3261. }
  3262. }
  3263. else
  3264. {
  3265. //没有录制音频
  3266. AudioPathName = null;
  3267. }
  3268. //合成视频
  3269. bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight, out string ErrMessage);
  3270. //}))).Start();
  3271. //new Thread(new ThreadStart(new Action(() =>
  3272. //{
  3273. if (!SynRes)
  3274. {
  3275. Dispatcher.Invoke(() =>
  3276. {
  3277. //MessageWindow.Show("视频录制失败,无法保存此视频!");
  3278. MessageWindow.Show("录制失败," + ErrMessage);
  3279. BtnRecord.IsEnabled = true;
  3280. btnStop.IsEnabled = true;
  3281. TxbRecordingWord.Text = "录制";
  3282. txbType.Text = "";
  3283. });
  3284. return;
  3285. }
  3286. Dispatcher.Invoke(() =>
  3287. {
  3288. txbType.Text = "转码中";
  3289. });
  3290. while (!FileToolsCommon.IsExistFile(VideoSynthesisPathName))
  3291. {
  3292. Thread.Sleep(100);
  3293. }
  3294. while (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(VideoSynthesisPathName) + "temp/"))
  3295. {
  3296. Thread.Sleep(100);
  3297. }
  3298. FileToolsCommon.DeleteFile(ThumbnailPathName);
  3299. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  3300. Thread.Sleep(500);
  3301. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  3302. VideoInfo.VideoPath = VideoSavePathName;
  3303. VideoInfo.ThumbnailPath = ThumbnailPathName;
  3304. //生成缩略图
  3305. bool ThuRes = APP.FFmpeg.GenerateThumbnails(VideoSynthesisPathName, ThumbnailPathName, 200, 130);
  3306. Thread.Sleep(500);
  3307. //if (ThuRes)
  3308. //{
  3309. // Bitmap bmp = ImageHelper.ReadBitmapFile(ThumbnailPathName);
  3310. // if (bmp != null)
  3311. // {
  3312. // imgW = bmp.Width + (bmp.Width % 2 > 0 ? 1 : 0);
  3313. // imgH = bmp.Height + (bmp.Height % 2 > 0 ? 1 : 0);
  3314. // }
  3315. //}
  3316. APP.FFmpeg.VideoTranscode(VideoSynthesisPathName, VideoSavePathName, gridActWidth, gridActHeight);
  3317. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  3318. VideoInfo.IsUpload = false;
  3319. VideoInfo.Uploaded = 0;
  3320. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  3321. APP.VideoList.Add(VideoInfo);
  3322. //保存数据
  3323. APP.SaveWkData();
  3324. IsFirstR = true;
  3325. Dispatcher.Invoke(() =>
  3326. {
  3327. BtnRecord.IsEnabled = true;
  3328. btnStop.IsEnabled = true;
  3329. TxbRecordingWord.Text = "录制";
  3330. txbType.Text = "";
  3331. });
  3332. }))).Start();
  3333. }
  3334. else
  3335. {
  3336. APP.FFmpeg.SuspendFFmpeg();
  3337. IsStartCount = false;
  3338. timer.Change(-1, 0);
  3339. timer.Dispose();
  3340. IsFirstR = true;
  3341. BtnRecord.IsEnabled = true;
  3342. btnStop.IsEnabled = true;
  3343. TxbRecordingWord.Text = "录制";
  3344. txbType.Text = "";
  3345. MessageWindow.Show("录制时间过短,请重新录制!");
  3346. Dispatcher.Invoke(() =>
  3347. {
  3348. txbTime.Text = "";
  3349. txbTime.Visibility = Visibility.Hidden;
  3350. });
  3351. }
  3352. //List<Model_Video> VideoList
  3353. }
  3354. catch (Exception ex)
  3355. {
  3356. MessageWindow.Show(ex.Message);
  3357. }
  3358. }
  3359. }
  3360. #endregion
  3361. /// <summary>
  3362. /// 登陆事件
  3363. /// </summary>
  3364. /// <param name="sender"></param>
  3365. /// <param name="e"></param>
  3366. private void BtnLoginType_Click(object sender, RoutedEventArgs e)
  3367. {
  3368. if ("未登录".Equals(txbLoginType.Text))
  3369. {
  3370. Login();
  3371. }
  3372. else
  3373. {
  3374. MessageBoxResult dr = MessageWindow.Show("确定退出登陆?", "提示", MessageBoxButton.OKCancel);
  3375. if (dr == MessageBoxResult.OK)
  3376. {
  3377. LoginType();
  3378. Login();
  3379. }
  3380. }
  3381. }
  3382. /// <summary>
  3383. /// 登陆
  3384. /// </summary>
  3385. private void Login()
  3386. {
  3387. if (APP.W_LoginWindow == null)
  3388. {
  3389. APP.W_LoginWindow = new LoginWindow
  3390. {
  3391. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  3392. Owner = this
  3393. };
  3394. }
  3395. else
  3396. {
  3397. APP.W_LoginWindow.Initialize();
  3398. }
  3399. APP.W_LoginWindow.ShowDialog();
  3400. if (APP.IsLoginType)
  3401. {
  3402. txbLoginType.Text = APP.UserInfo.Username;
  3403. //ImgUpload.Visibility = Visibility.Visible;
  3404. //ImgUploadTwo.Visibility = Visibility.Collapsed;
  3405. }
  3406. else
  3407. {
  3408. txbLoginType.Text = "未登录";
  3409. //ImgUpload.Visibility = Visibility.Collapsed;
  3410. //ImgUploadTwo.Visibility = Visibility.Visible;
  3411. }
  3412. }
  3413. /// <summary>
  3414. /// 状态更改为未登陆
  3415. /// </summary>
  3416. private void LoginType()
  3417. {
  3418. APP.IsLoginType = false;
  3419. txbLoginType.Text = "未登录";
  3420. APP.UserInfo = new Model_UserInfo();
  3421. //ImgUpload.Visibility = Visibility.Collapsed;
  3422. //ImgUploadTwo.Visibility = Visibility.Visible;
  3423. }
  3424. /// <summary>
  3425. /// 获取时间戳
  3426. /// </summary>
  3427. /// <returns></returns>
  3428. public string GetTimeStamp()
  3429. {
  3430. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3431. return Convert.ToInt64(ts.TotalSeconds).ToString();
  3432. }
  3433. /// <summary>
  3434. /// 返回一个时间戳到毫秒
  3435. /// </summary>
  3436. /// <returns></returns>
  3437. public static long Timestamp()
  3438. {
  3439. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  3440. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  3441. return timestr;
  3442. }
  3443. /// <summary>
  3444. /// 增加事件
  3445. /// </summary>
  3446. /// <param name="sender"></param>
  3447. /// <param name="e"></param>
  3448. private void BtnAdd_Click(object sender, RoutedEventArgs e)
  3449. {
  3450. Record();
  3451. if (APP.pageData.currpage > 0)
  3452. {
  3453. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3454. }
  3455. if (IsStartCount && blackboard_canvas.Visibility == Visibility.Collapsed)
  3456. {
  3457. blackboard_canvas.Visibility = Visibility.Visible;
  3458. }
  3459. APP.pageData.pagenum += 1;
  3460. HideAngleBorder();
  3461. gridPage.Visibility = Visibility.Visible;//页码大于0 显示
  3462. APP.pageData.currpage = APP.pageData.pagenum;
  3463. myblackboard.changepage(APP.pageData.currpage - 1);
  3464. scroMain.ScrollToVerticalOffset(0);
  3465. ///清空页面图片UI
  3466. imgCanvas.Source = null;
  3467. imgDocumentation.Source = null;
  3468. imgPPT.Source = null;
  3469. if (APP.pageData.pagenum == 1)
  3470. {
  3471. APP.PageDrawList = new List<Model_DrawData>();
  3472. }
  3473. ///画板模型增加一页
  3474. Model_DrawData model_DrawData = new Model_DrawData
  3475. {
  3476. PageNum = APP.pageData.currpage
  3477. };
  3478. APP.PageDrawList.Add(model_DrawData);
  3479. ImgPrint.Visibility = Visibility.Visible;//可打印
  3480. ImgPrintTwo.Visibility = Visibility.Collapsed;
  3481. btnPrint.IsEnabled = true;
  3482. //APP.SaveDraw();
  3483. if (btnImport.IsEnabled == true)
  3484. {
  3485. ///截图可用
  3486. ImgScreenshot.Visibility = Visibility.Visible;
  3487. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3488. btnScreenshot.IsEnabled = true;
  3489. }
  3490. #region 插入页码
  3491. PageData = new List<PageData>();
  3492. for (int i = 1; i <= APP.pageData.pagenum; i++)
  3493. {
  3494. PageData pd = new PageData();
  3495. pd.PageName = i.ToString();// + "页";
  3496. pd.PageCode = i;
  3497. PageData.Add(pd);
  3498. }
  3499. CbxPageList.ItemsSource = PageData;
  3500. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  3501. #endregion
  3502. }
  3503. /// <summary>
  3504. /// 打印事件
  3505. /// </summary>
  3506. /// <param name="sender"></param>
  3507. /// <param name="e"></param>
  3508. private void BtnPrint_Click(object sender, RoutedEventArgs e)
  3509. {
  3510. try
  3511. {
  3512. //3种情况 1.文档图片 2.截图图片 3.没有图片
  3513. if (APP.PageDrawList.Count == 0)
  3514. {
  3515. MessageWindow.Show("没有可打印的页,您可以通过加页、截图或导入来增加页!");
  3516. return;
  3517. }
  3518. //iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);
  3519. ////iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
  3520. //////设置纸张横向
  3521. ////document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
  3522. //string imgPath = FileToolsCommon.GetFileAbsolutePath("temp/");
  3523. //FileToolsCommon.CreateDirectory(imgPath);
  3524. //imgPath += "101.pdf";
  3525. //iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(imgPath, FileMode.Create, FileAccess.ReadWrite));
  3526. //document.Open();
  3527. //iTextSharp.text.Image image;
  3528. //for (int i = 0; i < APP.PageDrawList.Count; i++)
  3529. //{
  3530. // long ii = Timestamp();
  3531. // string directoryPath = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
  3532. // string filePathOutPut = Path.Combine(directoryPath, string.Format("print{0}{1}.jpg", ii, i));
  3533. // RectangleF rectangleFs = new RectangleF();
  3534. // MergerImg("", filePathOutPut, rectangleFs, out string errmsg);
  3535. // image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3536. // if (string.IsNullOrEmpty(APP.PageDrawList[i].PageImagePath))//没有图片
  3537. // {
  3538. // }
  3539. // else if (APP.PageDrawList[i].ImgDocumentation == true&& !APP.PageDrawList[i].Type.Equals("ppt"))
  3540. // {
  3541. // image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3542. // }
  3543. // else
  3544. // {
  3545. // RectangleF rectangleF = new RectangleF
  3546. // {
  3547. // Width = (float)APP.PageDrawList[i].ImageSizes.CenterX,
  3548. // Height = (float)APP.PageDrawList[i].ImageSizes.CenterY,
  3549. // X = (float)APP.PageDrawList[i].ImageLocation.X,
  3550. // Y = (float)APP.PageDrawList[i].ImageLocation.Y
  3551. // };
  3552. // string msg = string.Empty;
  3553. // bool isImg = MergerImg(APP.PageDrawList[i].PageImagePath, filePathOutPut, rectangleF, out msg);
  3554. // if (isImg)
  3555. // {
  3556. // image = iTextSharp.text.Image.GetInstance(filePathOutPut);
  3557. // }
  3558. // else
  3559. // {
  3560. // image = iTextSharp.text.Image.GetInstance(APP.PageDrawList[i].PageImagePath);
  3561. // }
  3562. // }
  3563. // if (image.Height > iTextSharp.text.PageSize.A4.Height)
  3564. // {
  3565. // image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3566. // }
  3567. // else if (image.Width > iTextSharp.text.PageSize.A4.Width)
  3568. // {
  3569. // image.ScaleToFit(iTextSharp.text.PageSize.A4.Width, iTextSharp.text.PageSize.A4.Height);
  3570. // }
  3571. // image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
  3572. // document.NewPage();
  3573. // document.Add(image);
  3574. // //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
  3575. // //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
  3576. // //p1.Leading = 150; //行间距
  3577. // //document.Add(p1);
  3578. //}
  3579. //Console.WriteLine("转换成功!");
  3580. //document.Close();
  3581. }
  3582. catch (Exception ex)
  3583. {
  3584. MessageWindow.Show(ex.Message);
  3585. Console.WriteLine("转换失败,原因:" + ex.Message);
  3586. }
  3587. //document.Close();
  3588. ////Console.ReadKey();
  3589. if (APP.W_PrintWindow == null)
  3590. {
  3591. APP.W_PrintWindow = new PrintWindow
  3592. {
  3593. //APP.W_PrintWindow.Topmost = true;
  3594. Owner = this
  3595. };
  3596. }
  3597. if (APP.PageDrawList.Count > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[0].PageImagePath))
  3598. {
  3599. APP.W_PrintWindow.Initialize(APP.PageDrawList[0].PageImagePath, gridM.ActualWidth, gridM.ActualHeight);
  3600. }
  3601. else
  3602. {
  3603. APP.W_PrintWindow.Initialize("", gridM.ActualWidth, gridActHeight);
  3604. }
  3605. APP.W_PrintWindow.ShowDialog();
  3606. //int pr = 1;
  3607. //string msg = string.Empty;
  3608. //string outPut = string.Empty;
  3609. //LatticeFileHelper.GeneratingPDF(@"G:\101.pdf", @"G:\102.TPF",out pr, out msg, out outPut);
  3610. //if(pr==0)
  3611. //{
  3612. // outPut = outPut.Replace("[", "").Replace("]","").Replace("\"","").Trim();
  3613. // APP.OutPut = outPut.Split(',');
  3614. // string defa = string.Empty;
  3615. // List<string>defaList= LatticeFileHelper.GetPrinterList(out defa);
  3616. // int printResult = 1;
  3617. // string standardError = string.Empty;
  3618. // string standardOutput = string.Empty;
  3619. // LatticeFileHelper.PrinterTPFFile(@"G:\102.TPF",1, /*defa*/"导出为WPS PDF", out printResult,out standardError,out standardOutput);
  3620. //}
  3621. }
  3622. /// 上一页
  3623. /// </summary>
  3624. /// <param name="sender"></param>
  3625. /// <param name="e"></param>
  3626. private void last_button_Click(object sender, RoutedEventArgs e)
  3627. {
  3628. if (APP.pageData.currpage > 1)
  3629. {
  3630. mouseDown = false;
  3631. HideAngleBorder();
  3632. //隐藏跳转
  3633. //txbCurrpage.Visibility = Visibility.Visible;
  3634. //txtJump.Visibility = Visibility.Hidden;
  3635. //BtnJumpPage.Visibility = Visibility.Hidden;
  3636. //if(!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3637. //{
  3638. // ImgWG();
  3639. //}
  3640. APP.pageData.currpage -= 1;
  3641. JumpPageClick();
  3642. }
  3643. }
  3644. /// <summary>
  3645. /// 跳转
  3646. /// </summary>
  3647. void JumpPageClick()
  3648. {
  3649. myblackboard.changepage(APP.pageData.currpage - 1);
  3650. scroMain.ScrollToVerticalOffset(0);
  3651. if (btnImport.IsEnabled == true)
  3652. {
  3653. ///截图可用
  3654. ImgScreenshot.Visibility = Visibility.Visible;
  3655. ImgScreenshotTwo.Visibility = Visibility.Collapsed;
  3656. btnScreenshot.IsEnabled = true;
  3657. }
  3658. if (APP.pageData.currpage <= APP.PageDrawList.Count)
  3659. {
  3660. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null)
  3661. {
  3662. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = true;
  3663. }
  3664. if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  3665. {
  3666. if (APP.PageDrawList[APP.pageData.currpage - 1].ImgDocumentation)
  3667. {
  3668. if ("ppt".Equals(APP.PageDrawList[APP.pageData.currpage - 1].Type))
  3669. {
  3670. imgCanvas.Source = null;
  3671. imgDocumentation.Source = null;
  3672. imgPPT.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3673. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3674. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3675. btnScreenshot.IsEnabled = false;
  3676. }
  3677. else
  3678. {
  3679. imgPPT.Source = null;
  3680. imgCanvas.Source = null;
  3681. imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3682. ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3683. ImgScreenshotTwo.Visibility = Visibility.Visible;
  3684. btnScreenshot.IsEnabled = false;
  3685. }
  3686. //imgCanvas.Source = null;
  3687. //imgDocumentation.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3688. //ImgScreenshot.Visibility = Visibility.Collapsed;//当前页为导入时不可截图
  3689. //ImgScreenshotTwo.Visibility = Visibility.Visible;
  3690. //btnScreenshot.IsEnabled = false;
  3691. }
  3692. else
  3693. {
  3694. imgPPT.Source = null;
  3695. imgDocumentation.Source = null;
  3696. imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  3697. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3698. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X > 0)
  3699. {
  3700. //var group = IMG.FindResource("Imageview") as TransformGroup;
  3701. //#region 高低 缩放比例
  3702. //if (APP.PageDrawList[APP.pageData.currpage - 1].ImageSize != null)
  3703. //{
  3704. // var transform1 = group.Children[0] as ScaleTransform;
  3705. // transform1.ScaleX = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX;
  3706. // transform1.ScaleY = APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY;
  3707. // imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  3708. // imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  3709. //}
  3710. //#endregion
  3711. //#region 坐标XY轴
  3712. //var transform = group.Children[1] as TranslateTransform;
  3713. //transform.X = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  3714. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  3715. //#endregion
  3716. mouseDown = false;
  3717. ImgXY();
  3718. }
  3719. }
  3720. }
  3721. else
  3722. {
  3723. imgPPT.Source = null;
  3724. imgCanvas.Source = null;
  3725. imgDocumentation.Source = null;
  3726. }
  3727. #region 修改跳转页码
  3728. CbxPageList.SelectedIndex = APP.pageData.currpage - 1;
  3729. #endregion
  3730. }
  3731. }
  3732. private void ImgXY()
  3733. {
  3734. imgCanvas.Width = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterX;
  3735. imgCanvas.Height = APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes.CenterY;
  3736. imgCanvas.Margin = new Thickness(APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X, APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y, 0, 0);
  3737. //imgCanvas.Margin.Left= APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.X;
  3738. //transform.Y = APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation.Y;
  3739. }
  3740. private void ImgWG()
  3741. {
  3742. mouseDown = false;
  3743. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3744. {
  3745. X = imgCanvas.Margin.Left,
  3746. Y = imgCanvas.Margin.Top
  3747. };
  3748. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  3749. {
  3750. CenterX = imgCanvas.ActualWidth,
  3751. CenterY = imgCanvas.ActualHeight
  3752. };
  3753. }
  3754. /// <summary>
  3755. /// 下一页
  3756. /// </summary>
  3757. /// <param name="sender"></param>
  3758. /// <param name="e"></param>
  3759. private void next_btn_Click(object sender, RoutedEventArgs e)
  3760. {
  3761. if (APP.pageData.currpage < APP.pageData.pagenum)
  3762. {
  3763. mouseDown = false;
  3764. HideAngleBorder();
  3765. //隐藏跳转
  3766. //txbCurrpage.Visibility = Visibility.Visible;
  3767. //txtJump.Visibility = Visibility.Hidden;
  3768. //BtnJumpPage.Visibility = Visibility.Hidden;
  3769. //if (!APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3770. //{
  3771. // ImgWG();
  3772. //}
  3773. APP.pageData.currpage += 1;
  3774. JumpPageClick();
  3775. }
  3776. }
  3777. /// <summary>
  3778. /// 生成图片
  3779. /// </summary>
  3780. /// <param name="_path">图片地址</param>
  3781. /// <param name="_saveimg">保存位置</param>
  3782. /// <param name="_rectangle">图片位置</param>
  3783. /// <param name="errmsg">错误消息</param>
  3784. /// <returns></returns>
  3785. private bool MergerImg(string _path, string _saveimg, RectangleF _rectangle, out string errmsg)
  3786. {
  3787. errmsg = null;
  3788. try
  3789. {
  3790. Bitmap bitmap = null;
  3791. //创建要显示的图片对象,根据参数的个数设置宽度
  3792. Bitmap backgroudImg = new Bitmap((int)gridM.ActualWidth, (int)gridM.ActualHeight);
  3793. Graphics g = Graphics.FromImage(backgroudImg);
  3794. //清除画布,背景设置为白色
  3795. g.Clear(System.Drawing.Color.White);
  3796. if (!string.IsNullOrWhiteSpace(_path))
  3797. {
  3798. bitmap = ImageHelper.ReadBitmapFile(_path);
  3799. g.DrawImage(bitmap, _rectangle);
  3800. }
  3801. backgroudImg.Save(_saveimg);
  3802. g.Dispose();
  3803. backgroudImg.Dispose();
  3804. if (bitmap != null)
  3805. {
  3806. bitmap.Dispose();
  3807. }
  3808. GC.Collect();
  3809. return true;
  3810. }
  3811. catch (Exception ex)
  3812. {
  3813. errmsg = ex.Message;
  3814. LogHelper.WriteErrLog("【截图合成】(MergerImg)图片合成失败:" + ex.Message, ex);
  3815. return false;
  3816. }
  3817. }
  3818. /// <summary>
  3819. /// 将Word文档转换为图片的方法(该方法基于第三方DLL),你可以像这样调用该方法: ConvertPDF2Image("F:\\PdfFile.doc", "F:\\",
  3820. /// "ImageFile", 1, 20, ImageFormat.Png, 256);
  3821. /// </summary>
  3822. /// <param name="pdfInputPath">Word文件路径</param>
  3823. /// <param name="imageOutputPath">图片输出路径,如果为空,默认值为Word所在路径</param>
  3824. /// <param name="imageName">图片的名字,不需要带扩展名,如果为空,默认值为Word的名称</param>
  3825. /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
  3826. /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
  3827. /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
  3828. /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
  3829. public List<string> ConvertWordToImage(string wordInputPath, string imageOutputPath,
  3830. string imageName, int startPageNum, int endPageNum, ImageFormat imageFormat, float resolution)
  3831. {
  3832. // 返回的图片绝对路径集合
  3833. List<string> images = new List<string>();
  3834. try
  3835. {
  3836. // open word file
  3837. Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);
  3838. // validate parameter
  3839. if (doc == null) { throw new Exception("Word文件无效或者Word文件被加密!"); }
  3840. if (imageOutputPath.Trim().Length == 0) { imageOutputPath = System.IO.Path.GetDirectoryName(wordInputPath); }
  3841. if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }
  3842. if (imageName.Trim().Length == 0) { imageName = System.IO.Path.GetFileNameWithoutExtension(wordInputPath); }
  3843. if (startPageNum <= 0) { startPageNum = 1; }
  3844. if (endPageNum > doc.PageCount || endPageNum <= 0) { endPageNum = doc.PageCount; }
  3845. if (startPageNum > endPageNum) { int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum; }
  3846. if (imageFormat == null) { imageFormat = ImageFormat.Png; }
  3847. if (resolution <= 0) { resolution = 128; }
  3848. ImageSaveOptions imageSaveOptions = new ImageSaveOptions(GetSaveFormat(imageFormat))
  3849. {
  3850. Resolution = resolution
  3851. };
  3852. // start to convert each page
  3853. for (int i = startPageNum; i <= endPageNum; i++)
  3854. {
  3855. imageSaveOptions.PageIndex = i - 1;
  3856. doc.Save(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString(), imageSaveOptions);
  3857. images.Add(System.IO.Path.Combine(imageOutputPath, imageName) + "_" + APP.num.ToString() + "." + imageFormat.ToString());
  3858. APP.num++;
  3859. }
  3860. imageSaveOptions = null;
  3861. doc = null;
  3862. }
  3863. catch (Exception ex)
  3864. {
  3865. //if(ex.Message.ToString().Equals("{\"The document appears to be corrupted and cannot be loaded.\"}"))
  3866. //{
  3867. // MessageWindow.Show("Word文件无效或者Word文件被加密!");
  3868. //}
  3869. //else
  3870. //{
  3871. MessageWindow.Show("该文件无法使用!");
  3872. //}
  3873. LogHelper.WriteErrLog("【导入方法(ConvertWordToImage)】错误日志:" + ex.Message, ex);
  3874. }
  3875. return images;
  3876. }
  3877. private static SaveFormat GetSaveFormat(ImageFormat imageFormat)
  3878. {
  3879. SaveFormat sf;// = SaveFormat.Unknown;
  3880. if (imageFormat.Equals(ImageFormat.Png))
  3881. {
  3882. sf = SaveFormat.Png;
  3883. }
  3884. else if (imageFormat.Equals(ImageFormat.Jpeg))
  3885. {
  3886. sf = SaveFormat.Jpeg;
  3887. }
  3888. else if (imageFormat.Equals(ImageFormat.Tiff))
  3889. {
  3890. sf = SaveFormat.Tiff;
  3891. }
  3892. else if (imageFormat.Equals(ImageFormat.Bmp))
  3893. {
  3894. sf = SaveFormat.Bmp;
  3895. }
  3896. else
  3897. {
  3898. sf = SaveFormat.Unknown;
  3899. }
  3900. return sf;
  3901. }
  3902. #region 图像缩放,移动
  3903. private bool mouseDown;
  3904. private System.Windows.Point mouseXY;
  3905. private void IMG1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  3906. {
  3907. ContentControl img = sender as ContentControl;
  3908. if (img == null)
  3909. {
  3910. return;
  3911. }
  3912. img.CaptureMouse();
  3913. mouseDown = true;
  3914. mouseXY = e.GetPosition(img);
  3915. Console.WriteLine("mouseXY.X = " + mouseXY.X + "; mouseXY.Y = " + mouseXY.Y);
  3916. }
  3917. private void IMG1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  3918. {
  3919. ContentControl img = sender as ContentControl;
  3920. if (img == null)
  3921. {
  3922. return;
  3923. }
  3924. img.ReleaseMouseCapture();
  3925. mouseDown = false;
  3926. }
  3927. private void IMG1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  3928. {
  3929. ContentControl img = sender as ContentControl;
  3930. if (img == null)
  3931. {
  3932. return;
  3933. }
  3934. if (mouseDown)
  3935. {
  3936. Domousemove(img, e);
  3937. }
  3938. }
  3939. /// <summary>
  3940. /// x y轴
  3941. /// </summary>
  3942. /// <param name="img"></param>
  3943. /// <param name="e"></param>
  3944. private void Domousemove(ContentControl img, System.Windows.Input.MouseEventArgs e)
  3945. {
  3946. if (e.LeftButton != MouseButtonState.Pressed)
  3947. {
  3948. return;
  3949. }
  3950. if (APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation != null && APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation)
  3951. {
  3952. return;
  3953. }
  3954. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3955. TranslateTransform transform = group.Children[1] as TranslateTransform;
  3956. System.Windows.Point position = e.GetPosition(img);
  3957. transform.X -= mouseXY.X - position.X;
  3958. transform.Y -= mouseXY.Y - position.Y;
  3959. mouseXY = position;
  3960. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  3961. {
  3962. X = transform.X,
  3963. Y = transform.Y
  3964. };
  3965. //APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  3966. }
  3967. private void IMG1_MouseWheel(object sender, MouseWheelEventArgs e)
  3968. {
  3969. ContentControl img = sender as ContentControl;
  3970. if (img == null)
  3971. {
  3972. return;
  3973. }
  3974. System.Windows.Point point = e.GetPosition(img);
  3975. Console.WriteLine("point.X = " + point.X + "; point.Y=" + point.Y);
  3976. System.Windows.Point PicLocate = e.GetPosition(imgCanvas);
  3977. Console.WriteLine("PicEmap.X = " + PicLocate.X + "; PicEmap.Y=" + PicLocate.Y);
  3978. TransformGroup group = IMG.FindResource("Imageview") as TransformGroup;
  3979. double delta = e.Delta * 0.001;
  3980. DowheelZoom(group, point, delta);
  3981. }
  3982. private void DowheelZoom(TransformGroup group, System.Windows.Point point, double delta)
  3983. {
  3984. System.Windows.Point pointToContent = group.Inverse.Transform(point);
  3985. ScaleTransform transform = group.Children[0] as ScaleTransform;
  3986. if (transform.ScaleX + delta < 0.1)
  3987. {
  3988. return;
  3989. }
  3990. transform.ScaleX += delta;
  3991. transform.ScaleY += delta;
  3992. TranslateTransform transform1 = group.Children[1] as TranslateTransform;
  3993. transform1.X = -1 * ((pointToContent.X * transform.ScaleX) - point.X);
  3994. transform1.Y = -1 * ((pointToContent.Y * transform.ScaleY) - point.Y);
  3995. //LogHelper.WriteInfoLog("【img宽高】" + imgCanvas.ActualWidth.ToString() + ":"
  3996. // + imgCanvas.ActualHeight.ToString() + "百分比:" + transform.ScaleX.ToString() + ":" + transform.ScaleY.ToString()
  3997. // );
  3998. //Console.WriteLine("transform.ScaleX = " + transform.ScaleX + "; transform.ScaleY = " + transform.ScaleY);
  3999. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize = new ScaleTransform();
  4000. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleX = transform.ScaleX;
  4001. //APP.PageDrawList[APP.pageData.currpage - 1].ImageSize.ScaleY = transform.ScaleY;
  4002. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4003. {
  4004. X = transform1.X,
  4005. Y = transform1.Y
  4006. };
  4007. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4008. {
  4009. CenterX = imgCanvas.ActualWidth,
  4010. CenterY = imgCanvas.ActualHeight
  4011. };
  4012. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4013. }
  4014. #endregion
  4015. #region 点阵笔相关
  4016. #region 值初始化
  4017. // 不同尺寸点阵纸点阵宽高尺寸计算方法为:纸张物理尺寸(毫米)/0.3 *8,详见 开发必读.pdf 文档
  4018. /// <summary>
  4019. /// A4点阵纸点阵宽度
  4020. /// </summary>
  4021. private const int A4_WIDTH = 5600;
  4022. /// <summary>
  4023. /// A4点阵纸点阵高度
  4024. /// </summary>
  4025. private const int A4_HEIGHT = 7920;
  4026. ///// <summary>
  4027. ///// 画板
  4028. ///// </summary>
  4029. //private Graphics graphics;
  4030. /// <summary>
  4031. /// 笔画坐标数组
  4032. /// </summary>
  4033. private List<System.Drawing.Point> stroke;
  4034. /// <summary>
  4035. /// 笔序列号
  4036. /// </summary>
  4037. private string penSerial;
  4038. /// <summary>
  4039. /// 笔是否在点
  4040. /// </summary>
  4041. private bool isPenDown;
  4042. //当前点阵地址
  4043. private string currentPageSerial = string.Empty;
  4044. //不同点阵地址对应的笔迹绘制图片,用于实现在不同点阵地址书写切换时,显示书写内容自动切换
  4045. //本例图片放在内存中存储,对于大量或者需要在多个点阵地址对应图片进行切换演示,建议将图片存储到文件,以免内存溢出
  4046. private Dictionary<string, System.Drawing.Image> pagesDic = new Dictionary<string, System.Drawing.Image>();
  4047. #endregion
  4048. public void InitPen()
  4049. {
  4050. stroke = new List<System.Drawing.Point>();
  4051. //获取点阵笔实例,并绑定点阵笔事件
  4052. //将授权文件内容传入,获取点阵笔对象实例
  4053. APP.digitalPen = DigitalPenHID.GetInstance(certificates.MyLicense.Bytes);
  4054. //绑定笔连接事件
  4055. APP.digitalPen.PenConnected += OnPenConnect;
  4056. //绑定笔断开事件
  4057. APP.digitalPen.PenDisconnect += OnPenDisconnect;
  4058. //绑定笔书写输出坐标事件
  4059. APP.digitalPen.PenCoordinate += OnPenCoordinate;
  4060. //绑定抬笔事件
  4061. APP.digitalPen.PenUp += OnPenUp;
  4062. //绑定落笔事件
  4063. APP.digitalPen.PenDown += OnPenDown;
  4064. APP.digitalPen.PenBatteryCapacity += OnBatteryCapacity;
  4065. APP.digitalPen.PenMemoryFillLevel += OnMemoryFillLevel;
  4066. //完成初始化点阵笔,开始与点阵笔通信
  4067. ERROR_CODE ER = APP.digitalPen.Start();
  4068. ////绑定笔在新的点阵地址页面书写事件
  4069. //APP.digitalPen.PenNewPage += APP.digitalPen_OnPenNewPage;
  4070. ////绑定笔信息事件
  4071. //APP.digitalPen.PenInfo += APP.digitalPen_OnPenInfo;
  4072. //启动接收笔数据,完成初始化工作
  4073. ERROR_CODE rc = APP.digitalPen.Start();
  4074. //判断是否成功
  4075. if (ER != ERROR_CODE.ERROR_OK)
  4076. {
  4077. MessageWindow.Show("初始化失败,授权过期,返回值:" + ER.ToString());
  4078. }
  4079. }
  4080. /// <summary>
  4081. /// 落笔
  4082. /// </summary>
  4083. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4084. /// <param name="penSerial">点阵笔序列号</param>
  4085. /// <param name="penType">点阵笔型号编号</param>
  4086. private void OnPenDown(ulong time, string penSerial, int penType)
  4087. {
  4088. if (CheckAccess())
  4089. {
  4090. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDown);
  4091. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4092. }
  4093. else
  4094. {
  4095. //labPenSerial.Text = penSerial;
  4096. //labPenStatus.Text = "PenDown";
  4097. isPenDown = true;
  4098. //Dispatcher.Invoke(new Action(() =>
  4099. //{
  4100. // for (int i = 0; i < APP.PageDrawList.Count; i++)
  4101. // {
  4102. // if (APP.PageDrawList[i].PageCode == penSerial)
  4103. // {
  4104. // if (i < APP.pageData.pagenum)
  4105. // {
  4106. // if (i < APP.pageData.currpage)
  4107. // {
  4108. // int num = APP.pageData.currpage - i;
  4109. // APP.pageData.currpage -= num;
  4110. // myblackboard.changepage(APP.pageData.currpage - 1);
  4111. // if (APP.PageDrawList.Count > 0)
  4112. // {
  4113. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && APP.pageData.currpage > 0 && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4114. // {
  4115. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));//cs
  4116. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4117. // }
  4118. // else
  4119. // {
  4120. // imgCanvas.Source = null;
  4121. // }
  4122. // }
  4123. // }
  4124. // else
  4125. // {
  4126. // int num = i - APP.pageData.currpage;
  4127. // APP.pageData.currpage += num;
  4128. // myblackboard.changepage(APP.pageData.currpage - 1);
  4129. // if (APP.PageDrawList.Count > 0)
  4130. // {
  4131. // if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.PageDrawList.Count && !string.IsNullOrWhiteSpace(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath))
  4132. // {
  4133. // //imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
  4134. // imgCanvas.Source = new BitmapImage(new Uri(APP.PageDrawList[APP.pageData.currpage - 1].PageImagePath));
  4135. // }
  4136. // else
  4137. // {
  4138. // imgCanvas.Source = null;
  4139. // }
  4140. // }
  4141. // }
  4142. // }
  4143. // return;
  4144. // }
  4145. // }
  4146. // //myblackboard.changepages(0, 0, true);
  4147. // //myblackboard.changepaget(0, 0, true, blackboard_canvas);
  4148. //}));
  4149. }
  4150. //myblackboard.changepages(0, 0, true);
  4151. }
  4152. /// <summary>
  4153. /// 抬笔
  4154. /// </summary>
  4155. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4156. /// <param name="penSerial">点阵笔序列号</param>
  4157. /// <param name="penType">点阵笔型号编号</param>
  4158. private void OnPenUp(ulong time, string penSerial, int penType)
  4159. {
  4160. if (CheckAccess())
  4161. {
  4162. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenUp);
  4163. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4164. }
  4165. else
  4166. {
  4167. isPenDown = false;
  4168. APP.PenSerial = penSerial;
  4169. //int leftPoints = stroke.Count % 3;
  4170. //if (0 != leftPoints)
  4171. //{
  4172. // int from = stroke.Count - leftPoints - 1;
  4173. // if (from < 0)
  4174. // from = 0;
  4175. // int to = stroke.Count - 1;
  4176. // DrawCoordinates(from, to);
  4177. //}
  4178. stroke.Clear();
  4179. }
  4180. if (APP.pageData.currpage > 0)
  4181. {
  4182. Dispatcher.Invoke(new Action(() =>
  4183. {
  4184. myblackboard.changepages(0, 0, true, Color, PenSize, APP.pageData.currpage - 1);
  4185. }));
  4186. }
  4187. }
  4188. /// <summary>
  4189. /// 笔断开
  4190. /// </summary>
  4191. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4192. /// <param name="penSerial">点阵笔序列号</param>
  4193. /// <param name="penType">点阵笔型号编号</param>
  4194. private void OnPenDisconnect(ulong time, string penSerial, int penType)
  4195. {
  4196. if (CheckAccess())
  4197. {
  4198. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenDisconnect);
  4199. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4200. }
  4201. else
  4202. {
  4203. APP.PenSerial = penSerial;
  4204. APP.PenStatus = false;
  4205. Dispatcher.Invoke(new Action(() =>
  4206. {
  4207. txbNotConnected.Text = "未连接";
  4208. txbNotConnecteds.Text = "未连接";
  4209. }));
  4210. }
  4211. }
  4212. /// <summary>
  4213. /// 笔连接
  4214. /// </summary>
  4215. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4216. /// <param name="penSerial">点阵笔序列号</param>
  4217. /// <param name="penType">点阵笔型号编号</param>
  4218. private void OnPenConnect(ulong time, string penSerial, int penType)
  4219. {
  4220. if (CheckAccess())
  4221. {
  4222. Action<ulong, string, int> action = new Action<ulong, string, int>(OnPenConnect);
  4223. Dispatcher.Invoke(action, new object[] { time, penSerial, penType });
  4224. }
  4225. else
  4226. {
  4227. APP.PenSerial = penSerial;
  4228. APP.PenStatus = true;
  4229. this.penSerial = penSerial;
  4230. //连接后,在获取笔数据前,可以清除笔内的历史数据
  4231. //APP.digitalPen.ClearMemory(penSerial);
  4232. //开始接收笔数据
  4233. APP.digitalPen.GetPenData(penSerial);
  4234. Dispatcher.Invoke(new Action(() =>
  4235. {
  4236. txbNotConnected.Text = "已连接";
  4237. txbNotConnecteds.Text = "已连接";
  4238. }));
  4239. }
  4240. }
  4241. /// <summary>
  4242. /// 电池电量
  4243. /// </summary>
  4244. /// <param name="time"></param>
  4245. /// <param name="penSerial"></param>
  4246. /// <param name="penType"></param>
  4247. /// <param name="capacity"></param>
  4248. private void OnBatteryCapacity(ulong time, string penSerial, int penType, byte capacity)
  4249. {
  4250. if (CheckAccess())
  4251. {
  4252. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnBatteryCapacity);
  4253. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, capacity });
  4254. }
  4255. else
  4256. {
  4257. //System.Windows.MessageWindow.Show("电池电量:" + capacity.ToString());
  4258. }
  4259. }
  4260. /// <summary>
  4261. /// 已用存储
  4262. /// </summary>
  4263. /// <param name="time"></param>
  4264. /// <param name="penSerial"></param>
  4265. /// <param name="penType"></param>
  4266. /// <param name="fillLevel"></param>
  4267. private void OnMemoryFillLevel(ulong time, string penSerial, int penType, byte fillLevel)
  4268. {
  4269. if (CheckAccess())
  4270. {
  4271. Action<ulong, string, int, byte> action = new Action<ulong, string, int, byte>(OnMemoryFillLevel);
  4272. Dispatcher.Invoke(action, new object[] { time, penSerial, penType, fillLevel });
  4273. }
  4274. else
  4275. {
  4276. //System.Windows.MessageWindow.Show("存储:" + fillLevel.ToString());
  4277. }
  4278. }
  4279. /// <summary>
  4280. /// 笔书写,收到坐标
  4281. /// </summary>
  4282. /// <param name="time">时间戳,1970年1月1日到现在的总毫秒数</param>
  4283. /// <param name="penSerial">点阵笔序列号</param>
  4284. /// <param name="penType">点阵笔型号编号</param>
  4285. /// <param name="pageSerial">点阵地址</param>
  4286. /// <param name="cx">x坐标</param>
  4287. /// <param name="cy">y坐标</param>
  4288. /// <param name="force">压力值</param>
  4289. private void OnPenCoordinate(ulong time, string penSerial, int penType, string pageSerial, int cx, int cy, byte force)
  4290. {
  4291. if (CheckAccess())
  4292. {
  4293. Action<ulong, string, int, string, int, int, byte> ac = new Action<ulong, string, int, string, int, int, byte>(OnPenCoordinate);
  4294. Dispatcher.Invoke(ac, new object[] { time, pageSerial, penType, pageSerial, cx, cy, force });
  4295. }
  4296. else
  4297. {
  4298. //判断是否是落笔后输出的坐标,在设置悬浮模式下,落笔前的悬浮坐标不绘制
  4299. if (!isPenDown)
  4300. {
  4301. return;
  4302. }
  4303. stroke.Add(new System.Drawing.Point(cx, cy));
  4304. double PropW = blackboard_canvas.ActualWidth / A4_WIDTH;
  4305. double PropH = blackboard_canvas.ActualHeight / A4_HEIGHT;
  4306. //点
  4307. double testX = cx * PropW;
  4308. double testY = cy * PropH;
  4309. //pageSerial //点阵IP地址 与打印的页面关联
  4310. if (APP.pageData.currpage > 0)
  4311. {
  4312. Dispatcher.Invoke(new Action(() =>
  4313. {
  4314. //myblackboard.changepages(testX, testY,false);
  4315. myblackboard.changepages(testX, testY, false, Color, PenSize, APP.pageData.currpage - 1);
  4316. #region 设置滚动条位置
  4317. //点在显示页面上方
  4318. if (testY < scroMain.VerticalOffset)
  4319. {
  4320. //滚动条当前位置
  4321. double RollCurrentLocation = scroMain.VerticalOffset;
  4322. //向上滚动至以点为中心需要滚动的距离
  4323. double UpRoll = (RollCurrentLocation - testY) + (scroMain.ActualHeight / 2);
  4324. //如果小于0则等于0
  4325. double RollLocation = RollCurrentLocation - UpRoll;
  4326. if (RollLocation < 0)
  4327. {
  4328. RollLocation = 0;
  4329. }
  4330. ////滚动条实际偏移量
  4331. //double RollOffset = RollCurrentLocation - RollLocation;
  4332. scroMain.ScrollToVerticalOffset(RollLocation);
  4333. }
  4334. //点在显示页面下方
  4335. if (testY > scroMain.VerticalOffset + scroMain.ActualHeight)
  4336. {
  4337. //滚动条当前位置
  4338. double RollCurrentLocation = scroMain.VerticalOffset;
  4339. //向下滚动至以点为中心需要滚动的距离
  4340. double DownRoll = (testY - RollCurrentLocation) - (scroMain.ActualHeight / 2);
  4341. //如果小于0则等于0
  4342. double RollLocation = RollCurrentLocation + DownRoll;
  4343. //滚动条最大滚动值
  4344. double ScrollbarMaxNum = gridM.ActualHeight - scroMain.ActualHeight;
  4345. if (RollLocation > ScrollbarMaxNum)
  4346. {
  4347. RollLocation = ScrollbarMaxNum;
  4348. }
  4349. ////滚动条实际偏移量
  4350. //double RollOffset = RollLocation-RollCurrentLocation;
  4351. scroMain.ScrollToVerticalOffset(RollLocation);
  4352. }
  4353. #endregion
  4354. //gridM.Height //A4高度
  4355. //scroMain.VerticalOffset;//获取滚动条位置
  4356. //scroMain.ActualHeight//A4纸显示高度
  4357. //scroMain.ScrollToHorizontalOffset()//设置滚动条位置
  4358. //Mouse.GetPosition(this)
  4359. if (testX > 0 && testY > 0)
  4360. {
  4361. //System.Windows.Point getP = blackboard_canvas.PointToScreen(new System.Windows.Point(testX, testY));
  4362. System.Windows.Point getP = scroMain.PointToScreen(new System.Windows.Point(testX, testY - scroMain.VerticalOffset));
  4363. SetCursorPos((int)getP.X, (int)getP.Y);
  4364. }
  4365. }));
  4366. }
  4367. ////每3个点画一条曲线
  4368. //if (stroke.Count % 3 == 0)
  4369. //{
  4370. // int from = stroke.Count - 3 - 1;
  4371. // if (from < 0)
  4372. // from = 0;
  4373. // int to = stroke.Count - 1;
  4374. // DrawCoordinates(from, to);
  4375. //}
  4376. }
  4377. }
  4378. /// <summary>
  4379. /// 停止笔
  4380. /// </summary>
  4381. public void StopDigitalPen()
  4382. {
  4383. //停止,释放资源
  4384. APP.digitalPen.Stop();
  4385. }
  4386. /// <summary>
  4387. /// 清空笔内存储
  4388. /// </summary>
  4389. public void ClearPenStorage()
  4390. {
  4391. if (!string.IsNullOrEmpty(penSerial))
  4392. {
  4393. APP.digitalPen.ClearMemory(penSerial);
  4394. }
  4395. }
  4396. /// <summary>
  4397. /// 获取剩余电量
  4398. /// </summary>
  4399. public void GetPenElectricityQuantity()
  4400. {
  4401. if (!string.IsNullOrEmpty(penSerial))
  4402. {
  4403. APP.digitalPen.GetBatteryCapacity(penSerial);
  4404. }
  4405. }
  4406. /// <summary>
  4407. /// 获取存储空间
  4408. /// </summary>
  4409. public void GetUsedStorage()
  4410. {
  4411. if (!string.IsNullOrEmpty(penSerial))
  4412. {
  4413. APP.digitalPen.GetMemoryFillLevel(penSerial);
  4414. }
  4415. }
  4416. /// <summary>
  4417. /// 开启悬浮
  4418. /// </summary>
  4419. public void 开启悬浮()
  4420. {
  4421. if (!string.IsNullOrEmpty(penSerial))
  4422. {
  4423. APP.digitalPen.SetPenHoverMode(true, penSerial);
  4424. }
  4425. }
  4426. /// <summary>
  4427. /// 关闭悬浮
  4428. /// </summary>
  4429. public void 关闭悬浮()
  4430. {
  4431. if (!string.IsNullOrEmpty(penSerial))
  4432. {
  4433. APP.digitalPen.SetPenHoverMode(false, penSerial);
  4434. }
  4435. }
  4436. #endregion
  4437. /// <summary>
  4438. /// 最小化
  4439. /// </summary>
  4440. /// <param name="sender"></param>
  4441. /// <param name="e"></param>
  4442. private void BtnShrink_Click(object sender, RoutedEventArgs e)
  4443. {
  4444. if (WindowState == WindowState.Minimized)
  4445. {
  4446. WindowState = WindowState.Normal;
  4447. }
  4448. else
  4449. {
  4450. WindowState = WindowState.Minimized;
  4451. }
  4452. }
  4453. /// <summary>
  4454. /// 引用user32.dll动态链接库(windows api),
  4455. /// 使用库中定义 API:SetCursorPos
  4456. /// 设置光标位置
  4457. /// </summary>
  4458. [System.Runtime.InteropServices.DllImport("user32.dll")]
  4459. private static extern int SetCursorPos(int x, int y);
  4460. #region 图片拉伸移动
  4461. private System.Windows.Point initialPoint;
  4462. /// <summary>
  4463. /// 隐藏图片四个点和线
  4464. /// </summary>
  4465. private void HideAngleBorder()
  4466. {
  4467. RectLeftUp.Visibility = Visibility.Hidden;
  4468. RectRightUp.Visibility = Visibility.Hidden;
  4469. RectLeftDown.Visibility = Visibility.Hidden;
  4470. RectRightDown.Visibility = Visibility.Hidden;
  4471. RectImgBorder.Visibility = Visibility.Hidden;
  4472. }
  4473. private void ShowAngleBorder()
  4474. {
  4475. PointLocation();
  4476. RectLeftUp.Visibility = Visibility.Visible;
  4477. RectRightUp.Visibility = Visibility.Visible;
  4478. RectLeftDown.Visibility = Visibility.Visible;
  4479. RectRightDown.Visibility = Visibility.Visible;
  4480. RectImgBorder.Visibility = Visibility.Visible;
  4481. }
  4482. /// <summary>
  4483. /// 确定四个点和边框的位置大小
  4484. /// </summary>
  4485. private void PointLocation()
  4486. {
  4487. RectImgBorder.Width = imgCanvas.ActualWidth + 10.0;
  4488. RectImgBorder.Height = imgCanvas.ActualHeight + 10.0;
  4489. RectImgBorder.Margin = new Thickness(imgCanvas.Margin.Left - 5.0, imgCanvas.Margin.Top - 5.0, 0, 0);
  4490. Canvas.SetLeft(RectLeftUp, imgCanvas.Margin.Left - 10.0);
  4491. Canvas.SetTop(RectLeftUp, imgCanvas.Margin.Top - 10.0);
  4492. Canvas.SetLeft(RectRightUp, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4493. Canvas.SetTop(RectRightUp, imgCanvas.Margin.Top - 10.0);
  4494. Canvas.SetLeft(RectLeftDown, imgCanvas.Margin.Left - 10.0);
  4495. Canvas.SetTop(RectLeftDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4496. Canvas.SetLeft(RectRightDown, imgCanvas.Margin.Left + imgCanvas.ActualWidth - 10.0);
  4497. Canvas.SetTop(RectRightDown, imgCanvas.Margin.Top + imgCanvas.ActualHeight - 10.0);
  4498. }
  4499. private void PicEMap_MouseDown(object sender, MouseButtonEventArgs e)
  4500. {
  4501. System.Windows.Point point = e.GetPosition(imgCanvas);
  4502. initialPoint = point;
  4503. //Console.WriteLine("PicEmap.X = " + point.X + "; PicEmap.Y = " + point.Y);
  4504. //if ((point.X - 304) * (point.X - 304) + (point.Y - 86) * (point.Y - 86) < 100)
  4505. //{
  4506. // Console.WriteLine("在范围内");
  4507. //}
  4508. HideAngleBorder();
  4509. }
  4510. private void imgCanvas_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  4511. {
  4512. if (e.LeftButton == MouseButtonState.Pressed && mouseDown)
  4513. {
  4514. System.Windows.Point point = e.GetPosition(imgCanvas);
  4515. imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left + (point.X - initialPoint.X), imgCanvas.Margin.Top + (point.Y - initialPoint.Y), 0, 0);
  4516. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4517. {
  4518. X = imgCanvas.Margin.Left,
  4519. Y = imgCanvas.Margin.Top
  4520. };
  4521. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4522. {
  4523. CenterX = imgCanvas.ActualWidth,
  4524. CenterY = imgCanvas.ActualHeight
  4525. };
  4526. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4527. }
  4528. }
  4529. private void imgCanvas_MouseUp(object sender, MouseButtonEventArgs e)
  4530. {
  4531. if (mouseDown)
  4532. {
  4533. ShowAngleBorder();
  4534. }
  4535. }
  4536. private System.Drawing.PointF imgRightDown;
  4537. /// <summary>
  4538. /// 设置控件最上层
  4539. /// </summary>
  4540. /// <param name="element"></param>
  4541. public void BringToFront(Thumb element)//图片置于最顶层显示
  4542. {
  4543. if (element == null)
  4544. {
  4545. return;
  4546. }
  4547. Canvas parent = element.Parent as Canvas;
  4548. if (parent == null)
  4549. {
  4550. return;
  4551. }
  4552. int maxZ = parent.Children.OfType<UIElement>()//linq语句,取Zindex的最大值
  4553. .Where(x => x != element)
  4554. .Select(x => Canvas.GetZIndex(x))
  4555. .Max();
  4556. Canvas.SetZIndex(element, maxZ + 1);
  4557. }
  4558. private void RectRightUp_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
  4559. {
  4560. try
  4561. {
  4562. Thumb thu = (Thumb)sender;
  4563. BringToFront(thu);
  4564. imgRightDown = new System.Drawing.PointF((float)(imgCanvas.Margin.Left + imgCanvas.ActualWidth), (float)(imgCanvas.Margin.Top + imgCanvas.ActualHeight));
  4565. HideAngleBorder();
  4566. switch (thu.Name)
  4567. {
  4568. case "RectLeftUp":
  4569. RectLeftUp.Visibility = Visibility.Visible;
  4570. break;
  4571. case "RectRightUp":
  4572. RectRightUp.Visibility = Visibility.Visible;
  4573. break;
  4574. case "RectLeftDown":
  4575. RectLeftDown.Visibility = Visibility.Visible;
  4576. break;
  4577. case "RectRightDown":
  4578. RectRightDown.Visibility = Visibility.Visible;
  4579. break;
  4580. default:
  4581. break;
  4582. }
  4583. }
  4584. catch (Exception ex)
  4585. {
  4586. MessageWindow.Show(ex.Message);
  4587. }
  4588. }
  4589. private void RectRightUp_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
  4590. {
  4591. try
  4592. {
  4593. if (mouseDown)
  4594. {
  4595. Thumb thu = (Thumb)sender;
  4596. #region 判断是否超出 暂无
  4597. double plul = Canvas.GetLeft(RectLeftUp);
  4598. double plut = Canvas.GetTop(RectLeftUp);
  4599. double prdl = Canvas.GetLeft(RectRightDown);
  4600. double prdt = Canvas.GetTop(RectRightDown);
  4601. #endregion
  4602. //Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4603. //Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4604. double imgW = 0;
  4605. double imgH = 0;
  4606. double imgX = 0;
  4607. double imgY = 0;
  4608. switch (thu.Name)
  4609. {
  4610. case "RectLeftUp":
  4611. #region 左上
  4612. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4613. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4614. imgX = 0;
  4615. imgY = 0;
  4616. if (imgW < 50)
  4617. {
  4618. imgCanvas.Width = 50;
  4619. imgX = imgCanvas.Margin.Left;
  4620. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4621. }
  4622. else
  4623. {
  4624. imgCanvas.Width = imgW;
  4625. imgX = Mouse.GetPosition(gridM).X;
  4626. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4627. }
  4628. if (imgH < 50)
  4629. {
  4630. imgCanvas.Height = 50;
  4631. imgY = imgCanvas.Margin.Top;
  4632. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4633. }
  4634. else
  4635. {
  4636. imgCanvas.Height = imgH;
  4637. imgY = Mouse.GetPosition(gridM).Y;
  4638. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4639. }
  4640. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4641. #endregion
  4642. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4643. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4644. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, Mouse.GetPosition(gridM).Y, 0, 0);
  4645. break;
  4646. case "RectRightUp":
  4647. #region 右上
  4648. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4649. imgH = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4650. imgX = 0;
  4651. imgY = 0;
  4652. if (imgW < 50)
  4653. {
  4654. imgCanvas.Width = 50;
  4655. imgX = imgCanvas.Margin.Left;
  4656. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4657. }
  4658. else
  4659. {
  4660. imgCanvas.Width = imgW;
  4661. imgX = imgCanvas.Margin.Left;
  4662. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4663. }
  4664. if (imgH < 50)
  4665. {
  4666. imgCanvas.Height = 50;
  4667. imgY = imgCanvas.Margin.Top;
  4668. Canvas.SetTop(thu, Canvas.GetTop(RectRightDown) - 50);
  4669. }
  4670. else
  4671. {
  4672. imgCanvas.Height = imgH;
  4673. imgY = Mouse.GetPosition(gridM).Y;
  4674. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4675. }
  4676. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4677. //imgCanvas.Width = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4678. //imgCanvas.Height = imgRightDown.Y - (Mouse.GetPosition(gridM).Y);
  4679. //imgCanvas.Margin = new Thickness(imgCanvas.Margin.Left, Mouse.GetPosition(gridM).Y, 0, 0);
  4680. #endregion
  4681. break;
  4682. case "RectLeftDown":
  4683. #region 左下
  4684. imgW = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4685. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4686. imgX = 0;
  4687. imgY = 0;
  4688. if (imgW < 50)
  4689. {
  4690. imgCanvas.Width = 50;
  4691. imgX = imgCanvas.Margin.Left;
  4692. Canvas.SetLeft(thu, Canvas.GetLeft(RectRightDown) - 50);
  4693. }
  4694. else
  4695. {
  4696. imgCanvas.Width = imgW;
  4697. imgX = Mouse.GetPosition(gridM).X;
  4698. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4699. }
  4700. if (imgH < 50)
  4701. {
  4702. imgCanvas.Height = 50;
  4703. imgY = imgCanvas.Margin.Top;
  4704. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4705. }
  4706. else
  4707. {
  4708. imgCanvas.Height = imgH;
  4709. imgY = imgCanvas.Margin.Top;
  4710. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4711. }
  4712. imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4713. //imgCanvas.Width = imgRightDown.X - (Mouse.GetPosition(gridM).X);
  4714. //imgCanvas.Height = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4715. //imgCanvas.Margin = new Thickness(Mouse.GetPosition(gridM).X, imgCanvas.Margin.Top, 0, 0);
  4716. #endregion
  4717. break;
  4718. case "RectRightDown":
  4719. #region 右下
  4720. imgW = Mouse.GetPosition(gridM).X - imgCanvas.Margin.Left;
  4721. imgH = Mouse.GetPosition(gridM).Y - imgCanvas.Margin.Top;
  4722. if (imgW < 50)
  4723. {
  4724. imgCanvas.Width = 50;
  4725. Canvas.SetLeft(thu, Canvas.GetLeft(RectLeftUp) + 50);
  4726. }
  4727. else
  4728. {
  4729. imgCanvas.Width = imgW;
  4730. Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
  4731. }
  4732. if (imgH < 50)
  4733. {
  4734. imgCanvas.Height = 50;
  4735. Canvas.SetTop(thu, Canvas.GetTop(RectLeftUp) + 50);
  4736. }
  4737. else
  4738. {
  4739. imgCanvas.Height = imgH;
  4740. Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
  4741. }
  4742. //imgCanvas.Margin = new Thickness(imgX, imgY, 0, 0);
  4743. //imgCanvas.Width += e.HorizontalChange;
  4744. //imgCanvas.Height += e.VerticalChange;
  4745. #endregion
  4746. break;
  4747. default:
  4748. break;
  4749. }
  4750. APP.PageDrawList[APP.pageData.currpage - 1].ImageLocation = new TranslateTransform
  4751. {
  4752. X = imgCanvas.Margin.Left,
  4753. Y = imgCanvas.Margin.Top
  4754. };
  4755. APP.PageDrawList[APP.pageData.currpage - 1].ImageSizes = new ScaleTransform
  4756. {
  4757. CenterX = imgCanvas.ActualWidth,
  4758. CenterY = imgCanvas.ActualHeight
  4759. };
  4760. APP.PageDrawList[APP.pageData.currpage - 1].IsImageLocation = false;
  4761. }
  4762. //lbl1.Content = imgCanvas.Margin.Left + "," + imgCanvas.Margin.Top;
  4763. //lbl2.Content = (imgCanvas.Margin.Left+ imgCanvas.Width) +"," + imgCanvas.Margin.Top;
  4764. //lbl3.Content = imgCanvas.Margin.Left + "," + (imgCanvas.Margin.Top+ imgCanvas.Height);
  4765. //lbl4.Content= (imgCanvas.Margin.Left + imgCanvas.Width )+ "," + (imgCanvas.Margin.Top + imgCanvas.Height);
  4766. }
  4767. catch (Exception)
  4768. {
  4769. MessageWindow.Show("图片过小!");
  4770. }
  4771. }
  4772. private void RectRightUp_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  4773. {
  4774. ShowAngleBorder();
  4775. }
  4776. #endregion
  4777. #region 方法
  4778. /// <summary>
  4779. /// 录屏 录制 截图 导入文档 增加 主页面显示
  4780. /// </summary>
  4781. private void Record()
  4782. {
  4783. GridMain.Visibility = Visibility.Visible;
  4784. gridSetUp.Visibility = Visibility.Collapsed;
  4785. //gridUpload.Visibility = Visibility.Collapsed;
  4786. GridMyVideo.Visibility = Visibility.Collapsed;
  4787. if (APP.pageData.pagenum > 0)
  4788. {
  4789. gridPage.Visibility = Visibility.Visible;
  4790. }
  4791. DataContext = APP.pageData;
  4792. }
  4793. /// <summary>
  4794. /// 设置页面显示
  4795. /// </summary>
  4796. private void SetUp()
  4797. {
  4798. }
  4799. #endregion
  4800. private void imgCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  4801. {
  4802. mouseDown = true;
  4803. }
  4804. /// <summary>
  4805. /// 点击标题栏 隐藏截图的四个点和线
  4806. /// </summary>
  4807. /// <param name="sender"></param>
  4808. /// <param name="e"></param>
  4809. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  4810. {
  4811. HideAngleBorder();
  4812. }
  4813. /// <summary>
  4814. /// 鼠标左键点击事件
  4815. /// </summary>
  4816. /// <param name="sender"></param>
  4817. /// <param name="e"></param>
  4818. private void Window_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
  4819. {
  4820. if (RectImgBorder.Visibility != Visibility.Hidden)
  4821. {
  4822. HideAngleBorder();
  4823. }
  4824. }
  4825. /// <summary>
  4826. /// 加载完成后调整录制区域大小
  4827. /// </summary>
  4828. /// <param name="sender"></param>
  4829. /// <param name="e"></param>
  4830. private void Window_Loaded(object sender, RoutedEventArgs e)
  4831. {
  4832. //调整录制区域宽高
  4833. double proportion = 210.0 / 297.0;
  4834. gridM.Height = gridM.ActualWidth / proportion;
  4835. }
  4836. #region 原跳转
  4837. /// <summary>
  4838. /// 跳转页
  4839. /// </summary>
  4840. /// <param name="sender"></param>
  4841. /// <param name="e"></param>
  4842. private void txbCurrpage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  4843. {
  4844. if (e.ClickCount == 2)
  4845. {
  4846. try
  4847. {
  4848. if (int.Parse(txbCurrpage.Text) > 0)
  4849. {
  4850. //txtJump.Text = txbCurrpage.Text;
  4851. //txbCurrpage.Visibility = Visibility.Hidden;
  4852. //txtJump.Visibility = Visibility.Visible;
  4853. //BtnJumpPage.Visibility = Visibility.Visible;
  4854. //txtJump.Focus();
  4855. //txtJump.SelectAll();
  4856. }
  4857. }
  4858. catch (Exception)
  4859. {
  4860. }
  4861. }
  4862. }
  4863. /// <summary>
  4864. /// 确定跳转
  4865. /// </summary>
  4866. /// <param name="sender"></param>
  4867. /// <param name="e"></param>
  4868. private void BtnJumpPage_Click(object sender, RoutedEventArgs e)
  4869. {
  4870. int JumpPage = 0;
  4871. //try
  4872. //{
  4873. // JumpPage = int.Parse(txtJump.Text);
  4874. //}
  4875. //catch (Exception ex)
  4876. //{
  4877. // MessageWindow.Show("操作有误!请输入有效的页码!");
  4878. // return;
  4879. //}
  4880. if (JumpPage < 1)
  4881. {
  4882. JumpPage = 1;
  4883. }
  4884. if (JumpPage > int.Parse(txbTotalpage.Text))
  4885. {
  4886. JumpPage = int.Parse(txbTotalpage.Text);
  4887. }
  4888. #region 跳转
  4889. APP.pageData.currpage = JumpPage;
  4890. JumpPageClick();
  4891. #endregion
  4892. //txbCurrpage.Visibility = Visibility.Visible;
  4893. //txtJump.Visibility = Visibility.Hidden;
  4894. //BtnJumpPage.Visibility = Visibility.Hidden;
  4895. }
  4896. /// <summary>
  4897. /// 只允许输入数字
  4898. /// </summary>
  4899. /// <param name="sender"></param>
  4900. /// <param name="e"></param>
  4901. private void txtJump_PreviewTextInput(object sender, TextCompositionEventArgs e)
  4902. {
  4903. Regex re = new Regex("[^0-9.-]+");
  4904. e.Handled = re.IsMatch(e.Text);
  4905. }
  4906. private void txtJump_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  4907. {
  4908. if (e.Key == Key.Enter)
  4909. {
  4910. BtnJumpPage_Click(null, null);
  4911. }
  4912. }
  4913. #endregion
  4914. #region 跳转
  4915. /// <summary>
  4916. /// 跳转
  4917. /// </summary>
  4918. /// <param name="sender"></param>
  4919. /// <param name="e"></param>
  4920. private void CbxPageList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  4921. {
  4922. #region 安全
  4923. if(CbxPageList.SelectedValue==null)
  4924. {
  4925. return;
  4926. }
  4927. if (APP.pageData.currpage == int.Parse(CbxPageList.SelectedValue.ToString()))
  4928. {
  4929. return;
  4930. }
  4931. #endregion
  4932. int JumpPage = 0;
  4933. try
  4934. {
  4935. JumpPage = int.Parse(CbxPageList.SelectedValue.ToString());
  4936. }
  4937. catch (Exception)
  4938. {
  4939. MessageWindow.Show("操作有误!请输入有效的页码!");
  4940. return;
  4941. }
  4942. if (JumpPage < 1)
  4943. {
  4944. JumpPage = 1;
  4945. }
  4946. if (JumpPage > int.Parse(txbTotalpage.Text))
  4947. {
  4948. JumpPage = int.Parse(txbTotalpage.Text);
  4949. }
  4950. #region 跳转
  4951. APP.pageData.currpage = JumpPage;
  4952. JumpPageClick();
  4953. #endregion
  4954. }
  4955. #endregion
  4956. }
  4957. public class PageData
  4958. {
  4959. public int PageCode { get; set; }
  4960. public string PageName { get; set; }
  4961. }
  4962. }