Reference Guide
Programming / Metadata / Accessing image metadata in direct access mode
In This Topic
    Accessing image metadata in direct access mode
    In This Topic

    GdPicture offers an image parsing mechanism, that allows direct access to image properties such as metadata, ICC profiles and embedded thumbnails without decoding pixels. This feature is particularly useful if you need to quickly extract document information without the need to edit and render it on the screen.

    Below is an example of fast XMP, iptc, gps and exif metadata extraction from any kind of image supported by the toolkit.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    Dim oGdPictureImaging As New GdPictureImaging()
    'Loading image in direct access mode.
    Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("image.JPG", False, True)
    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
        Dim sb As New System.Text.StringBuilder()
        Dim exifTagsCount As Integer = oGdPictureImaging.TagCount(ImageID)
        Dim iptcTagsCount As Integer = oGdPictureImaging.IPTCCount(ImageID) 
        If exifTagsCount <> 0 Then
            'Handling EXIF tags.
            sb.Append("EXIF tags:" & vbCrLf & "-----------" & vbCrLf)
            For i As Integer = 1 To exifTagsCount
                Dim tagName As String = oGdPictureImaging.TagGetName(ImageID, i)
                Dim tagFormattedValue As String = oGdPictureImaging.TagGetValueString(ImageID, i)
                sb.Append(tagName + ": " + tagFormattedValue + vbCrLf)
            Next
        End If
        If iptcTagsCount <> 0 Then
            'Handling IPTC tags.
            sb.Append("IPTC tags:" & vbCrLf & "-----------" & vbCrLf)
            For i As Integer = 1 To iptcTagsCount
                Dim tagName As String = oGdPictureImaging.IPTCGetID(ImageID, i).ToString()
                Dim tagFormattedValue As String = oGdPictureImaging.IPTCGetValueString(ImageID, i)
                sb.Append(tagName + ": " + tagFormattedValue + vbLf)
            Next
        End If
        oGdPictureImaging.ReleaseGdPictureImage(ImageID)
        MessageBox.Show(sb.ToString(), "Metadata Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
        MessageBox.Show("The image can't be loaded. Status: " + oGdPictureImaging.GetStat().ToString(), "Metadata Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If
    oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked. 
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    //Loading image in direct access mode.
    int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("image.JPG", false, true);
    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        int exifTagsCount = oGdPictureImaging.TagCount(ImageID);
        int iptcTagsCount = oGdPictureImaging.IPTCCount(ImageID); 
        if (exifTagsCount != 0)
        {
            //Handling EXIF tags.
            sb.Append("EXIF tags:\n-----------\n");
            for (int i = 1; i <= exifTagsCount; i++)
            {
                string tagName = oGdPictureImaging.TagGetName(ImageID, i);
                string tagFormattedValue = oGdPictureImaging.TagGetValueString(ImageID, i);
                sb.Append(tagName + ": " + tagFormattedValue + "\n");
            }
        }
        if (iptcTagsCount != 0)
        {
            //Handling IPTC tags.
            sb.Append("IPTC tags:\n-----------\n");
            for (int i = 1; i <= iptcTagsCount; i++)
            {
                string tagName = oGdPictureImaging.IPTCGetID(ImageID, i).ToString();
                string tagFormattedValue = oGdPictureImaging.IPTCGetValueString(ImageID, i);
                sb.Append(tagName + ": " + tagFormattedValue + "\n");
            }
        }
        oGdPictureImaging.ReleaseGdPictureImage(ImageID);
        MessageBox.Show(sb.ToString(), "Metadata Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
    {
        MessageBox.Show("The image can't be loaded. Status: " + oGdPictureImaging.GetStat().ToString(), "Metadata Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    oGdPictureImaging.Dispose();

    Result: