1、关于WIAAL
The Windows Image Acquisition (WIA) Automation Layer 2.0 is a high-quality, full-featured image manipulation component that provides end-to-end image processing capabilities for Microsoft Visual Basic 6.0, Active Server Pages (ASP), and scripting languages. The WIA Automation Layer exposes features in Windows XP Service Pack 1 (SP1) or later to make it easy to acquire images on digital cameras, scanners, or Web cameras, and to rotate, scale, and annotate your image files. Earlier versions of Windows are not supported.
Other new features include the ability to:
- Access the properties of image files.
- Read and write image files and their properties to databases.
- Modify pixels including alpha values.
- Write ASP pages that generate thumbnail images on the fly.
- Take pictures with your Web camera.
- Automatically download pictures from cameras as soon as they are connected, even if a script is not already running.
This overview includes the following topics.
Object Hierarchy
The WIA Automation Layer is broken down into two types of objects. The first type of object is a creatable object. This is an object that can be directly created by calling the Microsoft Visual Basic function CreateObject. In addition, three creatable objects (DeviceManager, CommonDialog, and VideoPreview) are also controls that can be dropped on a form in Visual Basic. The second type of object is the supporting object. This object is not directly creatable but instead is returned from properties or methods. For example, the Connect method on a DeviceInfo object returns a Device object.
The following object hierarchy diagrams show the relationship between objects, collections, and reused objects for both creatable and supporting objects. The hierarchy diagrams use these symbols.
As you can see in the previous illustrations, the WIA Automation Layer reuses objects wherever possible to reduce the number of different objects you need to learn to use. For example, the Device, DeviceInfo, Filter, FilterInfo, Item, and ImageFile objects all reuse the Properties collection to expose their properties. Once you learn how to use the Properties collection on one object you will be able to use it on all the others.
Notice the naming convention in which a collection of objects uses the plural of that object name. For example, a Filters collection holds Filter objects.
Accessing Imaging Devices
The DeviceManager object and, to a limited degree, the VideoPreview object are the primary ways to access Imaging Devices. The Device object represents an active connection to an Imaging Device. From the Device object you can access its properties, access the items that might be stored on it, transfer those items to files on the computer, and run commands that cause the Imaging Device to do something. For example, you could access a digital camera's date and time, transfer all its pictures to your computer or cause it to take a picture. These actions can be done in one of two ways, programmatically without any user intervention, or using the CommonDialog object to present dialog boxes that enable the user to precisely control the actions.
Manipulating Image Files
Once you have transferred pictures to your computer, you can use the ImageFile object to access the pictures. You can display them on forms, return them as binary data in ASP pages, or access their properties. Many digital cameras store a number of detailed properties in their pictures, from useful information like the date the picture was taken and a thumbnail image to interesting technical details like the model of camera, the focal length, aperture setting, and shutter speed. For more information about detailed properties, see Display all ImageFile Properties and Display Detailed Image Information.
In order to protect the original pictures that represent digital memories, the ImageFile object cannot directly modify the pictures. You can, however, use an ImageProcess object and one or more Filter objects to create a modified copy of the picture. The WIA Automation Layer provides filters that rotate, flip, crop, scale, stamp, modify properties, modify the individual pixels or change the file format to Tagged Image File Format (TIFF), JPEG, Portable Network Graphics (PNG), bitmap (BMP), or Graphics Interchange Format (GIF). For more information about filters, see How To Use Filters.
Example Code
All reference pages in this documentation set include example code or a link to examples in the Overviews/Tutorials section that illustrate how to use the API. Begin by reading Getting Started with Samples. This topic has the template code for a variety of development environments into which you can paste the reference examples. Shared Samples includes a number of examples that are applicable to a variety of applications.
The following examples are complete samples that you do not need to paste into template code.
- Download New Items as They are Created
- Use VideoPreview Control in HTML
- Implement a Web Camera ASP Page
- Implement a Windows Script Host Script that Runs Automatically
2、How to Use Filters
This topic provides examples that show how to use each of the filters available with the Windows Image Acquisition (WIA) Automation Library version 2.0.
These examples need to be inserted into template code to form complete samples. For the appropriate code template for your preferred development environment, see Getting Started with Samples. See also Shared Samples and the individual reference pages for additional sample code.
- RotateFlip Filter: Rotate a Picture
- Crop Filter: Crop a Picture
- Scale Filter: Resize an Image
- Stamp Filter: Stamp a Picture Over Another Picture
- EXIF Filter: Write a New Title Tag to an Image
- Frame Filter: Create a Multipage TIFF from Three Pictures
- ARGB Filter: Create a Modified Version of an Image
- Convert Filter: Create a Compressed JPEG File from Another File
RotateFlip Filter: Rotate a Picture
The following shows how to use the RotateFlip filter to rotate one of the sample pictures from Windows XP 90 degrees.
Dim Img 'As ImageFile Dim IP 'As ImageProcess Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" IP.Filters.Add IP.FilterInfos("RotateFlip").FilterID IP.Filters(1).Properties("RotationAngle") = 90 Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\Bliss90.bmp"
Crop Filter: Crop a Picture
The following shows how to use the Crop filter to crop 25 percent of the Top, Left, Bottom, and Right of one of the sample pictures from Windows XP.
Dim Img 'As ImageFile Dim IP 'As ImageProcess Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" IP.Filters.Add IP.FilterInfos("Crop").FilterID IP.Filters(1).Properties("Left") = Img.Width \ 4 IP.Filters(1).Properties("Top") = Img.Height \ 4 IP.Filters(1).Properties("Right") = Img.Width \ 4 IP.Filters(1).Properties("Bottom") = Img.Height \ 4 Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\BlissCrop.bmp"
Scale Filter: Resize an Image
The following shows how to use the Scale filter to create a thumb-sized version of one of the sample pictures from Windows XP.
Dim Img 'As ImageFile Dim IP 'As ImageProcess Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" IP.Filters.Add IP.FilterInfos("Scale").FilterID IP.Filters(1).Properties("MaximumWidth") = 100 IP.Filters(1).Properties("MaximumHeight") = 100 Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\BlissThumb.bmp"
Stamp Filter: Stamp a Picture Over Another Picture
The following shows how to stamp the thumb-sized picture created in the previous example on top of the full-sized version of one of the sample pictures from Windows XP.
Dim Thumb 'As ImageFile Dim Img 'As ImageFile Dim IP 'As ImageProcess Set Img = CreateObject("WIA.ImageFile") Set Thumb = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" Thumb.LoadFile "C:\WINDOWS\Web\Wallpaper\BlissThumb.bmp" IP.Filters.Add IP.FilterInfos("Stamp").FilterID Set IP.Filters(1).Properties("ImageFile") = Thumb IP.Filters(1).Properties("Left") = Img.Width - Thumb.Width IP.Filters(1).Properties("Top") = Img.Height - Thumb.Height Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\BlissStamp.bmp"
EXIF Filter: Write a New Title Tag to an Image
The following example shows how to write a Title tag to a new version of one of the sample pictures from Windows XP. You can view the Title tag by right-clicking the image, clicking Properties, and clicking the Summary tab. This example uses the Exchangeable Image File (EXIF) filter.
Dim Img 'As ImageFile Dim IP 'As ImageProcess Dim v 'As Vector Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Set v = CreateObject("WIA.Vector") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Autumn.jpg" IP.Filters.Add IP.FilterInfos("Exif").FilterID IP.Filters(1).Properties("ID") = 40091 IP.Filters(1).Properties("Type") = VectorOfBytesImagePropertyType v.SetFromString "This Title tag written by Windows Image Acquisition Library v2.0" IP.Filters(1).Properties("Value") = v Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\AutumnExif.jpg"
Frame Filter: Create a Multipage TIFF from Three Pictures
The following example shows how to create a multiframe (multipage) Tagged Image File Format (TIFF) file from three of the sample pictures from Windows XP, and then create a bitmap (BMP) file from the last frame. This example uses the Frame filter.
Dim Img 'As ImageFile Dim Page2 'As ImageFile Dim Page3 'As ImageFile Dim IP 'As ImageProcess Dim v 'As Vector Set Img = CreateObject("WIA.ImageFile") Set Page2 = CreateObject("WIA.ImageFile") Set Page3 = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" Page2.LoadFile "C:\WINDOWS\Web\Wallpaper\Azul.jpg" Page3.LoadFile "C:\WINDOWS\Web\Wallpaper\Autumn.jpg" IP.Filters.Add IP.FilterInfos("Frame").FilterID Set IP.Filters(IP.Filters.Count).Properties("ImageFile") = Page2 IP.Filters.Add IP.FilterInfos("Frame").FilterID Set IP.Filters(IP.Filters.Count).Properties("ImageFile") = Page3 IP.Filters.Add IP.FilterInfos("Convert").FilterID IP.Filters(IP.Filters.Count).Properties("FormatID") = wiaFormatTIFF Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\Bliss.tif" Img.ActiveFrame = Img.FrameCount Set v = Img.ARGBData Set Img = v.ImageFile(Img.Width, Img.Height) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\Autumn.bmp"
Note TIFF is the only format that supports saving multiple frames. If you want to preserve the frames of an animated Graphics Interchange Format (GIF) you can create a filter chain with a single Convert filter to convert the animated GIF to a TIFF. For an example that uses the Convert filter, see Convert Filter: Create a Compressed JPEG File from Another File.
ARGB Filter: Create a Modified Version of an Image
The following example shows how to create a version of one of the sample pictures from Windows XP with bright pink diagonal lines. The example uses the ARGB filter.
Note This operation can be slow on certain computers.
Dim Img 'As ImageFile Dim IP 'As ImageProcess Dim v 'As Vector Dim i 'As Long Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" Set v = Img.ARGBData For i = 1 To v.Count Step 21 v(i) = &HFFFF00FF 'opaque pink (A=255,R=255,G=0,B=255) Next IP.Filters.Add IP.FilterInfos("ARGB").FilterID Set IP.Filters(1).Properties("ARGBData") = v Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\BlissARGB.bmp"
Convert Filter: Create a Compressed JPEG File from Another File
The following example shows how to create a compressed JPEG version of one of the sample pictures from Windows XP. The example uses the Convert filter.
Dim Img 'As ImageFile Dim IP 'As ImageProcess Set Img = CreateObject("WIA.ImageFile") Set IP = CreateObject("WIA.ImageProcess") Img.LoadFile "C:\WINDOWS\Web\Wallpaper\Bliss.bmp" IP.Filters.Add IP.FilterInfos("Convert").FilterID IP.Filters(1).Properties("FormatID").Value = wiaFormatJPEG IP.Filters(1).Properties("Quality").Value = 5 Set Img = IP.Apply(Img) Img.SaveFile "C:\WINDOWS\Web\Wallpaper\BlissCompressed.jpg" 3、Getting Started with Samples
All the example code contained in the Windows Image Acquisition (WIA) Automation Layer 2.0 reference works in multiple languages. This way you can copy the examples from the reference pages into any of the following:
Visual Basic 6.0
To create a Microsoft Visual Basic project for any of the examples in the reference topics, perform the following steps.
- Start the Visual Basic Development Environment.
- Select Standard EXE.
- Click Components from the Project menu (or press Ctrl-T).
- Scroll down and select Microsoft Windows Image Acquisition Library v2.0 by placing a checkmark in front of it. Of the three new controls that appear on in the Toolbox, double click CommonDialog and DeviceManager to add them to your form.
Note The data types are commented out in the examples in the reference pages so you can copy and paste them into Microsoft Visual Basic Scripting Edition (VBScript) where all data types are a Variant. Visual Basic programmers should remove the comment mark (') in front of each data type.
Windows Script Host
To create a Windows Script Host project, copy the following into an empty file with a .wsf extension.
<job> <reference object="WIA.DeviceManager" /> <object id="DeviceManager1" progid="WIA.DeviceManager" /> <object id="CommonDialog1" progid="WIA.CommonDialog" /> <script language="VBScript"> 'Paste Sample Code Here </script> </job>
HTML Application
To create an HTML Application (HTA), copy the following into an empty file with an .hta extension. In addition, if you have not done so already, create the Visual Basic Script Constants file.
<html> <title>Sample HTA</title> <hta:application id="oHTA"/> <object ID="DeviceManager1" Width=0 Height=0 ClassID="CLSID:E1C5D730-7E97-4D8A-9E42-BBAE87C2059F"></object> <object ID="CommonDialog1" Width=0 Height=0 ClassID="CLSID:850D1D11-70F3-4BE5-9A11-77AA6B2BB201"></object> <script language="vbscript" src="wiaaut.vbs"></script> <script language="vbscript"> 'Paste Sample Code Here </script> </head> <body scroll="no"> </body> </html>
Script in an HTML Application
To create an HTML file with script, copy the following into an empty file with an .htm extension. In addition, if you have not done so already, create the Visual Basic Script Constants file.
Note Since the Windows Image Acquisition (WIA) Library is not marked safe for scripting, proper functionality is dependent on your security settings.
<html> <title>Sample HTML</title> <object ID="DeviceManager1" Width=0 Height=0 ClassID="CLSID:E1C5D730-7E97-4D8A-9E42-BBAE87C2059F"></object> <object ID="CommonDialog1" Width=0 Height=0 ClassID="CLSID:850D1D11-70F3-4BE5-9A11-77AA6B2BB201"></object> <script language="vbscript" src="wiaaut.vbs"></script> <script language="vbscript"> 'Paste Sample Code Here </script> </head> <body> </body> </html>
Active Server Pages
To create an Active Server Page, copy the following into an empty file with an .asp extension.
Note The script on Active Server Pages (ASP) runs on a non-interactive desktop so using the CommonDialog or VideoPreview control in an Active Server Page will not work as expected. In addition, in the interest of increased security, the default Server Security Settings needs to be adjusted before you can successfully create a DeviceManager object. For instructions on changing your security settings, see How to Configure Security Settings. Also, for security reasons you need to change any calls to the Visual Basic function CreateObject to instead use Server.CreateObject.
<%@ Language=VBScript %> <!--METADATA TYPE="TypeLib" UUID="94A0E92D-43C0-494E-AC29-FD45948A5221"--> <% 'Paste Sample Code Here %>
4、Shared Samples
参考:http://msdn.microsoft.com/en-us/library/windows/desktop/ms630826(v=vs.85).aspx
5、Visual Basic Script Constants
When using the Windows Image Acquisition (WIA) Library from an HTML Page or HTML Application (HTA) as illustrated in the examples, you need a file named Wiaaut.vbs that contains the following Microsoft Visual Basic Scripting Edition (VBScript) code. For more information about each of these constants and enumerated types, see the reference topics.
' Miscellaneous Const wiaIDUnknown = "{00000000-0000-0000-0000-000000000000}" Const wiaAnyDeviceID = "*" ' FormatID Const wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatGIF = "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" Const wiaFormatTIFF = "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}" ' EventID Const wiaEventDeviceConnected = "{A28BBADE-64B6-11D2-A231-00C04FA31809}" Const wiaEventDeviceDisconnected = "{143E4E83-6497-11D2-A231-00C04FA31809}" Const wiaEventItemCreated = "{4C8F4EF5-E14F-11D2-B326-00C04F68CE61}" Const wiaEventItemDeleted = "{1D22A559-E14F-11D2-B326-00C04F68CE61}" Const wiaEventScanImage = "{A6C5A715-8C6E-11D2-977A-0000F87A926F}" Const wiaEventScanPrintImage = "{B441F425-8C6E-11D2-977A-0000F87A926F}" Const wiaEventScanFaxImage = "{C00EB793-8C6E-11D2-977A-0000F87A926F}" Const wiaEventScanOCRImage = "{9D095B89-37D6-4877-AFED-62A297DC6DBE}" Const wiaEventScanEmailImage = "{C686DCEE-54F2-419E-9A27-2FC7F2E98F9E}" Const wiaEventScanFilmImage = "{9B2B662C-6185-438C-B68B-E39EE25E71CB}" Const wiaEventScanImage2 = "{FC4767C1-C8B3-48A2-9CFA-2E90CB3D3590}" Const wiaEventScanImage3 = "{154E27BE-B617-4653-ACC5-0FD7BD4C65CE}" Const wiaEventScanImage4 = "{A65B704A-7F3C-4447-A75D-8A26DFCA1FDF}" ' CommandID Const wiaCommandSynchronize = "{9B26B7B2-ACAD-11D2-A093-00C04F72DC3C}" Const wiaCommandTakePicture = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}" Const wiaCommandDeleteAllItems = "{E208C170-ACAD-11D2-A093-00C04F72DC3C}" Const wiaCommandChangeDocument = "{04E725B0-ACAE-11D2-A093-00C04F72DC3C}" Const wiaCommandUnloadDocument = "{1F3B3D8E-ACAE-11D2-A093-00C04F72DC3C}" ' WiaSubType enumeration Const UnspecifiedSubType = 0 Const RangeSubType = 1 Const ListSubType = 2 Const FlagSubType = 3 ' WiaDeviceType enumeration Const UnspecifiedDeviceType = 0 Const ScannerDeviceType = 1 Const CameraDeviceType = 2 Const VideoDeviceType = 3 ' WiaItemFlag enumeration Const FreeItemFlag = &h0 Const ImageItemFlag = &h1 Const FileItemFlag = &h2 Const FolderItemFlag = &h4 Const RootItemFlag = &h8 Const AnalyzeItemFlag = &h10 Const AudioItemFlag = &h20 Const DeviceItemFlag = &h40 Const DeletedItemFlag = &h80 Const DisconnectedItemFlag = &h100 Const HPanoramaItemFlag = &h200 Const VPanoramaItemFlag = &h400 Const BurstItemFlag = &h800 Const StorageItemFlag = &h1000 Const TransferItemFlag = &h2000 Const GeneratedItemFlag = &h4000 Const HasAttachmentsItemFlag = &h8000 Const VideoItemFlag = &h10000 Const RemovedItemFlag = &h80000000 ' WiaPropertyType enumeration Const UnsupportedPropertyType = 0 Const BooleanPropertyType = 1 Const BytePropertyType = 2 Const IntegerPropertyType = 3 Const UnsignedIntegerPropertyType = 4 Const LongPropertyType = 5 Const UnsignedLongPropertyType = 6 Const ErrorCodePropertyType = 7 Const LargeIntegerPropertyType = 8 Const UnsignedLargeIntegerPropertyType = 9 Const SinglePropertyType = 10 Const DoublePropertyType = 11 Const CurrencyPropertyType = 12 Const DatePropertyType = 13 Const FileTimePropertyType = 14 Const ClassIDPropertyType = 15 Const StringPropertyType = 16 Const ObjectPropertyType = 17 Const HandlePropertyType = 18 Const VariantPropertyType = 19 Const VectorOfBooleansPropertyType = 101 Const VectorOfBytesPropertyType = 102 Const VectorOfIntegersPropertyType = 103 Const VectorOfUnsignedIntegersPropertyType = 104 Const VectorOfLongsPropertyType = 105 Const VectorOfUnsignedLongsPropertyType = 106 Const VectorOfErrorCodesPropertyType = 107 Const VectorOfLargeIntegersPropertyType = 108 Const VectorOfUnsignedLargeIntegersPropertyType = 109 Const VectorOfSinglesPropertyType = 110 Const VectorOfDoublesPropertyType = 111 Const VectorOfCurrenciesPropertyType = 112 Const VectorOfDatesPropertyType = 113 Const VectorOfFileTimesPropertyType = 114 Const VectorOfClassIDsPropertyType = 115 Const VectorOfStringsPropertyType = 116 Const VectorOfVariantsPropertyType = 119 ' WiaImagePropertyType enumeration Const UndefinedImagePropertyType = 1000 Const ByteImagePropertyType = 1001 Const StringImagePropertyType = 1002 Const UnsignedIntegerImagePropertyType = 1003 Const LongImagePropertyType = 1004 Const UnsignedLongImagePropertyType = 1005 Const RationalImagePropertyType = 1006 Const UnsignedRationalImagePropertyType = 1007 Const VectorOfUndefinedImagePropertyType = 1100 Const VectorOfBytesImagePropertyType = 1101 Const VectorOfUnsignedIntegersImagePropertyType = 1102 Const VectorOfLongsImagePropertyType = 1103 Const VectorOfUnsignedLongsImagePropertyType = 1104 Const VectorOfRationalsImagePropertyType = 1105 Const VectorOfUnsignedRationalsImagePropertyType = 1106 ' WiaEventFlag enumeration Const NotificationEvent = 1 Const ActionEvent = 2 ' WiaImageIntent enumeration Const UnspecifiedIntent = 0 Const ColorIntent = 1 Const GrayscaleIntent = 2 Const TextIntent = 4 ' WiaImageBias enumeration Const MinimizeSize = 65536 Const MaximizeQuality = 1310726、ObjectsThis section contains reference information for the Windows Image Acquisition (WIA) Automation Library version 2.0 objects.
This section presents the following topics.
Objects
- CommonDialog
- Device
- DeviceCommand
- DeviceCommands
- DeviceEvent
- DeviceEvents
- DeviceInfo
- DeviceInfos
- DeviceManager
- Filter
- FilterInfo
- FilterInfos
- Filters
- Formats
- ImageFile
- ImageProcess
- Item
- Items
- Properties
- Property
- Rational
- Vector
- VideoPreview
7、Constants and EnumerationsThis section contains reference information for the constants and enumerations introduced in the Windows Image Acquisition (WIA) Automation Library version 2.0.
This section presents the following topics.
Constants and Enumerations
- CommandID Constants
- EventID Constants
- FormatID Constants
- Miscellaneous Constants
- WiaDeviceType
- WiaEventFlag
- WiaImageBias
- WiaImageIntent
- WiaImagePropertyType
- WiaItemFlag
- WiaPropertyType
- WiaSubType
以上来自:http://msdn.microsoft.com/en-us/library/windows/desktop/ms630827(v=vs.85).aspxWIA下载:http://www.microsoft.com/en-us/download/details.aspx?id=18287
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步