📄 wiahelpers.cpp
字号:
if(SUCCEEDED(hr))
{
LONG lSheetFeederRegistration = LEFT_JUSTIFIED;
hr = PropertyManager.AddProperty(WIA_IPS_SHEET_FEEDER_REGISTRATION ,WIA_IPS_SHEET_FEEDER_REGISTRATION_STR ,RN,lSheetFeederRegistration);
}
if(SUCCEEDED(hr))
{
//
// Just basic duplex mode supported (no single back side scan):
//
LONG lDocumentHandlingSelect = FEEDER;
LONG lDocumentHandlingSelectValidValues = FEEDER|DUPLEX;
hr = PropertyManager.AddProperty(WIA_IPS_DOCUMENT_HANDLING_SELECT ,WIA_IPS_DOCUMENT_HANDLING_SELECT_STR ,RWF,lDocumentHandlingSelect,lDocumentHandlingSelectValidValues);
}
if(SUCCEEDED(hr))
{
LONG lMaxPages = 100;
LONG lDefaultPagesSetting = 1;
LONG lPages = 1;
hr = PropertyManager.AddProperty(WIA_IPS_PAGES ,WIA_IPS_PAGES_STR ,RWR,lDefaultPagesSetting,lDefaultPagesSetting,0,lMaxPages,lPages);
}
//
// For the Feeder item implement support for WIA_IPS_PAGE_SIZE (just AUTO supported for now,
// in a real case standard and possibly document sizes would have to be added here):
//
if (SUCCEEDED(hr))
{
LONG lAutoPageSize = WIA_PAGE_AUTO;
hr = PropertyManager.AddProperty(WIA_IPS_PAGE_SIZE, WIA_IPS_PAGE_SIZE_STR, RN, lAutoPageSize);
CBasicDynamicArray<LONG> lPageSizeArray;
lPageSizeArray.Append(WIA_PAGE_AUTO);
hr = PropertyManager.AddProperty(WIA_IPS_PAGE_SIZE, WIA_IPS_PAGE_SIZE_STR, RWL, lPageSizeArray[0], lPageSizeArray[0], &lPageSizeArray);
}
}
if(SUCCEEDED(hr))
{
LONG lCurrentIntent = WIA_INTENT_NONE;
LONG lCurrentIntentValidValues = WIA_INTENT_IMAGE_TYPE_COLOR | WIA_INTENT_MINIMIZE_SIZE | WIA_INTENT_MAXIMIZE_QUALITY;
hr = PropertyManager.AddProperty(WIA_IPS_CUR_INTENT ,WIA_IPS_CUR_INTENT_STR ,RWF,lCurrentIntent,lCurrentIntentValidValues);
}
if(SUCCEEDED(hr))
{
GUID guidItemCategory = WIA_CATEGORY_FLATBED;
switch(uiResourceID)
{
case IDB_FLATBED:
guidItemCategory = WIA_CATEGORY_FLATBED;
break;
case IDB_FEEDER:
guidItemCategory = WIA_CATEGORY_FEEDER;
break;
case IDB_FILM:
guidItemCategory = WIA_CATEGORY_FILM;
break;
default:
guidItemCategory = GUID_NULL;
break;
}
hr = PropertyManager.AddProperty(WIA_IPA_ITEM_CATEGORY,WIA_IPA_ITEM_CATEGORY_STR,RN,guidItemCategory);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<LONG> lXResolutionArray;
lXResolutionArray.Append(lXResolution);
hr = PropertyManager.AddProperty(WIA_IPS_XRES ,WIA_IPS_XRES_STR ,RWLC,lXResolutionArray[0],lXResolutionArray[0],&lXResolutionArray);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<LONG> lYResolutionArray;
lYResolutionArray.Append(lYResolution);
hr = PropertyManager.AddProperty(WIA_IPS_YRES ,WIA_IPS_YRES_STR ,RWLC,lYResolutionArray[0],lYResolutionArray[0],&lYResolutionArray);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_XPOS ,WIA_IPS_XPOS_STR ,RWRC,lXPosition,lXPosition,lXPosition,lXPosition + (lXExtent - 1),1);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_YPOS ,WIA_IPS_YPOS_STR ,RWRC,lYPosition,lYPosition,lYPosition,lYPosition + (lYExtent - 1),1);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_XEXTENT ,WIA_IPS_XEXTENT_STR , RWRC,lXExtent,lXExtent,1,lXExtent,1);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_YEXTENT ,WIA_IPS_YEXTENT_STR ,RWRC,lYExtent,lYExtent,1,lYExtent,1);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<LONG> lRotationArray;
lRotationArray.Append(PORTRAIT);
lRotationArray.Append(LANSCAPE);
lRotationArray.Append(ROT180);
lRotationArray.Append(ROT270);
hr = PropertyManager.AddProperty(WIA_IPS_ROTATION ,WIA_IPS_ROTATION_STR ,RWLC,lRotationArray[0],lRotationArray[0],&lRotationArray);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_DESKEW_X ,WIA_IPS_DESKEW_X_STR ,RWRC,0,0,0,lXExtent,1);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.AddProperty(WIA_IPS_DESKEW_Y ,WIA_IPS_DESKEW_Y_STR ,RWRC,0,0,0,lYExtent,1);
}
if(SUCCEEDED(hr))
{
LONG lBrightness = 0;
hr = PropertyManager.AddProperty(WIA_IPS_BRIGHTNESS,WIA_IPS_BRIGHTNESS_STR,RWRC,lBrightness,lBrightness,-1000,1000,1);
}
if(SUCCEEDED(hr))
{
LONG lContrast = 0;
hr = PropertyManager.AddProperty(WIA_IPS_CONTRAST ,WIA_IPS_CONTRAST_STR ,RWRC,lContrast,lContrast,-1000,1000,1);
}
if(SUCCEEDED(hr) && ((IDB_FILM == uiResourceID) || (IDB_FLATBED == uiResourceID)))
{
LONG lSegmentation = (IDB_FLATBED == uiResourceID) ? WIA_USE_SEGMENTATION_FILTER : WIA_DONT_USE_SEGMENTATION_FILTER;
hr = PropertyManager.AddProperty(WIA_IPS_SEGMENTATION ,WIA_IPS_SEGMENTATION_STR ,RN, lSegmentation);
}
if(SUCCEEDED(hr))
{
LONG lErrorHandler = ERROR_HANDLING_NONE;
LONG lErrorHandlerValidValues = ERROR_HANDLING_WARMING_UP | ERROR_HANDLING_COVER_OPEN | ERROR_HANDLING_PRIVATE_ERROR | ERROR_HANDLING_UNHANDLED_STATUS | ERROR_HANDLING_UNHANDLED_ERROR;
hr = PropertyManager.AddProperty(MY_WIA_ERROR_HANDLING_PROP ,MY_WIA_ERROR_HANDLING_PROP_STR ,RWF,lErrorHandler,lErrorHandlerValidValues);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<LONG> lTestFilterArray;
lTestFilterArray.Append(0);
lTestFilterArray.Append(1);
hr = PropertyManager.AddProperty(MY_TEST_FILTER_PROP ,MY_TEST_FILTER_PROP_STR ,RWLC,lTestFilterArray[0],lTestFilterArray[0],&lTestFilterArray);
}
if(SUCCEEDED(hr))
{
LONG lItemSize = 0;
hr = PropertyManager.AddProperty(WIA_IPA_ITEM_SIZE ,WIA_IPA_ITEM_SIZE_STR ,RN,lItemSize);
}
if(SUCCEEDED(hr))
{
// TBD: This property is assuming that the source image is color. Should be changed to be
// more dynamic.
CBasicDynamicArray<LONG> lDataTypeArray;
lDataTypeArray.Append(WIA_DATA_COLOR);
hr = PropertyManager.AddProperty(WIA_IPA_DATATYPE ,WIA_IPA_DATATYPE_STR ,RWL,lDataTypeArray[0],lDataTypeArray[0],&lDataTypeArray);
}
if(SUCCEEDED(hr))
{
// TBD: This property is assuming that the source image is 24-bit color. Should be changed to be
// more dynamic.
CBasicDynamicArray<LONG> lBitDepthArray;
lBitDepthArray.Append(24);
hr = PropertyManager.AddProperty(WIA_IPA_DEPTH ,WIA_IPA_DEPTH_STR ,RWLC,lBitDepthArray[0],lBitDepthArray[0],&lBitDepthArray);
}
if(SUCCEEDED(hr))
{
GUID guidPreferredFormat = WiaImgFmt_BMP;
hr = PropertyManager.AddProperty(WIA_IPA_PREFERRED_FORMAT ,WIA_IPA_PREFERRED_FORMAT_STR ,RN,guidPreferredFormat);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<GUID> guidFormatArray;
guidFormatArray.Append(WiaImgFmt_BMP);
guidFormatArray.Append(WiaImgFmt_RAW);
hr = PropertyManager.AddProperty(WIA_IPA_FORMAT ,WIA_IPA_FORMAT_STR ,RWL,guidFormatArray[0],guidFormatArray[0],&guidFormatArray);
}
if(SUCCEEDED(hr))
{
LONG lCompression = WIA_COMPRESSION_NONE;
hr = PropertyManager.AddProperty(WIA_IPA_COMPRESSION ,WIA_IPA_COMPRESSION_STR ,RN,lCompression);
}
if(SUCCEEDED(hr))
{
CBasicDynamicArray<LONG> lTymedArray;
lTymedArray.Append(TYMED_FILE);
hr = PropertyManager.AddProperty(WIA_IPA_TYMED ,WIA_IPA_TYMED_STR ,RWL,lTymedArray[0],lTymedArray[0],&lTymedArray);
}
if(SUCCEEDED(hr))
{
// TBD: This property is assuming that the source image is 24-bit color and has 3 channels. Should be changed to be
// more dynamic.
LONG lChannelsPerPixel = 3;
hr = PropertyManager.AddProperty(WIA_IPA_CHANNELS_PER_PIXEL ,WIA_IPA_CHANNELS_PER_PIXEL_STR ,RN,lChannelsPerPixel);
}
if(SUCCEEDED(hr))
{
// TBD: This property is assuming that the source image is 24-bit color and has 8 bits per channel. Should be changed to be
// more dynamic.
LONG lBitsPerChannel = 8;
hr = PropertyManager.AddProperty(WIA_IPA_BITS_PER_CHANNEL ,WIA_IPA_BITS_PER_CHANNEL_STR ,RN,lBitsPerChannel);
}
if(SUCCEEDED(hr))
{
//
// According with the limited type of input image data we use in this sample
// we'll initialize this property for 24-bit color / 3 channels RGB image data.
// (see also above the initialization of WIA_IPA_CHANNELS_PER_PIXEL and WIA_IPA_BITS_PER_CHANNEL)
// A real solution may need however to consider more than just this single format:
//
BYTE bBitsPerChannel[] = { 8, 8, 8 };
hr = PropertyManager.AddProperty(WIA_IPA_RAW_BITS_PER_CHANNEL, WIA_IPA_RAW_BITS_PER_CHANNEL_STR, RN, &bBitsPerChannel[0], 3);
}
if(SUCCEEDED(hr))
{
//
// WIA_IPS_PHOTOMETRIC_INTERP is needed for the Raw transfer format:
//
LONG lPhotometricInterp = WIA_PHOTO_WHITE_1;
hr = PropertyManager.AddProperty(WIA_IPS_PHOTOMETRIC_INTERP, WIA_IPS_PHOTOMETRIC_INTERP_STR, RN, lPhotometricInterp);
}
if(SUCCEEDED(hr))
{
LONG lPlanar = WIA_PACKED_PIXEL;
hr = PropertyManager.AddProperty(WIA_IPA_PLANAR ,WIA_IPA_PLANAR_STR ,RN,lPlanar);
}
if(SUCCEEDED(hr))
{
LONG lPixelsPerLine = lXExtent;
hr = PropertyManager.AddProperty(WIA_IPA_PIXELS_PER_LINE ,WIA_IPA_PIXELS_PER_LINE_STR ,RN,lPixelsPerLine);
}
if(SUCCEEDED(hr))
{
LONG lNumberOfLines = lYExtent;
hr = PropertyManager.AddProperty(WIA_IPA_NUMBER_OF_LINES ,WIA_IPA_NUMBER_OF_LINES_STR ,RN,lNumberOfLines);
}
if(SUCCEEDED(hr))
{
// TBD: A small buffer size was used here to allow slower transfers with more progress. Real
// drivers should use a higher value to increase performance.
LONG lBufferSize = DEFAULT_BUFFER_SIZE;
hr = PropertyManager.AddProperty(WIA_IPA_BUFFER_SIZE ,WIA_IPA_BUFFER_SIZE_STR ,RN,lBufferSize);
}
if(SUCCEEDED(hr))
{
BSTR bstrFileExtension = SysAllocString(L"BMP");
if(bstrFileExtension)
{
hr = PropertyManager.AddProperty(WIA_IPA_FILENAME_EXTENSION ,WIA_IPA_FILENAME_EXTENSION_STR ,RN,bstrFileExtension);
SysFreeString(bstrFileExtension);
bstrFileExtension = NULL;
}
else
{
hr = E_OUTOFMEMORY;
WIAS_ERROR((g_hInst, "Could not allocate the file name extension property value, hr = 0x%lx.",hr));
}
}
if(SUCCEEDED(hr))
{
GUID guidStreamCompatID = GUID_NULL;
hr = PropertyManager.AddProperty(WIA_IPA_PROP_STREAM_COMPAT_ID,WIA_IPA_PROP_STREAM_COMPAT_ID_STR,RN,guidStreamCompatID);
}
if(SUCCEEDED(hr))
{
hr = PropertyManager.SetItemProperties(pWiasContext);
if(FAILED(hr))
{
WIAS_ERROR((g_hInst, "CWIAPropertyManager::SetItemProperties failed to set WIA flatbed item properties, hr = 0x%lx",hr));
}
}
}
else
{
WIAS_ERROR((g_hInst, "Failed to obtain valid information from flatbed bitmap file resource to build a WIA property set"));
}
}
else
{
WIAS_ERROR((g_hInst, "Failed to obtain driver item context data"));
}
}
else
{
WIAS_ERROR((g_hInst, "Invalid parameters were passed"));
}
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -