当前位置: 首页>>代码示例>>C#>>正文


C# Tags.HasFlag方法代码示例

本文整理汇总了C#中Tags.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# Tags.HasFlag方法的具体用法?C# Tags.HasFlag怎么用?C# Tags.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tags的用法示例。


在下文中一共展示了Tags.HasFlag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadTagsAsync

		/// <summary>
		/// Reads several tags in media <paramref name="file"/>.
		/// </summary>
		/// <returns>A dictionary that contains all tags values.</returns>
		/// <param name="file">Media file that contains EXIF tags.</param>
		/// <param name="tags">Tags to read.</param>
		public Task<Dictionary<Tags, object>> ReadTagsAsync(string file, Tags tags)
		{
			return Task.Run(() =>
			{
				try
				{
					var results = new Dictionary<Tags, object>();

					var tagFile = TagLib.File.Create(file);
					if (tags.HasFlag(Tags.Comments))
						results.Add(Tags.Comments, tagFile.Tag.Comment);

					var mediaType = GetMediaType(tagFile);
					if (tags.HasFlag(Tags.MediaType)) results.Add(Tags.MediaType, mediaType);

					switch(mediaType)
					{
						case MediaType.Image:
							FillImageTags(tagFile, results, tags);
							break;
						case MediaType.Video:
							FillVideoTags(tagFile, results, tags);
							break;
						case MediaType.Audio:
							FillAudioTags(tagFile, results, tags);
							break;
					}

					var video = tagFile.GetTag(TagTypes.DivX) as TagLib.Mpeg4.AppleTag;

					return results;
				}
//				catch (TagLib ex)
//				{
//					Log.E(ex, "File '{0}' is not a valid image to read EXIF values.", file);
//				}
				catch (Exception ex)
				{
					Log.E(ex, "Error while trying to read EXIF value for tag '{0}'.", tags);
				}
				return null;
			});
		}
开发者ID:crabouif,项目名称:Self-Media-Database,代码行数:49,代码来源:TagLibHelper.cs

示例2: SetImageTagValue

		/// <summary>
		/// Sets the image tag value.
		/// </summary>
		/// <param name="tagFile">TagLib file.</param>
		/// <param name="tag">Tag to set.</param>
		/// <param name="value">Value to set.</param>
		private void SetImageTagValue(TagLib.File tagFile, Tags tag, object value)
		{
			var image = tagFile.GetTag(TagTypes.XMP) as TagLib.Image.ImageTag;
			if (image != null)
			{
				if (tag.HasFlag(Tags.Keywords))
					image.Keywords = (string[])value;
				else if (tag.HasFlag(Tags.Rating))
					image.Rating = Convert.ToUInt32(value);
				else if (tag.HasFlag(Tags.Comments))
					image.Comment = value.ToString();
				else
					Log.W("Setting value to tag '{0}' is not supported in image files.", tag);
			}
		}
开发者ID:crabouif,项目名称:Self-Media-Database,代码行数:21,代码来源:TagLibHelper.cs

示例3: FillImageTags

		/// <summary>
		/// Fills the image tags to the <paramref name="results"/> dictionary.
		/// </summary>
		/// <param name="tagFile">Tag file.</param>
		/// <param name="results">Result dictionary to be filled.</param>
		/// <param name="tags">Tags to read.</param>
		private void FillImageTags(TagLib.File tagFile, Dictionary<Tags, object> results, Tags tags)
		{
            var image = tagFile.GetTag(TagTypes.AudibleMetadata) as TagLib.Image.ImageTag;
			if (image != null)
			{
				if (tags.HasFlag(Tags.GpsLatitude))
					results.Add(Tags.GpsLatitude, image.Latitude);
				if (tags.HasFlag(Tags.GpsLongitude))
					results.Add(Tags.GpsLongitude, image.Longitude);
				if (tags.HasFlag(Tags.Keywords))
					results.Add(Tags.Keywords, image.Keywords);
				if (tags.HasFlag(Tags.DateTimeTaken))
					results.Add(Tags.DateTimeTaken, image.DateTime);
				if (tags.HasFlag(Tags.Rating))
					results.Add(Tags.Rating, image.Rating);
			}
		}
开发者ID:crabouif,项目名称:Self-Media-Database,代码行数:23,代码来源:TagLibHelper.cs

示例4: FillVideoTags

		/// <summary>
		/// Fills the video tags to the <paramref name="results"/> dictionary.
		/// </summary>
		/// <param name="tagFile">Tag file.</param>
		/// <param name="results">Result dictionary to be filled.</param>
		/// <param name="tags">Tags to read.</param>
		private void FillVideoTags(TagLib.File tagFile, Dictionary<Tags, object> results, Tags tags)
		{
			var h264 = tagFile.GetTag(TagTypes.H264) as TagLib.H264.Tag;

			if (tags.HasFlag(Tags.DateTimeTaken))
			{
				if (h264 != null)
					results.Add(Tags.Keywords, h264.DateTimeOriginal);
			}
		}
开发者ID:crabouif,项目名称:Self-Media-Database,代码行数:16,代码来源:TagLibHelper.cs

示例5: GetExifLibraryTags

		/// <summary>
		/// Gets the exif library tags according abstract <see cref="Tags"/>.
		/// </summary>
		/// <returns>The exif library tags.</returns>
		/// <param name="tags">Tags.</param>
		private Dictionary<ExifTag, Tags> GetExifLibraryTags(Tags tags)
		{
			var exifLibraryTags = new Dictionary<ExifTag, Tags>();
			if (tags.HasFlag(Tags.Comments))
			{
				exifLibraryTags.Add(ExifTag.UserComment, Tags.Comments);
				exifLibraryTags.Add(ExifTag.WindowsComment, Tags.Comments);
			}
			if (tags.HasFlag(Tags.DateTimeTaken))
				exifLibraryTags.Add(ExifTag.DateTimeOriginal, Tags.DateTimeTaken);
			if (tags.HasFlag(Tags.Keywords))
				exifLibraryTags.Add(ExifTag.WindowsKeywords, Tags.Keywords);
			if (tags.HasFlag(Tags.GpsLatitude))
				exifLibraryTags.Add(ExifTag.GPSLatitude, Tags.GpsLatitude);
			if (tags.HasFlag(Tags.GpsLongitude))
				exifLibraryTags.Add(ExifTag.GPSLongitude, Tags.GpsLongitude);

			return exifLibraryTags;
		}
开发者ID:crabouif,项目名称:Self-Media-Database,代码行数:24,代码来源:ExifLibraryHelper.cs


注:本文中的Tags.HasFlag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。