Windows脚本编程核心技术精解Chapter21.pdf
《Windows脚本编程核心技术精解Chapter21.pdf》由会员分享,可在线阅读,更多相关《Windows脚本编程核心技术精解Chapter21.pdf(26页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Chapter 21Fax,Printer,Scanner,and GraphicsIn This Chapter?Discover Kodak Imaging and how you can control its functions by script?Check your TWAIN scanner support,select picture sources,and scan images?Automate scanning and scan in hundreds of images using batch automation?Print any image and create
2、your own scan-print-photocopy tool?Scale printouts to fit the page?Load,print,and save any picture file?Rotate,scale,and zoom pictures,and create button faces from scannedimages automatically?Generate comprehensive thumbnail preview pages and organize your picture archives?Convert the graphics forma
3、t and choose compression and color depth?Reveal compression settings and size information for any picture file,and repair picture file types automaticallyAll Windows versions come with a secret add-on called Kodak Imaging.Its fully scriptable,and in this chapter,you learn how to use it toscan images
4、 from a TWAIN scanner and to print or save the images.Say“Hi”to Kodak ImagingMicrosoft has included a tremendously useful tool in all 32-bit Windowsversions,and its called the Kodak Imaging tool(see Figure 21-1).This littletool hides in the Accessories program group(if its missing,you can justinstal
5、l it from your Windows CD by using the Control Panel Software moduleand choosing the Windows Setup tab).The Imaging tool is part of the base services offered by Windows.Just asWordPad gives you out-of-the-box access to WinWord documents,Imagingallows you to view graphics files,fax messages,and scan
6、in pictures from anyTWAIN-compatible flatbed scanner.4684-8 ch21.f.qc 3/3/00 9:44 AM Page 581Figure 21-1:Kodak Imaging is a multi-purpose image viewing utility included with Windows.At first sight,the Imaging tool doesnt seem to be special,but it is.Its fullyscriptable.And it provides your scripts w
7、ith new methods to read in picturesfrom any TWAIN picture source,as well as to print them out.A closer lookInternally,the Imaging tool consists of a number of COM objects,as shown inTable 21-1.Table 21-1Components of Kodak ImagingCOM ObjectDescriptionIMGADMIN.OCXAdministration toolIMGEDIT.OCXDisplay
8、 and print images,add notationsIMGSCAN.OCXTWAIN-compatible scanner supportIMGTHUMB.OCXThumbnail viewSome Windows versions come with a very detailed help file that provides allthe information necessary to script the components(see Figure 21-2).Searchfor IMGOCXD.HLP.Even if you dont find IMGOCXD.HLPon
9、 your system,youstill can retrieve all the methods and properties available.Just use script 5-12and enter the filenames listed above.582Part V:Accessing Hidden ComponentsII4684-8 ch21.f.qc 3/3/00 9:44 AM Page 582Figure 21-2:Kodak Imaging provides a full documentation.Getting access to the controlYou
10、 cant script the Kodak tools directly.Instead,you need to either embedthem into a Web page or use them as controls inside a custom COM object.As you might suspect,I have created a sample COM object.It basically wrapsthe controls and provides public methods and properties your script canaccess.Instal
11、l installscansetup.exe(full source code is provided atcomponentsscanscan.vbp).Watch out because there are many different versions of Kodak Imaging around.If your source code wont compile and instead complains about illegal methods,then you need to replace the Imaging controls on the form with the co
12、ntrolsinstalled on your system.To do so,delete the controls from the form and then right-click the tool bar.Choose Components,and in the dialog box,click Browse.Now,search for thefiles listed in Table 21-1 and add them to your toolbar.At last,add thosecontrols back to your form.Now youre done.But th
13、eres an even easier way.You can install the pre-built COM objectwithout recompiling it.A word of cautionTake a look at the COM object source code.Its not complicatedthe Imagingtool handles the difficult parts.Still,you need to be aware of some very impor-tant design rules.Chapter 21:Fax,Printer,Scan
14、ner,and Graphics583II4684-8 ch21.f.qc 3/3/00 9:44 AM Page 583The COM object places the Imaging controls on a separate form.This is doneso you can display the edit control as a dialog box.However,theres a strictrulealways place the code managing the controls into the same object thathosts the control
15、s.If you dont,you may experience protection faults andblue screens.The reason is simple.The form may be unloaded in the event of an error.Thecontrols arent there anymore because they“lived”inside the form.If some otherpart of your COM object still tries to access the controls,it will send data to am
16、emory address thats no longer valid,making the protection fault necessary.Still,you need code in the User Control because this is the only place you canmake internal functions accessible to the outside world.However,the code inthe User Control only“wraps”the code defined in the form.This is okay.Jus
17、tmake sure all the complex parts are in the same object together with theImaging controls they refer to.Finding out if TWAIN support is availableKodak Imaging requires that TWAIN software be installed on your system(see Figure 21-3).Most scanners and a lot of other imaging sources come with TWAIN dr
18、ivers.To make sure,use your new COM object and find out:Figure 21-3:Find out whether you have TWAIN support.21-1.VBSset tool=CreateObject(“twain.manager”)ok=tool.ScannerAvailableif ok thenMsgBox“TWAIN support is installed.Check out your scan sources!”tool.SelectScannerelseMsgBox“No TWAIN support det
19、ected.Get a“_&“TWAIN-compliant Scanner!”,vbExclamationend ifIf TWAIN support is detected,the script calls SelectScanner.This invokes abuilt-in dialog box that lists all TWAIN-compliant imaging sources available.Ifno TWAIN support was detected,you cant proceed.Get a TWAIN-compliantimaging device firs
20、t.Although many different imaging devices can be controlled via TWAIN,theKodak Imaging tool specializes in scanners.You may or may not be able touse a digital camera or other devices.Non-compliant devices generate benignerror messages.584Part V:Accessing Hidden ComponentsII4684-8 ch21.f.qc 3/3/00 9:
21、44 AM Page 584Scanning PicturesWith the help of your new COM component,your scripts can now scan pages.There are many useful real-world tasks you can now master.For example,youcan create your own little photocopy machine,or you can batch-scan a wholeseries of pictures without having to click too man
22、y buttons.Saving scanned pictures to diskThe next script shows how to scan a picture and save it to disk.The script ispretty straightforward because it leaves the difficult stuff to the Imaging tool:21-2.VBSset tool=CreateObject(“twain.manager”)check whether twain support is availableif not tool.Sca
23、nnerAvailable thenMsgBox“No TWAIN support!”,vbCriticalWScript.Quitend if fill in informationfilename=“C:mypic.jpg”scan and save as bmp graphictool.FileType=3 1:TIFF(default)2:AWD(Win 98 Fax format)3:BMP tell control how to storetool.PageOption=6 0:create new picture.Error if picture already exists 1
24、:create new picture.Ask if picture already exists(default)2:append to existing picture 3:insert into existing picture at position specified by page 4:overwrite existing picture.If picture doesnt exist,error 5:overwrite existing picture,ask for permission.Error if picture doesnt yet exist 6:always ov
25、erwrite tell control how to scantool.ScanTo=1 0:display image only(default)1:display and write to disk 2:write to disk 3:write to disk using template and display 4:write to disk using template 5:fax image(fax software must be installed)show scanner setup?tool.ShowSetup=trueChapter 21:Fax,Printer,Sca
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Windows 脚本 编程 核心技术 Chapter21
限制150内