TagCount Method (GdPictureImaging)
In This Topic
Returns the number of tags attached to a GdPicture image.
Syntax
'Declaration
Public Function TagCount( _
ByVal As Integer _
) As Integer
public int TagCount(
int
)
public function TagCount(
: Integer
): Integer;
public function TagCount(
: int
) : int;
public: int TagCount(
int
)
public:
int TagCount(
int
)
Parameters
- ImageID
- GdPicture image identifier.
Return Value
The number of tags attached to a GdPicture image.
Example
Dealing with the tags of a GdPicture image.
Reading the tags from a jpeg image.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.jpg", false);
// Write in a report all the tags available within the file.
StringBuilder report = new StringBuilder();
int tagCount = gdpictureImaging.TagCount(imageID);
for (int tagNo = 1; tagNo <= tagCount; tagNo++)
{
Tags tagID = gdpictureImaging.TagGetID(imageID, tagNo);
string tagName = gdpictureImaging.TagGetName(imageID, tagNo);
string tagValue = gdpictureImaging.TagGetValueString(imageID, tagNo);
report.AppendLine(tagID.ToString() + " " + tagName.ToString() + " " + tagValue.ToString());
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
MessageBox.Show(report.ToString(), "Tags", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Reading gps coordinates from the tags of a jpeg image.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.jpg", false);
// Walk the list of tags to gather the gps coordinates.
StringBuilder report = new StringBuilder();
int tagCount = gdpictureImaging.TagCount(imageID);
for (int tagNo = 1; tagNo <= tagCount; tagNo++)
{
Tags tag = gdpictureImaging.TagGetID(imageID, tagNo);
switch (tag)
{
case Tags.TagGpsLatitudeRef:
report.Append("LatitudeRef: ");
report.AppendLine(gdpictureImaging.TagGetValueString(imageID, tagNo));
break;
case Tags.TagGpsLongitudeRef:
report.Append("LongitudeRef: ");
report.AppendLine(gdpictureImaging.TagGetValueString(imageID, tagNo));
break;
case Tags.TagGpsLatitude:
case Tags.TagGpsLongitude:
StringBuilder coordinate = new StringBuilder();
if (gdpictureImaging.TagGetType(imageID, tagNo) == TagType.TagTypeRational)
{
// Read the rationals for the coordinate, usually 3 floatting values, 8 bytes per value.
int dataLength = gdpictureImaging.TagGetLength(imageID, tagNo);
byte[] data = new byte[dataLength];
gdpictureImaging.TagGetValueBytes(imageID, tagNo, ref data);
int rationalsCount = dataLength / 8;
int readIndex = 0;
for (int rationalIndex = 0; rationalIndex < rationalsCount; rationalIndex++)
{
uint numerator = System.BitConverter.ToUInt32(data, readIndex);
uint denominator = System.BitConverter.ToUInt32(data, readIndex + 4);
double value = (double)numerator / (double)denominator;
coordinate.Append(value.ToString());
coordinate.Append(" ");
readIndex += 8;
}
}
else
{
coordinate.Append(gdpictureImaging.TagGetValueString(imageID, tagNo));
}
report.Append(tag.ToString() + ": ");
report.AppendLine(coordinate.ToString());
break;
default:
break;
}
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
MessageBox.Show(report.ToString(), "Coordinates", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Example
Dealing with the tags of a GdPicture image.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.jpg", false);
// Write in a report all the tags available within the file.
StringBuilder report = new StringBuilder();
int tagCount = gdpictureImaging.TagCount(imageID);
for (int tagNo = 1; tagNo <= tagCount; tagNo++)
{
Tags tagID = gdpictureImaging.TagGetID(imageID, tagNo);
string tagName = gdpictureImaging.TagGetName(imageID, tagNo);
string tagValue = gdpictureImaging.TagGetValueString(imageID, tagNo);
report.AppendLine(tagID.ToString() + " " + tagName.ToString() + " " + tagValue.ToString());
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
MessageBox.Show(report.ToString(), "Tags", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
int imageID = gdpictureImaging.CreateGdPictureImageFromFile("image.jpg", false);
// Walk the list of tags to gather the gps coordinates.
StringBuilder report = new StringBuilder();
int tagCount = gdpictureImaging.TagCount(imageID);
for (int tagNo = 1; tagNo <= tagCount; tagNo++)
{
Tags tag = gdpictureImaging.TagGetID(imageID, tagNo);
switch (tag)
{
case Tags.TagGpsLatitudeRef:
report.Append("LatitudeRef: ");
report.AppendLine(gdpictureImaging.TagGetValueString(imageID, tagNo));
break;
case Tags.TagGpsLongitudeRef:
report.Append("LongitudeRef: ");
report.AppendLine(gdpictureImaging.TagGetValueString(imageID, tagNo));
break;
case Tags.TagGpsLatitude:
case Tags.TagGpsLongitude:
StringBuilder coordinate = new StringBuilder();
if (gdpictureImaging.TagGetType(imageID, tagNo) == TagType.TagTypeRational)
{
// Read the rationals for the coordinate, usually 3 floatting values, 8 bytes per value.
int dataLength = gdpictureImaging.TagGetLength(imageID, tagNo);
byte[] data = new byte[dataLength];
gdpictureImaging.TagGetValueBytes(imageID, tagNo, ref data);
int rationalsCount = dataLength / 8;
int readIndex = 0;
for (int rationalIndex = 0; rationalIndex < rationalsCount; rationalIndex++)
{
uint numerator = System.BitConverter.ToUInt32(data, readIndex);
uint denominator = System.BitConverter.ToUInt32(data, readIndex + 4);
double value = (double)numerator / (double)denominator;
coordinate.Append(value.ToString());
coordinate.Append(" ");
readIndex += 8;
}
}
else
{
coordinate.Append(gdpictureImaging.TagGetValueString(imageID, tagNo));
}
report.Append(tag.ToString() + ": ");
report.AppendLine(coordinate.ToString());
break;
default:
break;
}
}
gdpictureImaging.ReleaseGdPictureImage(imageID);
MessageBox.Show(report.ToString(), "Coordinates", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
See Also