public void SetProperties(
object item,
WiaProperties properties
)
item
Handle to the item having its properties set. Retrieve this parameter by either calling the GetRootItem method to get the device's root item or by enumerating the child items of the device through a call to the EnumChildItems method.
properties
The properties to set.
Add the SetPropertiesEvent event to be informed of any error codes returned from setting each property available in the WiaProperties structure, and to have the ability to cancel the process.
Note: |
If the ShowUserInterface flag is set for any of the acquire methods, then be aware that some of the previously set/changed user properties (using any of the SetPropertyXxx or SetProperties methods) will be overwritten by the Microsoft's image acquisition dialog box. Microsoft's image acquisition dialog box sets its own initialization properties like the current intent (image type), selected area (left, top, width and height), paper source and duplex mode, etc.
To suppress the manufacturer's image acquisition dialog and acquire directly from the specified source item through the item parameter using the values set through the SetPropertyXxx and SetProperties methods, do not set the ShowUserInterface flag. |
For more information, refer to Managing WIA Sources.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Wia;
WiaSession wiaSession;
public void GetRootItemExample(IntPtr parent)
{
if (!WiaSession.IsAvailable(WiaVersion.Version1))
{
Console.WriteLine("WIA version 1.0 not installed.");
return;
}
wiaSession = new WiaSession();
wiaSession.Startup(WiaVersion.Version1);
DialogResult res = wiaSession.SelectDeviceDlg(parent, WiaDeviceType.Default, WiaSelectSourceFlags.NoDefault);
if (res != DialogResult.OK)
{
Console.WriteLine("Error selecting WIA device.");
wiaSession.Shutdown();
return;
}
object rootItem = wiaSession.GetRootItem(null);
if (rootItem != null)
{
wiaSession.EnumItemsEvent += new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent);
wiaSession.EnumChildItems(rootItem);
wiaSession.EnumItemsEvent -= new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent);
}
wiaSession.Shutdown();
}
void wiaSession_EnumItemsEvent(object sender, WiaEnumItemsEventArgs e)
{
if (e.Item != null)
{
WiaDataTransferProperties dataTransfer = WiaDataTransferProperties.Empty;
WiaImageEffectsProperties imageEffects = WiaImageEffectsProperties.Empty;
WiaProperties properties = wiaSession.GetProperties(e.Item);
dataTransfer.ImageDataType = WiaImageDataType.Grayscale;
imageEffects.Brightness = 250;
properties.DataTransfer = dataTransfer;
properties.ImageEffects = imageEffects;
properties.ScanningMode = WiaScanningModeFlags.Feeder; // set scanning source to Feeder
properties.MaximumNumberOfPages = 0; // scan all pages in feeder
properties.ImageType = WiaImageType.Grayscale;
properties.Orientation = WiaOrientation.Portrait;
WiaImageResolutionProperties imageResolution = properties.ImageResolution;
imageResolution.BitsPerPixel = 8;
imageResolution.HorizontalResolution = 600;
imageResolution.VerticalResolution = 600;
properties.ImageResolution = imageResolution;
wiaSession.SetPropertiesEvent += new EventHandler<WiaSetPropertiesEventArgs>(wiaSession_SetPropertiesEvent);
wiaSession.SetProperties(e.Item, properties);
wiaSession.SetPropertiesEvent -= new EventHandler<WiaSetPropertiesEventArgs>(wiaSession_SetPropertiesEvent);
wiaSession.FreeItem(e.Item);
}
}
void wiaSession_SetPropertiesEvent(object sender, WiaSetPropertiesEventArgs e)
{
if (e.Error <= 0)
{
Console.WriteLine("Failed to set the below property:\n\tProperty Id: {0}\n\tProperty Value: {1}\n\tError: {2}\n\n", e.PropertyId.ToString(), e.Value.ToString(), e.Error.ToString());
}
}