在图片框中显示Jpeg的元数据缩略图 [英] Display Metadata-thumbnail of Jpeg in picturebox

查看:149
本文介绍了在图片框中显示Jpeg的元数据缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示图片的缩略图,该缩略图保存在图片框的元数据中.我正在使用VB.NET

I need to display a Image's thumbnail, that is saved in its Metadata in a picturebox. I'm using VB.NET

http: //msdn.microsoft.com/zh-CN/library/windows/desktop/ee719904%28v=vs.85%29.aspx#_jpeg_metadata

到目前为止,我想到了这个.添加断点将显示GETQUERY返回空,即使我知道该文件确实具有缩略图也是如此

So far i came up with this. Adding a breakpoint displays that GETQUERY returns empty even if i know that the file does indeed have a thumbnail

    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

推荐答案

您可以尝试执行以下操作:

You can try something like this:

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

这篇关于在图片框中显示Jpeg的元数据缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