在图片框中显示 Jpeg 的元数据缩略图
Posted
技术标签:
【中文标题】在图片框中显示 Jpeg 的元数据缩略图【英文标题】:Display Metadata-thumbnail of Jpeg in picturebox 【发布时间】:2013-08-28 20:53:23 【问题描述】:我需要显示图像的缩略图,该缩略图保存在图片框中的元数据中。我正在使用 VB.NET
http://msdn.microsoft.com/en-us/library/windows/desktop/ee719904%28v=vs.85%29.aspx#_jpeg_metadata
到目前为止,我想出了这个。添加断点会显示 GETQUERY 返回空,即使我知道该文件确实有缩略图
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim imagepath = "C:\xampp\htdocs\Downloads\IMG_1322.JPG" ' path to file
Dim stream = New FileStream(imagepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim decoder = New JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None)
Dim metadata = TryCast(decoder.Frames(0).Metadata, BitmapMetadata)
Dim ms As New System.IO.MemoryStream
Dim bm As Bitmap
Dim arData() As Byte
arData = metadata.GetQuery("/app0/ushort=6") '<--- Breakpoint here: Query returns nothing!
ms.Write(arData, 78, arData.Length - 78)
bm = New Bitmap(ms)
PictureBox1.Image = bm
stream.Close()
End Sub
【问题讨论】:
【参考方案1】:你可以试试这样的:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim imagepath = "C:\xampp\htdocs\Downloads\IMG_1322.JPG" ' path to file
Dim stream = New FileStream(imagepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim decoder = New JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None)
Dim metadata = TryCast(decoder.Frames(0).Metadata, BitmapMetadata)
Dim thumb As BitmapMetadataBlob
thumb = metadata.GetQuery("/app1/thumb/")
If Not (thumb Is Nothing) Then
Dim src As New BitmapImage
Dim ms As MemoryStream = New MemoryStream(thumb.GetBlobValue())
src.BeginInit()
src.StreamSource = ms
src.EndInit()
PictureBox1.Source = src
End If
stream.Close()
End Sub
【讨论】:
耶!你是最好的! :D 你的代码中有一个类型。 bm 未声明,ms 声明了 2 次。但它很棒!谢谢 如何找到 IPTC 数据的查询路径?例如,您如何知道要编写什么查询来获取/设置图像的标题?以上是关于在图片框中显示 Jpeg 的元数据缩略图的主要内容,如果未能解决你的问题,请参考以下文章