📷 A modern, cross-platform, 2D Graphics library for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

47 lines
1.4 KiB

// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Globalization;
namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
{
internal sealed class ExifByte : ExifValue<byte>
{
public ExifByte(ExifTag<byte> tag, ExifDataType dataType)
: base(tag) => this.DataType = dataType;
public ExifByte(ExifTagValue tag, ExifDataType dataType)
: base(tag) => this.DataType = dataType;
private ExifByte(ExifByte value)
: base(value) => this.DataType = value.DataType;
public override ExifDataType DataType { get; }
protected override string StringValue => this.Value.ToString("X2", CultureInfo.InvariantCulture);
public override bool TrySetValue(object value)
{
if (base.TrySetValue(value))
{
return true;
}
switch (value)
{
case int intValue:
if (intValue >= byte.MinValue && intValue <= byte.MaxValue)
{
this.Value = (byte)intValue;
return true;
}
return false;
default:
return base.TrySetValue(value);
}
}
public override IExifValue DeepClone() => new ExifByte(this);
}
}