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.
Asked
Active
Viewed 406 times
0
-
1Some of your code may help to solve your problem. – Adam Sep 18 '14 at 16:17
1 Answers
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

Hans-Martin Goebel
- 532
- 4
- 15