public Stream GetPropertyBuffer(
object item,
string propertyIdName,
WiaPropertyId propertyId
)
item
Handle to the item which represents the item having the property. You can retrieve this parameter by either calling the GetRootItem method to get the device's root item itself or by enumerating the child items of the device through a call to EnumChildItems method.
propertyIdName
This string should contain the equivalent property Id string for the WIA property ID. Use the GetPropertyIdString method to get this string for the property ID.
If you passed null for this parameter, then the WIA toolkit will use the property ID passed through the third parameter,
propertyId
The property ID for the value being sought. For a list of available property IDs, see WiaPropertyId.
This parameter is required only if the second parameter, propertyIdName, is null; otherwise, you can pass 0 for this parameter.
The WIA property buffer value.
Any WIA property of type WiaVariableTypes.UI1 or WiaVariableTypes.Vector (for example, WiaPropertyId.CameraItemThumbnail, WiaPropertyId.ScannerDevicePadColor , ...etc) returns a Stream. In order to retrieve this type of buffer you need to call the function GetPropertyBuffer.
For more information, refer to Managing WIA Sources.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Wia;
WiaSession myWiaSession;
public void GetPropertyBufferExample(IntPtr parent)
{
if (!WiaSession.IsAvailable(WiaVersion.Version1))
{
Console.WriteLine("WIA version 1.0 not installed.");
return;
}
myWiaSession = new WiaSession();
myWiaSession.Startup(WiaVersion.Version1);
DialogResult res = myWiaSession.SelectDeviceDlg(parent, WiaDeviceType.StreamingVideo, WiaSelectSourceFlags.NoDefault);
if (res != DialogResult.OK)
{
Console.WriteLine("Error selecting WIA device.");
myWiaSession.Shutdown();
return;
}
object rootItem = myWiaSession.GetRootItem(null);
if (rootItem != null)
{
myWiaSession.EnumItemsEvent += new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent2);
myWiaSession.EnumChildItems(rootItem);
myWiaSession.EnumItemsEvent -= new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent2);
}
myWiaSession.Shutdown();
}
void wiaSession_EnumItemsEvent2(object sender, WiaEnumItemsEventArgs e)
{
if (e.Item != null)
{
// Read the camera item thumbnail property.
Stream stream = myWiaSession.GetPropertyBuffer(e.Item, null, WiaPropertyId.CameraItemThumbnail);
// Read the camera thumbnail width property.
int nWidth = myWiaSession.GetPropertyLong(e.Item, null, WiaPropertyId.CameraItemThumbWidth);
// Read the camera thumbnail height property.
int nHeight = myWiaSession.GetPropertyLong(e.Item, null, WiaPropertyId.CameraItemThumbHeight);
int userDataLen = (int)stream.Length;
byte[] userData = new byte[userDataLen];
stream.Read(userData, 0, userDataLen);
using (RasterImage thumbImage = new RasterImage(
RasterMemoryFlags.User,
nWidth,
nHeight,
24,
RasterByteOrder.Bgr,
RasterViewPerspective.LeftTop,
null,
userData,
userDataLen))
{
using (RasterCodecs codecs = new RasterCodecs())
{
codecs.Save(thumbImage, Path.Combine(LEAD_VARS.ImagesDir, "WiaThumb.jpg"), RasterImageFormat.Jpeg, 24);
}
}
myWiaSession.FreeItem(e.Item);
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}