Ejemplo: DownloadPreviewImage
La función DownloadPreviewImage descarga datos de imagen del analizador mediante una llamada al método IWiaPreview::GetNewPreview del componente de vista previa. A continuación, llama a la función DetectSubregions si el usuario de la aplicación quiere invocar el filtro de segmentación, que crea un elemento secundario en pWiaItem2 para cada región que detecta. Para obtener información sobre DetectSubregions, que se usa en este ejemplo, vea el método IWiaSegmentationFilter::D etectRegions .
En este ejemplo, el usuario de la aplicación establece el parámetro m_bUseSegmentationFilter haciendo clic en una casilla. Si la aplicación lo admite, primero debe comprobar que el controlador tiene un filtro de segmentación mediante una llamada a IWiaItem2::CheckExtension. Para obtener información sobre CheckImgFilter, que se usa en este ejemplo, vea el método IWiaPreview::GetNewPreview en la documentación de Microsoft Windows SDK.
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;
}