[Original] WIA study notes

xiaoxiao2021-03-06  76

First, WIA Introduction 1. About WIAWIA is a referusion of Windows Image Acquisition, the current available version is WIA 1.0, which is a digital image acquisition service provided in Windows Millennium Edition (Windows Me) or later Windows systems, and it can also manage digital image devices . The WIA interface is both an application interface (WIA API), but also the device driver interface (WIA DDI), which is the content of the WIA API below. With WIA API, the app is:

Run in a strong and stable environment; maximum possible collaboration problem; enumerate the available image acquisition device; simultaneously connect multiple devices; query device properties with standards, scalable methods; standard, high-performance transmission Mechanism Gets data; maintain image properties during data transfer; obtain a large number of device event notification messages. 2. WIA Architecture WIA is a COM component implemented by an Out of Process service. It is different from most process external service programs that WIA avoids the image data transfer process by providing its own data transfer mechanism (IwiaDataTransfer interface). Performance loss. High-performance IWIADATATRANSFER interface uses shared memory to transmit data to the client. WIA has three main components: Device Manager, Minidriver Service Library and Device Minidriver.

Device Manager: Enumerates the image device, get the device, establishes events and creates device objects for the device; MiniDriver Service Library: Performs all devices unrelated services; Device Minidriver interprets the mapping: WIA properties and commands to specific devices. Second, use WIA1. Selecting the device application can select the device either in a WIA built-in dialog or a user interface of WIA. The following program pops up a WIA selection device dialog:

#include

#pragma comment (lib, "WiaGuid.lib") int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {HRESULT hResult; IWiaItem * pItemRoot; IWiaDevMgr * pWiaDevMgr; CoInitialize (NULL); __try {// Create WIA Device Manager instance pWiaDevMgr = NULL; hResult = CoCreateInstance (CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void **) & pWiaDevMgr); if (hResult = S_OK!) {MessageBox (NULL, "Error:. CoCreateInstance ()", NULL , MB_ICONSTOP); __leave;} // Display a WIA select device dialog pItemRoot = NULL; hResult = pWiaDevMgr-> SelectDeviceDlg (NULL, 0, WIA_SELECT_DEVICE_NODEFAULT, NULL, & pItemRoot); // User canceled if (hResult == S_FALSE) {MessageBox (NULL, "User Canceled.", NULL, MB_ICONICONFORMATION; __LEAVE;} // no device available else f (hresult == wiA_s_no_device_available) {MessageBox (NULL, "NO Device Available.", NULL, MB_ICONICONFORMATION; __LEVE;} // ok, then ........} __finally {// Release COM interface. If (piteMroot) PiteMroot > Release (); if (pwiadevmgr) PWIADEVMGR-> Release (); couninitialize ();} returnit;} 2. Getting images to the file WIA acquisition image is very simple, call iwiadevmgr :: getimagedlg (), it integrates the Select Device and SELECT Image dialog box, which will automatically appear a progress instruction dialog box when sending images, below is an example :

// ... // Create WIA Device Manager object.hResult = CoCreateInstance (CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void **) & pWiaDevMgr);. If (hResult == S_OK) {// Get a image hResult = pWiaDevMgr -> getImagedlg (hwnd, 0, wi_device_dialog_single_image, wi_intent_maximize_quality, null, wszfilename, & guidformat); // ......} // ... but due to iwiadevmgr :: getImagedlg () is in the form of a picture file If you return data, sometimes you don't meet our needs. At this time, we need to use the iWiaDataTratransfer interface to transfer images. 3. Getting image data in memory After iwiadevmgr :: selectDevicedlg (), you can use the iWiaItem :: DeviceDlg () method of the rootItem :: DeviceDlg () method it returns to display a dialog to browse the picture in the WIA device, please see the example below:

// ...... // Display a WIA dialog box to the user to prepare for image acquisition.hResult = pRootItem-> DeviceDlg (hWnd, 0, WIA_INTENT_MAXIMIZE_QUALITY, & cItem, & ppWiaItems); if (hResult == S_OK) { For (i = 0; i

