星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

XHMicroLessonSystemWindow.xaml.cs 226KB

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