LEADTOOLS WIA (Leadtools.Wia assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.30
GetPropertyBuffer Method
See Also 
Leadtools.Wia Namespace > WiaSession Class : GetPropertyBuffer Method



item
Handle to the item which represents the item having the property. You can retrieve this parameter by either calling the WiaSession.GetRootItem method to get the device’s root item itself or by enumerating the child items of the device through a call to Leadtools.Wia.WiaSession.EnumChildItems method.
propertyIdName

This string should contain the equivalent property Id string for the WIA property ID. Use the see 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; otherwise this parameters will be used whether or not you passed valid property ID through the propertyId parameter

propertyId

The property ID for the value being sought, for 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.

item
Handle to the item which represents the item having the property. You can retrieve this parameter by either calling the WiaSession.GetRootItem method to get the device’s root item itself or by enumerating the child items of the device through a call to Leadtools.Wia.WiaSession.EnumChildItems method.
propertyIdName

This string should contain the equivalent property Id string for the WIA property ID. Use the see 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; otherwise this parameters will be used whether or not you passed valid property ID through the propertyId parameter

propertyId

The property ID for the value being sought, for 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.

Retrieves the buffer of type Stream for any WIA property of type WiaVariableTypes.UI1 or WiaVariableTypes.Vector .

Syntax

Visual Basic (Declaration) 
Public Function GetPropertyBuffer( _
   ByVal item As Object, _
   ByVal propertyIdName As String, _
   ByVal propertyId As WiaPropertyId _
) As Stream
Visual Basic (Usage)Copy Code
Dim instance As WiaSession
Dim item As Object
Dim propertyIdName As String
Dim propertyId As WiaPropertyId
Dim value As Stream
 
value = instance.GetPropertyBuffer(item, propertyIdName, propertyId)
C# 
public Stream GetPropertyBuffer( 
   object item,
   string propertyIdName,
   WiaPropertyId propertyId
)
C++/CLI 
public:
Stream^ GetPropertyBuffer( 
   Object^ item,
   String^ propertyIdName,
   WiaPropertyId propertyId
) 

Parameters

item
Handle to the item which represents the item having the property. You can retrieve this parameter by either calling the WiaSession.GetRootItem method to get the device’s root item itself or by enumerating the child items of the device through a call to Leadtools.Wia.WiaSession.EnumChildItems method.
propertyIdName

This string should contain the equivalent property Id string for the WIA property ID. Use the see 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; otherwise this parameters will be used whether or not you passed valid property ID through the propertyId parameter

propertyId

The property ID for the value being sought, for 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.

Return Value

The WIA property buffer value.

Example

Visual BasicCopy Code
Dim myWiaSession As WiaSession
   Public Sub GetPropertyBufferExample(ByVal parent As IWin32Window)
      If (Not WiaSession.IsAvailable(WiaVersion.Version1)) Then
         MessageBox.Show("WIA version 1.0 not installed.")
         Return
      End If

      myWiaSession = New WiaSession()
      myWiaSession.Startup(WiaVersion.Version1)

      Dim res As DialogResult = myWiaSession.SelectDeviceDlg(parent, WiaDeviceType.StreamingVideo, WiaSelectSourceFlags.NoDefault)
      If res <> DialogResult.OK Then
         MessageBox.Show("Error selecting WIA device.")
         myWiaSession.Shutdown()
         Return
      End If

      Dim rootItem As Object = myWiaSession.GetRootItem(Nothing)
      If Not rootItem Is Nothing Then
         AddHandler myWiaSession.EnumItemsEvent, AddressOf session_EnumItemsEvent2

         myWiaSession.EnumChildItems(rootItem)

         RemoveHandler myWiaSession.EnumItemsEvent, AddressOf session_EnumItemsEvent2
      End If

      myWiaSession.Shutdown()
   End Sub

   Private Sub session_EnumItemsEvent2(ByVal sender As Object, ByVal e As WiaEnumItemsEventArgs)
      If Not IsNothing(e.Item) Then
         ' Read the camera item thumbnail property.
         Dim stream As Stream = myWiaSession.GetPropertyBuffer(e.Item, Nothing, WiaPropertyId.CameraItemThumbnail)

         ' Read the camera thumbnail width property.
         Dim nWidth As Integer = myWiaSession.GetPropertyLong(e.Item, Nothing, WiaPropertyId.CameraItemThumbWidth)

         ' Read the camera thumbnail height property.
         Dim nHeight As Integer = myWiaSession.GetPropertyLong(e.Item, Nothing, WiaPropertyId.CameraItemThumbHeight)

         Dim userDataLen As Integer = CType(stream.Length, Integer)
         Dim userData(userDataLen - 1) As Byte
         stream.Read(userData, 0, userDataLen)

         Using thumbImage As New RasterImage( _
            RasterMemoryFlags.User, _
            nWidth, _
            nHeight, _
            24, _
            RasterByteOrder.Bgr, _
            RasterViewPerspective.LeftTop, _
            Nothing, _
            userData, _
            userDataLen)
            Using codecs As New RasterCodecs()
               codecs.Save(thumbImage, Path.Combine(LEAD_VARS.ImagesDir, "WiaThumb.jpg"), RasterImageFormat.Jpeg, 24)
            End Using
         End Using

         myWiaSession.FreeItem(e.Item)
      End If
   End Sub


Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
WiaSession myWiaSession;
   public void GetPropertyBufferExample(IWin32Window parent)
   {
      if (!WiaSession.IsAvailable(WiaVersion.Version1))
      {
         MessageBox.Show("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)
      {
         MessageBox.Show("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:\Users\Public\Documents\LEADTOOLS Images";
}

Remarks

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.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also