IwiaItem :: Devicedlg () Returns the total number of pictures selected and the WiaItem pointer for each image, we can use the iWiaDataTaSfer interface to transfer images. Before transferring each WiAItem data, you should call the IID_IWIAPROPERTYSTORAGE interface to set the appropriate properties:

// ...... // Get the IWiaPropertyStorage interface so we can set required properties.hResult = pWiaItem-> QueryInterface (IID_IWiaPropertyStorage, (void **) & pWiaPropertyStorage); if (hResult == S_OK) {// Prepare PROPSPECs and PROPVARIANTs for setting the media type and format psPropSpec [0] .ulKind = PRSPEC_PROPID;. psPropSpec [0] .propid = WIA_IPA_FORMAT; psPropSpec [1] .ulKind = PRSPEC_PROPID; psPropSpec [1] .propid = WIA_IPA_TYMED; guidOutputFormat = WiaImgFmt_MEMORYBMP; pvPropVariant [0] .vt = VT_CLSID; pvPropVariant [0] .puuid = & guidOutputFormat; pvPropVariant [1] .vt = VT_I4; pvPropVariant [1] .lVal = TYMED_CALLBACK; // Set the properties hResult = pWiaPropertyStorage-> WriteMultiple (sizeof. (pvpropvariant) / sizeof (pvpropvariant [0]), pspropspec, pvpropvariant, wia_ipa_first); // ......} // ...... If we transfer data with the iWiaDataTransfer interface, we also need to write code Iwiadatacallback interface, where data can be received in our iWiaDataCallback :: bandedDatacallback (), for example:

// [Summary] Recieve data transfer status notifications.HRESULT CALLBACK CWiaDataCallback :: BandedDataCallback (LONG lMessage, LONG lStatus, LONG lPercentComplete, LONG lOffset, LONG lLength, LONG lReserved, LONG lResLength, BYTE * pbData) {PWIA_DATA_CALLBACK_HEADER pHeader = NULL; switch (lMessage) {case IT_MSG_DATA_HEADER:.. // The data header contains the image's final size pHeader = (PWIA_DATA_CALLBACK_HEADER) pbData; if ((pHeader) && (pHeader-> lBufferSize)) {// Save the buffer size m_nBufferLength = pHeader- > lBufferSize; // Allocate a block of memory to hold the image m_pBuffer = (PBYTE) HeapAlloc (GetProcessHeap (), 0, m_nBufferLength); if (m_pBuffer == NULL) return S_FALSE;} break; case IT_MSG_DATA:. // Make Sure A Block of Memory Has Been Created. IF (m_pbuffer) {// Copy The New Band. CopyMemory (M_PBuffer Lof . Fset, pbData, lLength); // Increment the counter m_nBytesTransfered = lLength;} break; case IT_MSG_TERMINATION: // Notify that we complete to recive a image break; default:. Break;} return S_OK;} Then, we You can use the iWiaDataTransfer interface to transfer data:

// ... // Create our callback class.pCallback = new CWiaDataCallback (hWnd); if (pCallback) {// Get the IWiaDataCallback interface from our callback class hResult = pCallback-> QueryInterface (IID_IWiaDataCallback, (void **). & pWiaDataCallback); if (hResult == S_OK) {// Perform the transfer wdtiTransferInfo.ulSize = sizeof (WIA_DATA_TRANSFER_INFO);. hResult = pWiaDataTransfer-> idtGetBandedData (& wdtiTransferInfo, pWiaDataCallback); // ......} //. .....} // ...... Three, WIA is WINDOWS ME and its future operating system, Windows 98/2000 does not support WIA, so you need to be on a newer version of MSDN Library There is a WIA document in the middle. WIA 1.0 in MSDN's documentation address is: http://msdn.microsoft.com/library/default.asp? URL = / library / en-us / wia / wi / overviews / startpage.asp, or by directory: MSDN Library -> Graphics and Multimedia -> Windows Image Get -> WIA 1.0. In addition, because there is no WIA library in Visual C 6.0, you need to compile the WIA program using Visual Studio.net 2002/2003. See WIA Assistant Library I wrote: Wiahelper - WIA Assistant Library

转载请注明原文地址:https://www.9cbs.com/read-94360.html

New Post(0)