DownloadPreviewImage 函式會呼叫預覽元件的 IWiaPreview::GetNewPreview 方法,從掃描儀下載影像數據。 然後,如果應用程式使用者想要叫用分割篩選器,它會呼叫 DetectSubregions 函式,這會針對偵測到的每個區域,在 pWiaItem2 底 下建立子專案。 如需 DetectSubregions的相關資訊,請參閱 IWiaSegmentationFilter::DetectRegions 方法。
在此範例中,應用程式使用者按下複選框來設定 m_bUseSegmentationFilter 參數。 如果應用程式支援此功能,它應該先呼叫 IWiaItem2::CheckExtension來檢查驅動程式是否有分割篩選。 如需了解在此範例中使用的 CheckImgFilter的相關信息,請參閱 Microsoft Windows SDK 檔案中的 IWiaPreview::GetNewPreview 方法。
HRESULT
DownloadPreviewImage(
IN IWiaItem2 *pWiaFlatbedItem2)
{
HRESULT hr = S_OK;
BOOL bHasImgFilter = FALSE;
IWiaTransferCallback *pAppWiaTransferCallback = NULL;
hr = CheckImgFilter(pWiaFlatbedItem2, &bHasImgFilter)
if (SUCCEEDED(hr))
{
if (bHasImgFilter)
{
IWiaPreview *pWiaPreview = NULL;
// In this example, the AppWiaTransferCallback class
// implements the IWiaTransferCallback interface.
// The constructor of AppWiaTransferCallback sets the
// reference count to 1.
pAppWiaTransferCallback = new AppWiaTransferCallback();
hr = pAppWiaTransferCallback ? S_OK : E_OUTOFMEMORY;
if (SUCCEEDED(hr))
{
// Acquire image from scanner
hr = m_pWiaPreview->GetNewPreview(pWiaFlatbedItem2,
0,
pAppWiaTransferCallback);
}
// m_FlatbedPreviewStream is the stream that
// AppWiaTransferCallback::GetNextStream returned for the
// flatbed item.
// This stream is where the image data is stored after
// the successful return of GetNewPreview.
// The stream is passed into the segmentation filter
// for region detection.
if (SUCCEEDED(hr) && m_bUseSegmentationFilter)
{
DetectSubregions(m_FlatbedPreviewStream, pWiaFlatbedItem2);
}
if (pAppWiaTransferCallback)
{
// If the call to GetNewPreview was successful, the
// preview component calls AddRef on the callback so
// this call doesn't delete the object.
pAppWiaTransferCallback->Release();
}
}
else
{
// Do not create an instance of preview component if the
// driver does not come with an image-processing filter.
// You can use a segmentation filter, however, if the driver
// comes with one (omitted here).
}
}
return hr;
}