WIA 是 Windows Image Acquisition 的簡稱,是一個圖形處理軟體。
基本介紹
- 中文名:WIA
- 外文名:Windows Image Acquisition
- 啟用設備:掃瞄器和數位相機
- 當前可用版本:WIA 1.0
Windows圖像採集
關於 WIA
WIA 架構
使用WIA
#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_ICONINFORMATION); __leave; } // No device available else if (hResult == WIA_S_NO_DEVICE_AVAILABLE) { MessageBox( NULL, "No device available.", NULL, MB_ICONINFORMATION); __leave; } // OK, Then .......... } __finally { // Release COM interface. if (pItemRoot) pItemRoot->Release(); if (pWiaDevMgr) pWiaDevMgr->Release(); CoUninitialize(); } return 0; }
WIA 獲取圖像非常簡單,直接調用 IWiaDevMgr::GetImageDlg(),它集成了 Select Device 和 Select Image 對話框,在傳送圖像的時候還會自動出現一個進度指示對話框,下面是一個例子:
// ...// 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, WIA_DEVICE_DIALOG_SINGLE_IMAGE, WIA_INTENT_MAXIMIZE_QUALITY, NULL, wszFilename, &guidFormat); // ...... }// ......
在 IWiaDevMgr::SelectDeviceDlg() 之後,可以用它返回的 RootItem 對象的 IWiaItem::DeviceDlg() 方法顯示一個對話框瀏覽 WIA 設備中圖片,請看下面的例子:
// ......// 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 < cItem; i++) { // ...... // ppWiaItems[i] } }// ......
// ......// 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); // ...... }// ......
// 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 + lOffset, 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; }
// ...// 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); // ...... } // ...... }// ......
後注
工業無線網路WIA
簡介
工業無線網路WIA技術主要套用於石油、石化、冶金、環保、污水處理等領域。