csImageFile can be used to read and write "people tags" which are metadata properties used to identify people in digital photographs. They are used by Windows Live and Windows Live Photo Gallery. This example shows how tags can be read from an image and the people highlighted.
Tag Details:
Person Tag 1: Dave Kemp
Area Position (in pixels): (10, 45)
Area Size (in pixels): 80 x 100
Person Tag 2: Ryan Blott
Area Position (in pixels): (275, 90)
Area Size (in pixels): 100 x 100
The following code is used to read each person tag in turn and it uses the coordinates of each tag to locally adjust the brightness and write the person's name at their location. It assumes that an instance of csImageFile has been created with the name Image and the image has been loaded.
If Image.XMPPersonTagCount > 0 Then
For I = 0 to Image.XMPPersonTagCount - 1
X = Image.XMPRectangleX(I)
Y = Image.XMPRectangleY(I)
Height = Image.XMPRectangleHeight(I)
Width = Image.XMPRectangleWidth(I)
Image.SetSelection X, Y, X + Width, Y + Height
Image.Brightness 70
Image.TextSize = 14
Image.TextOpaque = false
Image.TextColor = "FFFFFF"
Image.Text X, Y, Image.XMPPersonTag(I)
Next
End If
The XMPPersonTagCount property returns the number of tags in an image so this is checked to see if there are any tags present and it is used as the loop variable. Each person tag must have a name, the XMPPersonTag property, but the rectangle showing the person's location is optional. The rectangle is defined by the X and Y coordinates of the top left corner, and its width and height. The SetSelection method specifies the area that will be adjusted by the Brightness method.
The person tags are stored in a list and are identified in the code with an index variable which starts at zero for the first tag. An exception will be raised if an invalid index is used.
The ASP code to display the tag data is very similar and is not shown here. It is shown as part of our interactive IPTC demo.
The code to write one of the tags would be as follows:
Index = Image.AddXMPPersonTag("Ryan Blott")
Image.SetXMPRectanglePX Index, 275, 90, 100, 100
First the name is added with AddXMPPersonTag and this creates the tag, but with no rectangle defined at this stage. Two methods are available for defining the rectangle. This code shows SetXMPRectanglePX, which uses pixel values for the coordinates, but there is also a method called SetXMPRectangle which uses floating point values between 0 and 1 and the dimensions are measured as fractions of the width and height. The variable Index is used to make sure that the rectangle and the name match. If some user interaction is needed to allow the rectangle to be selected with the mouse, we have a downloadable demo that can be adapted.
© Chestysoft, 2024.
This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.