In This Topic
Programming / Metadata / How to get and set custom EXIF tag in a TIFF document

How to get and set custom EXIF tag in a TIFF document

In This Topic

In this example, we will see how to set a custom EXIF tag and then retrieve it on a TIFF document.

Copy Code
'We assume that GdPicture has been correctly installed and unlocked.

'Tag identifier must be in the range [65000 - 65535].

Const  MY_CUSTOM_EXIF_TAG_1 As Integer = 65000

Dim oGdPictureImaging As New GdPictureImaging()

'Adding custom exif tag to input.tif bitmap.

Dim ImageID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif", True)

Dim saved As Boolean = False

If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then

    oGdPictureImaging.TagSetValueString(ImageID, DirectCast(MY_CUSTOM_EXIF_TAG_1, Tags), TagType.TagTypeASCII, "my private exif tag")

    'Checking if the image has been saved correctly.

    saved = (oGdPictureImaging.SaveAsTIFF(ImageID, "input.tif", oGdPictureImaging.GetTiffCompression(ImageID)) = GdPictureStatus.OK)

    oGdPictureImaging.ReleaseGdPictureImage(ImageID)

End If 

If saved Then

    'Now retrieving the custom tag value.

    ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif", True)

    If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then

        For i As Integer = 1 To oGdPictureImaging.TagCount(ImageID)

            If oGdPictureImaging.TagGetID(ImageID, i) = DirectCast(MY_CUSTOM_EXIF_TAG_1, Tags) Then

                MessageBox.Show("Tag value is: " + oGdPictureImaging.TagGetValueString(ImageID, i), "Metadata Example", MessageBoxButtons.OK, MessageBoxIcon.Information)

                Exit For

            End If

        Next

        oGdPictureImaging.ReleaseGdPictureImage(ImageID)

    End If

End If

oGdPictureImaging.Dispose()
Copy Code
//We assume that GdPicture has been correctly installed and unlocked.

const int MY_CUSTOM_EXIF_TAG_1 = 65000; //Tag identifier must be in the range [65000 - 65535]. 

GdPictureImaging oGdPictureImaging = new GdPictureImaging();

//Adding custom exif tag to input.tif bitmap.

int ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif", true);

bool saved = false;

if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)

{

    oGdPictureImaging.TagSetValueString(ImageID, (Tags)MY_CUSTOM_EXIF_TAG_1, TagType.TagTypeASCII, "my private exif tag");

    //Checking if the image has been saved correctly.

    saved = (oGdPictureImaging.SaveAsTIFF(ImageID, "input.tif", oGdPictureImaging.GetTiffCompression(ImageID)) == GdPictureStatus.OK);

    oGdPictureImaging.ReleaseGdPictureImage(ImageID);

}

if (saved)

{

    //Now retrieving the custom tag value.

    ImageID = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif", true);

    if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)

    {

        for (int i = 1; i <= oGdPictureImaging.TagCount(ImageID); i++)

        {

            if (oGdPictureImaging.TagGetID(ImageID, i) == (Tags)MY_CUSTOM_EXIF_TAG_1)

            {

                MessageBox.Show("Tag value is: " + oGdPictureImaging.TagGetValueString(ImageID, i), "Metadata Example", MessageBoxButtons.OK, MessageBoxIcon.Information);

                break;

            }

        }

        oGdPictureImaging.ReleaseGdPictureImage(ImageID);

    }

}

oGdPictureImaging.Dispose();