freeimage.h

FreeImage_SetMetadata

DLL_API BOOL DLL_CALLCONV FreeImage_SetMetadata(FREE_IMAGE_MDMODEL model, FIBITMAP
*dib, const char *key, FITAG *tag);

añade una nueva etiqueta FreeImage a un dib. A la entrada, model es el modelo de metadatos usado para almacenar la etiqueta, dib es la imagen de destino, key es el nombre del campo de etiqueta y tag es la etiqueta FreeImage a añadir.

Si tag es NULL entonces el metadato es eliminado.

Si tanto key como tag son NULL entonces el modelo de metadatos es eliminado.

La función retorna TRUE si tiene éxito y FALSE en caso contrario.

El nombre de campo de etiqueta (o tag key) usado por FreeImage para indexar una etiqueta viene dado por la especificación del modelo de metadatos (por ejemplo la especificación EXIF o Adobe XMP).

char *xmp_profile = NULL;
DWORD profile_size = 0;
// ...
// the following assumes that you have a XML packet stored in
// the (null terminated) variable 'xmp_profile'.
// The size of the packet is given
// by 'profile_size' and includes the NULL value
// create a tag
FITAG *tag = FreeImage_CreateTag();
if(tag) {
    // fill the tag members
    // note that the FIMD_XMP model accept a single key named “XMLPacket”
    FreeImage_SetTagKey(tag, “XMLPacket”);
    FreeImage_SetTagLength(tag, profile_size);
    FreeImage_SetTagCount(tag, profile_size);
    FreeImage_SetTagType(tag, FIDT_ASCII);
    // the tag value must be stored after
    // the tag data type, tag count and tag length have been filled.
    FreeImage_SetTagValue(tag, xmp_profile);

    // store the tag
    FreeImage_SetMetadata(FIMD_XMP, dib, FreeImage_GetTagKey(tag), tag);
    // destroy the tag
    FreeImage_DeleteTag(tag);
}
/**
Add a single IPTC tag to a FIBITMAP
NB: The tag ID is not needed as it is filled automatically by FreeImage_SetMetadata
@param image Your image to be saved
@param key Tag key
@param value Tag value
*/
void add_IPTC_tag(FIBITMAP *image, const char *key, const char *value) {
    // create a tag
    FITAG *tag = FreeImage_CreateTag();
    if(tag) {
        // fill the tag
        FreeImage_SetTagKey(tag, key);
        FreeImage_SetTagLength(tag, strlen(value) + 1);
        FreeImage_SetTagCount(tag, strlen(value) + 1);
        FreeImage_SetTagType(tag, FIDT_ASCII);
        FreeImage_SetTagValue(tag, value);
        FreeImage_SetMetadata(FIMD_IPTC, image, FreeImage_GetTagKey(tag), tag);
        // destroy the tag
        FreeImage_DeleteTag(tag);
    }
}
/**
Add some IPTC tags to a FIBITMAP
*/
void add_IPTC_Metadata(FIBITMAP *dib) {
    // !!! IPTC data is ignored by Photoshop when there is a XML packet in the dib !!!
    add_IPTC_tag(dib, "ObjectName", "my title");
    add_IPTC_tag(dib, "Caption-Abstract", "my caption");
    add_IPTC_tag(dib, "Writer-Editor", "myself");
    add_IPTC_tag(dib, "By-line", "my name");
    add_IPTC_tag(dib, "By-lineTitle", "my position");
    add_IPTC_tag(dib, "Keywords", "FreeImage;Library;Images;Compression");
}