ImageGear does not use a separate data storage for the Simplified Metadata API. Instead, it uses the General Metadata storage engine. Simplified API classes only provide easy access to the data stored in the General metadata tree. As a result, there are a few points you may consider.
Each time you access an array or a structure in the Simplified Metadata API, ImageGear returns a new instance of array or structure, with all corresponding data copied into it. To maintain optimal performance, it is better to assign the array to a local variable, and then access its values, rather than access the array property from the metadata for retrieving each value:
C#
// Access array property once - good performance
ImGearXMPBag<ImGearXMPString> Subject = (igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject;
if (Subject != null)
{
for (int i = 0; i < Subject.Count; i++)
Debug.WriteLine(Subject[i].Value);
}
// Access array property multiple times - array is
// created and copied each time a value is accessed (poor performance)
if ((igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject != null)
{
for (int i = 0; i < Subject.Count; i++)
Debug.WriteLine((igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject[i].Value);
}
VB.NET
' Access array property once - good performance
Dim Subject As ImGearXMPBag(Of ImGearXMPString) = DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject
If Subject IsNot Nothing Then
For i As Integer = 0 To Subject.Count - 1
Debug.WriteLine(Subject(i).Value)
Next
End If
' Access array property multiple times - array is
' created and copied each time a value is accessed (poor performance)
If DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject IsNot Nothing Then
For i As Integer = 0 To Subject.Count - 1
Debug.WriteLine(DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject(i).Value)
Next
End If
To set an array or structure type property, create a new array (structure), set its values as needed, and then assign this array (structure) to the corresponding property of the Simplified API. Changing values of an array or structure which has already been set will not have any effect.
C#
// Incorrect: The array will remain empty
(igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject = new ImGearXMPBag<ImGearXMPString>();
(igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject.Add(new ImGearXMPString("Subject1"));
(igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject.Add(new ImGearXMPString("Subject2"));
// Correct: The array will contain the 2 strings
ImGearXMPBag<ImGearXMPString> Subject = new ImGearXMPBag<ImGearXMPString>();
Subject.Add(new ImGearXMPString("Subject1"));
Subject.Add(new ImGearXMPString("Subject2"));
(igPage.Metadata.XMP as ImGearXMPMetadataRoot).DublinCore.Subject = Subject;
VB.NET
' Incorrect: The array will remain empty
DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject = New ImGearXMPBag(Of ImGearXMPString)()
DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject.Add(New ImGearXMPString("Subject1"))
DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject.Add(New ImGearXMPString("Subject2"))
' Correct: The array will contain the 2 strings
Dim Subject As New ImGearXMPBag(Of ImGearXMPString)()
Subject.Add(New ImGearXMPString("Subject1"))
Subject.Add(New ImGearXMPString("Subject2"))
DirectCast(igPage.Metadata.XMP, ImGearXMPMetadataRoot).DublinCore.Subject = Subject