mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 3bca9a911b0189867911ef22765009909a9bbe00 Former-commit-id: 91add02607f34749757840aa946b1fe987bd234f Former-commit-id: cb69236b11426f8c1abd1928c22d0922c1554baaaf/merge-core
4 changed files with 94 additions and 0 deletions
@ -0,0 +1,49 @@ |
|||
// <copyright file="ExifTag.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore |
|||
{ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
|
|||
/// <summary>
|
|||
/// Class that provides a description for an ExifTag value.
|
|||
/// </summary>
|
|||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)] |
|||
internal sealed class ExifTagDescriptionAttribute : Attribute |
|||
{ |
|||
private object value; |
|||
private string description; |
|||
|
|||
///<summary>
|
|||
/// Initializes a new instance of the ExifTagDescriptionAttribute class.
|
|||
///</summary>
|
|||
/// <param name="value">The value of the exif tag.</param>
|
|||
/// <param name="description">The description for the value of the exif tag.</param>
|
|||
public ExifTagDescriptionAttribute(object value, string description) |
|||
{ |
|||
this.value = value; |
|||
this.description = description; |
|||
} |
|||
|
|||
public static string GetDescription(ExifTag tag, object value) |
|||
{ |
|||
FieldInfo field = tag.GetType().GetTypeInfo().GetDeclaredField(tag.ToString()); |
|||
if (field == null) |
|||
return null; |
|||
|
|||
foreach (CustomAttributeData customAttribute in field.CustomAttributes) |
|||
{ |
|||
object attributeValue = customAttribute.ConstructorArguments[0].Value; |
|||
|
|||
if (Equals(attributeValue, value)) |
|||
return (string)customAttribute.ConstructorArguments[1].Value; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
// <copyright file="ExifProfileTests.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Tests |
|||
{ |
|||
using Xunit; |
|||
|
|||
public class ExifDescriptionAttributeTests |
|||
{ |
|||
[Fact] |
|||
public void Test_ExifTag() |
|||
{ |
|||
var exifProfile = new ExifProfile(); |
|||
|
|||
exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)1); |
|||
ExifValue value = exifProfile.GetValue(ExifTag.ResolutionUnit); |
|||
Assert.Equal("None", value.ToString()); |
|||
|
|||
exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)2); |
|||
value = exifProfile.GetValue(ExifTag.ResolutionUnit); |
|||
Assert.Equal("Inches", value.ToString()); |
|||
|
|||
exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)3); |
|||
value = exifProfile.GetValue(ExifTag.ResolutionUnit); |
|||
Assert.Equal("Cm", value.ToString()); |
|||
|
|||
exifProfile.SetValue(ExifTag.ResolutionUnit, (ushort)4); |
|||
value = exifProfile.GetValue(ExifTag.ResolutionUnit); |
|||
Assert.Equal("4", value.ToString()); |
|||
|
|||
exifProfile.SetValue(ExifTag.ImageWidth, 123); |
|||
value = exifProfile.GetValue(ExifTag.ImageWidth); |
|||
Assert.Equal("123", value.ToString()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue