/// <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)); }
public void TestJpegRead() { Assert.IsTrue(_file is Jpeg.File); Assert.AreEqual(CONTAINED_TYPES, _file.TagTypes); Assert.AreEqual(CONTAINED_TYPES, _file.TagTypesOnDisk); Assert.IsNotNull(_file.Properties, "properties"); Assert.AreEqual(7, _file.Properties.PhotoHeight); Assert.AreEqual(10, _file.Properties.PhotoWidth); Assert.AreEqual(90, _file.Properties.PhotoQuality); JpegCommentTag tag = _file.GetTag(TagTypes.JpegComment) as JpegCommentTag; Assert.IsFalse(tag == null); Assert.AreEqual("Test Comment", tag.Value); }