我們有存儲在數據庫中的圖像,它們用於替換Word文檔中的圖像 - 除非替換圖像是縱向並替換橫向圖像,那麼該位可以完美地工作,所以我試圖讓元數據,以確定使用此功能從圖像文件中獲取元數據
Public Function GetImageTags(ImageFile() As Byte) As String()
Try
Dim vReturnArray() As String = Nothing
Using MS As New System.IO.MemoryStream(ImageFile)
Dim vDecoder As BitmapDecoder = BitmapDecoder.Create(MS, BitmapCreateOptions.None, BitmapCacheOption.Default)
Dim vFrame As BitmapFrame = vDecoder.Frames(0)
Dim vMetadata As BitmapMetadata = TryCast(vFrame.Metadata, BitmapMetadata)
If vMetadata IsNot Nothing And vMetadata.Keywords IsNot Nothing Then
vReturnArray = vMetadata.Keywords.ToArray()
End If
End Using
Return vReturnArray
Catch ex As Exception
EmailError(ex)
Return Nothing
End Try
End Function
圖像是如何定向...但它拋出的玩具了與...
This codec does not support the specified property.
at System.Windows.Media.Imaging.BitmapMetadata.GetQuery(String query)
at System.Windows.Media.Imaging.BitmapMetadata.get_Keywords()
...在BitMapMetadata 。關鍵詞。任何想法如何克服這一點,並獲得關鍵字?
謝謝
================ UPDATE ================
看來,錯誤,我也試過......
vReturnArray = TryCast(vMetadata.GetQuery("System.Keywords"), String())
...只返回一些圖像,但所有我試過的字符串()
一些編解碼器(如PNG)不支持BitmapMetadata.Keywords財產。您應該在try塊中訪問它。 – Clemens
您是否試過[this](http://sanderstechnology.com/2013/extracting-file-metadata-with-c-and-the-net-framework/12679/)?它是C#,但它應該與'vb.net'一起使用。 – lightlike
克萊門斯 - 也嘗試過PngBitmapDecoder – gchq