/// <summary>
        /// Find the attribute in the parsed exif data
        /// </summary>
        /// <param name="exif">Parsed exif data</param>
        /// <returns>New attribute parsed from the exif or null if there is no such tag</returns>
        public Attribute Parse(IExifMetadata exif)
        {
            var directory = exif.GetDirectoryOfType <T>();

            if (directory == null || !directory.ContainsTag(Tag))
            {
                return(null);
            }

            try
            {
                switch (Type)
                {
                case AttributeType.Int:
                    return(new Attribute(Name, new IntValue(directory.GetInt32(Tag)), AttributeSource.Metadata));

                case AttributeType.Double:
                    return(new Attribute(Name, new RealValue(directory.GetDouble(Tag)), AttributeSource.Metadata));

                case AttributeType.String:
                    return(new Attribute(Name, new StringValue(directory.GetString(Tag)), AttributeSource.Metadata));

                case AttributeType.DateTime:
                    return(new Attribute(Name, new DateTimeValue(directory.GetDateTime(Tag)), AttributeSource.Metadata));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (MetadataException)
            {
                // the tag exists but its format is invalid => ignore it
                return(null);
            }
        }
        /// <summary>
        /// Try parsing thumbnail from exif
        /// </summary>
        /// <param name="exif">Exif metadata</param>
        /// <returns>Thumbnail attribute</returns>
        public Attribute Parse(IExifMetadata exif)
        {
            var dir = exif.GetDirectoryOfType <T>();

            if (dir == null)
            {
                return(null);
            }

            if (!dir.ContainsTag(ExifThumbnailDirectory.TagThumbnailOffset) ||
                !dir.ContainsTag(ExifThumbnailDirectory.TagThumbnailLength))
            {
                return(null);
            }

            var offset = dir.GetInt32(ExifThumbnailDirectory.TagThumbnailOffset);
            var length = dir.GetInt32(ExifThumbnailDirectory.TagThumbnailLength);

            if (length <= 0)
            {
                return(null);
            }

            var buffer = new byte[length];

            // the offset is from the start of the exif data, not the start of the segment data
            // we have to add 6 for the segment header "Exif\0\0"
            Array.Copy(exif.Segment.Bytes, offset + 6, buffer, 0, length);
            return(new Attribute(_attributeName, new ImageValue(buffer), AttributeSource.Metadata));
        }
Exemple #3
0
 public Attribute Parse(IExifMetadata exif)
 {
     return(_attr);
 }