如何将Wia缩略图转换为.net图像?如果我加载属性,我会得到一个Com-Object,但我现在不知道如何处理它。
答案 0 :(得分:1)
WIAitem Thumbnail属性是一个wia.vector对象,属性binarydata可以通过image.fromstream轻松转换为.net图像。这是代码:
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