Leadtools.Wia Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
GetPropertyBuffer Method
See Also  Example
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 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 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 Sub GetPropertyBuffer( _
   ByVal item As Object, _
   ByVal propertyIdName As String, _
   ByVal propertyId As WiaPropertyId _
) 
Visual Basic (Usage)Copy Code
Dim instance As WiaSession
Dim item As Object
Dim propertyIdName As String
Dim propertyId As WiaPropertyId
 
instance.GetPropertyBuffer(item, propertyIdName, propertyId)
C# 
public void GetPropertyBuffer( 
   object item,
   string propertyIdName,
   WiaPropertyId propertyId
)
C++/CLI 
public:
void 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 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.

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)
   RasterCodecs.Startup()

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

   myWiaSession.GetRootItem(Nothing)
   If Not myWiaSession.RootItem Is Nothing Then
      AddHandler myWiaSession.EnumItemsEvent, AddressOf session_EnumItemsEvent2

      myWiaSession.EnumChildItems(myWiaSession.RootItem)

      RemoveHandler myWiaSession.EnumItemsEvent, AddressOf session_EnumItemsEvent2
   End If

   myWiaSession.Shutdown()
   RasterCodecs.Shutdown()
End Sub

Private Sub session_EnumItemsEvent2(ByVal sender As Object, ByVal e As WiaEnumItemsEventArgs)
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim thumbImage As RasterImage = Nothing
   Dim nWidth As Int32 = 0
   Dim nHeight As Int32 = 0

   If Not e.Item Is Nothing Then
      ' Read the camera item thumbnail property.
      myWiaSession.GetPropertyBuffer(e.Item, Nothing, WiaPropertyId.CameraItemThumbnail)

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

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

      Dim buffer As Byte() = Nothing
      Dim userData As IntPtr = New IntPtr()

      myWiaSession.BufferValue.Write(buffer, 0, CInt(myWiaSession.BufferValue.Length))
      Dim userDataLen As Int32 = CInt(myWiaSession.BufferValue.Length)
      Marshal.Copy(buffer, 0, userData, userDataLen)

      thumbImage = New RasterImage(RasterMemoryFlags.User, nWidth, nHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.LeftTop, Nothing, userData, userDataLen)

      If Not thumbImage Is Nothing Then
              codecs.Save(thumbImage, LeadtoolsExamples.Common.ImagesPath.Path + "WiaThumb.jpg", RasterImageFormat.Jpeg, 24)
      End If

      myWiaSession.FreeItem(e.Item)
   End If
End Sub
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); 
   RasterCodecs.Startup(); 
 
   DialogResult res = myWiaSession.SelectDeviceDlg(parent, WiaDeviceType.StreamingVideo, WiaSelectSourceFlags.NoDefault); 
   if (res != DialogResult.OK) 
   { 
      MessageBox.Show("Error selecting WIA device."); 
      myWiaSession.Shutdown(); 
      RasterCodecs.Shutdown(); 
      return; 
   } 
 
   myWiaSession.GetRootItem(null); 
   if (myWiaSession.RootItem != null) 
   { 
      myWiaSession.EnumItemsEvent += new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent2); 
 
      myWiaSession.EnumChildItems(myWiaSession.RootItem); 
 
      myWiaSession.EnumItemsEvent -= new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent2); 
   } 
 
   myWiaSession.Shutdown(); 
   RasterCodecs.Shutdown(); 

 
void wiaSession_EnumItemsEvent2(object sender, WiaEnumItemsEventArgs e) 

   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage thumbImage = null; 
   Int32 nWidth = 0; 
   Int32 nHeight = 0; 
 
   if(e.Item != null) 
   { 
      // Read the camera item thumbnail property. 
      myWiaSession.GetPropertyBuffer(e.Item, null, WiaPropertyId.CameraItemThumbnail); 
 
      // Read the camera thumbnail width property. 
      myWiaSession.GetPropertyLong(e.Item, null, WiaPropertyId.CameraItemThumbWidth); 
      nWidth = myWiaSession.LongValue; 
 
      // Read the camera thumbnail height property. 
      myWiaSession.GetPropertyLong(e.Item, null, WiaPropertyId.CameraItemThumbHeight); 
      nHeight = myWiaSession.LongValue; 
 
      byte[] buffer = null; 
      IntPtr userData = new IntPtr(); 
 
      myWiaSession.BufferValue.Write(buffer, 0, (int)myWiaSession.BufferValue.Length); 
      Int32 userDataLen = (Int32)myWiaSession.BufferValue.Length; 
      Marshal.Copy(buffer, 0, userData, userDataLen); 
 
      thumbImage = new RasterImage(RasterMemoryFlags.User,  
                                   nWidth,  
                                   nHeight,  
                                   24,  
                                   RasterByteOrder.Bgr,  
                                   RasterViewPerspective.LeftTop,  
                                   null, 
                                   userData, 
                                   userDataLen); 
 
      if(thumbImage != null) 
      { 
         codecs.Save(thumbImage, LeadtoolsExamples.Common.ImagesPath.Path + "WiaThumb.jpg", RasterImageFormat.Jpeg, 24); 
      } 
 
      myWiaSession.FreeItem(e.Item); 
   } 
}

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.

After calling this method the BufferValue property will become available for you to use to get the retrieved buffer.

For more information, refer to Managing WIA Sources.

Requirements

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

See Also