Пример #1
0
        internal void AddTag(ImageTag tag)
        {
            if ((tag.TagTypes & AllowedTypes) != tag.TagTypes)
            {
                throw new Exception(String.Format("Attempted to add {0} to an image, but the only allowed types are {1}", tag.TagTypes, AllowedTypes));
            }

            if (tag is IFDTag)
            {
                Exif = tag as IFDTag;
            }
            else if (tag is XmpTag)
            {
                // we treat a IPTC-IIM tag as a XMP tag. However, we prefer the real XMP tag.
                // See comments in Jpeg/File.cs for what we should do to deal with this properly.
                if (Xmp != null && (tag is IIM.IIMTag || Xmp is IIM.IIMTag))
                {
                    var iimTag = tag as IIM.IIMTag;
                    if (iimTag == null)
                    {
                        iimTag = Xmp as IIM.IIMTag;
                        Xmp    = tag as XmpTag;
                    }

                    if (string.IsNullOrEmpty(Xmp.Title))
                    {
                        Xmp.Title = iimTag.Title;
                    }
                    if (string.IsNullOrEmpty(Xmp.Creator))
                    {
                        Xmp.Creator = iimTag.Creator;
                    }
                    if (string.IsNullOrEmpty(Xmp.Copyright))
                    {
                        Xmp.Copyright = iimTag.Copyright;
                    }
                    if (string.IsNullOrEmpty(Xmp.Comment))
                    {
                        Xmp.Comment = iimTag.Comment;
                    }
                    if (Xmp.Keywords == null)
                    {
                        Xmp.Keywords = iimTag.Keywords;
                    }
                }
                else
                {
                    Xmp = tag as XmpTag;
                }
            }
            else
            {
                OtherTags.Add(tag);
            }

            all_tags = null;
        }
Пример #2
0
        /// <summary>
        ///    Gets a tag of a specified type from the current instance,
        ///    optionally creating a new tag if possible.
        /// </summary>
        /// <param name="type">
        ///    A <see cref="TagLib.TagTypes" /> value indicating the
        ///    type of tag to read.
        /// </param>
        /// <param name="create">
        ///    A <see cref="bool" /> value specifying whether or not to
        ///    try and create the tag if one is not found.
        /// </param>
        /// <returns>
        ///    A <see cref="Tag" /> object containing the tag that was
        ///    found in or added to the current instance. If no
        ///    matching tag was found and none was created, <see
        ///    langword="null" /> is returned.
        /// </returns>
        public override TagLib.Tag GetTag(TagLib.TagTypes type,
                                          bool create)
        {
            foreach (Tag tag in ImageTag.AllTags)
            {
                if ((tag.TagTypes & type) == type)
                {
                    return(tag);
                }
            }

            if (!create || (type & ImageTag.AllowedTypes) == 0)
            {
                return(null);
            }

            ImageTag new_tag = null;

            switch (type)
            {
            case TagTypes.JpegComment:
                new_tag = new JpegCommentTag();
                break;

            case TagTypes.GifComment:
                new_tag = new GifCommentTag();
                break;

            case TagTypes.Png:
                new_tag = new PngTag();
                break;

            case TagTypes.TiffIFD:
                new_tag = new IFDTag();
                break;

            case TagTypes.XMP:
                new_tag = new XmpTag();
                break;
            }

            if (new_tag != null)
            {
                ImageTag.AddTag(new_tag);
                return(new_tag);
            }

            throw new NotImplementedException(String.Format("Adding tag of type {0} not supported!", type));
        }
Пример #3
0
        internal void RemoveTag(ImageTag tag)
        {
            if (tag is IFDTag)
            {
                Exif = null;
            }
            else if (tag is XmpTag)
            {
                Xmp = null;
            }
            else
            {
                OtherTags.Remove(tag);
            }

            all_tags = null;
        }