Visual Basic: Get metadata from an image using GDI+

Platform:Visual Basic
Task:Get metadata from an image using GDI+
Some image files contain metadata that you can read to determine features of the image. For example, a digital photograph might contain metadata that you can read to determine the make and model of the camera used to capture the image. With GDI+, you can read existing metadata, and you can also write new metadata to image files. GDI+ stores an individual piece of metadata in a PropertyItem object. You can read the PropertyItems property of an Image object to retrieve all the metadata from a file. The PropertyItems property returns an array of PropertyItem objects.
Imports System.Drawing.Imaging 
Public Class Form1

    Private Sub btnGetMetadata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetMetadata.Click
        'this example synthesized from the typically overly elaborate, confusing and complicated example at

        'Create an Image object. 
        Dim TheImage As Bitmap = New Bitmap("K:\ARCN Lisa\photos\2007 sheep photos\GAAR sheep photos\4K_sheep.jpg")

        'Get the PropertyItems property from image.
        Dim PropItems As PropertyItem() = TheImage.PropertyItems

        Dim encoding As New System.Text.ASCIIEncoding()
        MsgBox(encoding.GetString(PropItems(8).Value)) 'the 8th item seems to be the date and time the picture was taken, change the number for other items.
    End Sub
End Class
Back to Index