0

How can I convert Wia thumbnails to .net image? If I load the property I get an Com-Object, but I don't now how to handle it.

Fish Below the Ice
  • 1,273
  • 13
  • 23

1 Answers1

1

The WIAitem Thumbnail property is a wia.vector Object and the property binarydata can be easily converted to a .net image with image.fromstream. Here is the code:

Public Shared Function GetThumbnail(Item As WIA.Item) As Image

Dim Jpeg As WIA.ImageFile = Nothing

With Item

  If .Properties.Exists("Thumbnail Data") Then
    Dim Thumb As WIA.Vector
    Thumb = .Properties("Thumbnail Data").Value
    Jpeg = Thumb.ImageFile(CInt(.Properties("Thumbnail Width").Value), CInt(.Properties("Thumbnail Height").Value))
  End If
End With
If Jpeg IsNot Nothing Then
  Dim imageBytes As Byte() = Jpeg.FileData.BinaryData
  Using ms As New IO.MemoryStream(imageBytes)
    Dim img As Image = Image.FromStream(ms)
    ms.Close()
    Return img
  End Using
Else
  Return Nothing
End If

End Function