Read and Extract IPTC Metadata from Images in C#

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 editing and rendering it on the screen.

The code below shows how to quickly extract IPTC metadata from any kind of image supported by the toolkit:

// We assume GdPicture has been correctly installed and unlocked.
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
// Loading the 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 iptcTagsCount = oGdPictureImaging.IPTCCount(ImageID);
    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();
'We assume GdPicture has been correctly installed and unlocked.
Dim oGdPictureImaging As New GdPictureImaging()
'Loading the 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 iptcTagsCount As Integer = oGdPictureImaging.IPTCCount(ImageID)
    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()