本文整理汇总了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;
});
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}