将wia项目属性“缩略图数据”转换为.net图像

时间:2014-09-18 15:59:11

标签: c# .net vb.net wia

如何将Wia缩略图转换为.net图像?如果我加载属性,我会得到一个Com-Object,但我现在不知道如何处理它。

1 个答案:

答案 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