Skip to content

Instantly share code, notes, and snippets.

@phillip-haydon
Created August 27, 2014 18:26
Show Gist options
  • Save phillip-haydon/ea396778ddc4bd97111e to your computer and use it in GitHub Desktop.
Save phillip-haydon/ea396778ddc4bd97111e to your computer and use it in GitHub Desktop.
public class ExifInfo
{
public static IList<Exif> ExifTagsToCapture;
static ExifInfo()
{
ExifTagsToCapture = new List<Exif>
{
new Exif
{
ExifTag = CustomExifTags.Make,
Show = true,
Name = "Make",
Id = (ushort)CustomExifTags.Make,
ToString = value => value.ToString()
},
new Exif
{
ExifTag = CustomExifTags.Model,
Show = true,
Name = "Model",
Id = (ushort)CustomExifTags.Model,
ToString = value => value.ToString()
},
new Exif
{
ExifTag = CustomExifTags.ExposureTime,
Show = true,
Name = "ExposureTime",
Id = (ushort)CustomExifTags.ExposureTime,
ToString = value => ((double)value).DoubleToFraction()
}
};
}
public class Exif
{
public bool Show { get; set; }
public ushort Id { get; set; }
public string Name { get; set; }
public CustomExifTags ExifTag { get; set; }
public new Func<object, string> ToString { get; set; }
}
}
public enum CustomExifTags : ushort
{
ImageWidth = 0x100,
ImageLength = 0x101,
Make = 0x10F,
Model = 0x110,
FocalLength = 0x920A,
FNumber = 0x829D,
ExposureTime = 0x829A,
DateTime = 0x0132,
DateTimeOriginal = 0x9003,
DateTimeDigitized = 0x9004,
ShutterSpeedValue = 0x9201,
ApertureValue = 0x9202,
LensModel=0xa434,
ISOSpeed = 0x8833,
TimeZoneOffset = 0x882A
}
using (var reader = new ExifReader(propertyStream))
{
foreach (var tag in ExifInfo.ExifTagsToCapture)
{
dynamic dynamicValue;
if (reader.GetTagValue(tag.Id, out dynamicValue))
{
var value = tag.ToString((object) dynamicValue);
photo.AddImageProperties(tag.Name, value);
}
}
}
The result of this stored in the database:
"Properties": [
{
"Name": "Camera Make",
"Value": "Canon",
"Show": true
},
{
"Name": "Camera Model",
"Value": "Canon EOS 650D",
"Show": true
},
{
"Name": "Exposure Time",
"Value": "1/80",
"Show": true
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment