2014-09-18 33 views

回答

1

WIAitem縮略圖屬性是一個wia.vector對象,屬性binarydata可以很容易地轉換爲.net圖像與image.fromstream。這裏是代碼:

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