ImageEn, unit hyieutils

TIEDictionary.GetString

TIEDictionary.GetString


Declaration

function GetString(const key: WideString; recursive: boolean = True): WideString; overload;
function GetString(const key: WideString; const Def: string; recursive: boolean = True): WideString; overload;


Description

Returns the string value to which the key is mapped in this dictionary. If the key doesn't exist an exception is raised.

Parameter Description
key A key in this dictionary
recursive If true then it will also search for this key in sub-dictionaries
Note: Use '#text' as the key to get the values from a tag list, e.g. memo1.lines.add( dict.GetString( '#text', false ));


Examples

// Return the photo description from the XMP metadata
sDescription := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'dc:description' );

// Return the creation date from the XMP metadata (XMP date strings are formatted the same EXIF date strings)
dtCreateDate := EXIFDateToDateTime( ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'xmp:CreateDate' ));

// Return the creator or author of the asset from the XMP metadata. If not found, return '' instead of rasing exception
sCreator := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'dc:creator', '' );

// Return location information about the content being shown in the image
sLocation := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'photoshop:City' ) + ', ' +
             ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'photoshop:State' ) + ', ' +
             ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'photoshop:Country' );

// Return the document title from the XMP metadata
sTitle := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'dc:title' );

// Return the document keywords from the XMP metadata
sKeywords := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'dc:subject' );

// Return the document copyright information from the XMP metadata
sCopyright := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'dc:rights' );

// Return the Photoshop Headline from the XMP metadata. If not found, return '' instead of rasing exception
sHeadline := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'photoshop:Headline', '' );

// Return the Windows Rating from the XMP metadata (0 to 5)
sRating := ImageEnView1.IO.Params.Dict.GetDictionary( 'XMP' ).GetString( 'xmp:Rating' );


// Output all entries of dc:subject->rdf:Bag of JPEG XMP
{
Example XMP content:

  <dc:subject>
    <rdf:Bag>
       <rdf:li>China</rdf:li>
       <rdf:li>Jan 2008</rdf:li>
       <rdf:li>Shanghai</rdf:li>
    </rdf:Bag>
  </dc:subject>

Output:

  China
  Jan 2008
  Shanghai
}
var
  xmpDict: TIEDictionary;  // Dict containing image XMP data
  navDict: TIEDictionary;  // Dict to navigate XML structure
  list: TObjectList;
  i: integer;
begin
  ImageEnView1.IO.LoadFromFile( 'D:\XMP_Data_202112.JPG' );

  // Get XMP
  xmpDict := ImageEnView1.IO.Params.Dict.GetDictionary('XMP');

  // Output all entries of dc:subject->rdf:Bag into "memo1"
  navDict := xmpDict.GetDictionary('dc:subject', True);
  navDict := navDict.GetDictionary('#content', false);
  navDict := navDict.GetDictionary('rdf:Bag', false);
  navDict := navDict.GetDictionary('#content', false);
  list := navDict.GetList('rdf:li', false);
  for i := 0 to list.Count - 1 do
  begin
    navDict := TIEDictionary(list[i]).GetDictionary('#content', false);
    memo1.lines.add( navDict.GetString('#text', false) );
  end;
end;