IWiaSegmentationFilter::D etectRegions 方法
确定平面板上布局的图像的子区域,以便每个子区域都可以获取到单独的图像项中。
语法
HRESULT DetectRegions(
[in] LONG lFlags,
[in] IStream *pInputStream,
[in] IWiaItem2 *pWiaItem2
);
参数
-
lFlags [in]
-
类型: LONG
当前未使用。 应设置为零。
-
pInputStream [in]
-
类型: IStream*
指定指向 IStream 预览图像的指针。
-
pWiaItem2 [in]
-
类型: IWiaItem2*
指定指向获取 pInputStream 的 IWiaItem2 项的指针。 分段筛选器为此项创建子项。
返回值
类型: HRESULT
如果此方法成功,则返回 S_OK。 否则,它将返回 HRESULT 错误代码。
注解
此方法确定 pInputStream 表示的图像的子区域。 对于检测到的每个子区域,它会为 pWiaItem2 参数中指定的 IWiaItem2 项创建子项。 对于每个子项,分段筛选器必须使用以下 扫描程序 WIA 项属性常量设置要扫描的区域边界矩形的值。
如果驱动程序支持反倾斜,则更高级的筛选器还可能需要其他 扫描程序 WIA 项属性常量 ,例如 WIA_IPS_DESKEW_X 和 WIA_IPS_DESKEW_Y。
如果应用程序多次调用 IWiaSegmentationFilter::D etectRegions ,则应用程序必须首先删除上次调用 IWiaSegmentationFilter::D etectRegions 创建的子项。
如果应用程序将任何属性更改为 pWiaItem2,在将映像获取到 pInputStream 及其对 IWiaSegmentationFilter::D etectRegions 的调用之间,原始属性 (即必须还原获取流时项的属性) 。 这可以通过 GetPropertyStream 和 SetPropertyStream 完成。
如果应用程序多次将同一流传递给分段筛选器,则应用程序必须重置 IStream 。 应用程序还必须在初始下载之后以及调用 IWiaSegmentationFilter::D etectRegions 之前重置流。
示例
分段对传入 DetectSubregion 的流执行区域检测 (pImageStream
) 。 请参阅此示例中使用的 CreateSegmentationFilter 方法的 GetExtension 。
HRESULT
DetectSubregions(
IN IStream *pImageStream,
IN IWiaItem2 *pWiaItem2)
{
HRESULT hr = S_OK;
IWiaSegmentationFilter* pSegmentationFilter = NULL;
if (!pWiaItem2 || !pImageStream)
{
hr = E_INVALIDARG;
}
if (SUCCEEDED(hr))
{
hr = CreateSegmentationFilter(pWiaItem2, &pSegmentationFilter);
}
if (SUCCEEDED(hr))
{
hr = pSegmentationFilter->DetectRegions(0,pImageStream, pWiaItem2);
}
if (pSegmentationFilter)
{
pSegmentationFilter->Release();
pSegmentationFilter = NULL;
}
return hr;
}
DownloadPreviewImage 通过调用预览组件的 GetNewPreview 方法从扫描程序下载图像数据。 然后,如果应用程序用户想要调用分段筛选器,它会为检测到的每个区域调用 DetectSubregion,该筛选器会在 pWiaItem2 下创建子项。 有关此示例中使用的 DetectSubregions 方法,请参阅 IWiaSegmentationFilter::D etectRegions 。
在此示例中,应用程序用户通过单击复选框来设置 m_bUseSegmentationFilter
。 如果应用程序支持此功能,应首先通过调用 CheckExtension 来检查驱动程序是否具有分段筛选器。 有关 CheckImgFilter 方法示例,请参阅 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);
}
//
// Check the application UI for whether the user wants
// to use the segmentation filter indicated by the value
// of m_bUseSegmentationFilter.
//
// 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;
}
要求
要求 | 值 |
---|---|
最低受支持的客户端 |
Windows Vista [仅限桌面应用] |
最低受支持的服务器 |
Windows Server 2008 [仅限桌面应用] |
标头 |
|
IDL |
|