using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Media.Imaging;
namespace WPFExifInfo
{
public class ExifMetaInfo
private BitmapMetadata _metaInfo;
public ExifMetaInfo(Uri imageUri)
BitmapFrame bFrame = BitmapFrame.Create(imageUri, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
_metaInfo = (BitmapMetadata)bFrame.Metadata;
}
private void buildDB(System.Drawing.Imaging.PropertyItem[] parr)
properties.Clear();
//
data = "";
Encoding ascii = Encoding.ASCII;
foreach (System.Drawing.Imaging.PropertyItem p in parr)
string v = "";
string name = (string)myHash[p.Id];
// tag not found. skip it
if (name == null) continue;
data += name + ": ";
//My code starts here
if (p.Id == 0x0004)
//lat
// rational
byte[] deg = new byte[4];
byte[] degdiv = new byte[4];
byte[] min = new byte[4];
byte[] mindiv = new byte[4];
byte[] sec = new byte[4];
byte[] secdiv = new byte[4];
Array.Copy(p.Value, 0, deg, 0, 4);
Array.Copy(p.Value, 4, degdiv, 0, 4);
Array.Copy(p.Value, 8, min, 0, 4);
Array.Copy(p.Value, 12, mindiv, 0, 4);
Array.Copy(p.Value, 16, sec, 0, 4);
Array.Copy(p.Value, 20, secdiv, 0, 4);
double a = convertToInt32U(deg);
double b = convertToInt32U(degdiv);
double c = convertToInt32U(min);
double d = convertToInt32U(mindiv);
double e = convertToInt32U(sec);
double f = convertToInt32U(secdiv);
double o = ((a / b) + ((c / b) / 60) + ((e / f) / 3600));
v = o.ToString();
// Rational r = new Rational(a, b);
else if (p.Id == 0x0002)
//long
//My Code ends here
/*
private object GetMetaInfo(string infoQuery)
if (_metaInfo.ContainsQuery(infoQuery))
return _metaInfo.GetQuery(infoQuery);
else
return null;
public uint? Width
get
object obj = GetMetaInfo("/app1/ifd/exif/subifd:{uint=40962}");
if (obj == null)
if (obj.GetType() == typeof(UInt32))
return (uint)obj;
return Convert.ToUInt32(obj);
public uint? Height
object obj = GetMetaInfo("/app1/ifd/exif/subifd:{uint=40963}");
public string EquipmentManufacturer
object val = GetMetaInfo("/app1/ifd/exif:{uint=271}");
return (val != null ? (string)val : String.Empty);
public string CameraModel
object val = GetMetaInfo("/app1/ifd/exif:{uint=272}");
public string CreationSoftware
object val = GetMetaInfo("/app1/ifd/exif:{uint=305}");
public ColorRepresentation ColorRepresentation
if ((ushort)GetMetaInfo("/app1/ifd/exif/subifd:{uint=40961}") == 1)
return ColorRepresentation.sRGB;
return ColorRepresentation.Uncalibrated;
public decimal? ExposureTime
object val = GetMetaInfo("/app1/ifd/exif/subifd:{uint=33434}");
if (val != null)
return ParseUnsigned((ulong)val);
public decimal? LensAperture
object val = GetMetaInfo("/app1/ifd/exif/subifd:{uint=33437}");
public decimal? FocalLength
object val = GetMetaInfo("/app1/ifd/exif/subifd:{uint=37386}");
public ushort? IsoSpeed
return (ushort?)GetMetaInfo("/app1/ifd/exif/subifd:{uint=34855}");
public FlashMode FlashMode
if ((ushort)GetMetaInfo("/app1/ifd/exif/subifd:{uint=37385}") % 2 == 1)
return FlashMode.FlashFired;
return FlashMode.FlashNotFire;
private decimal ParseUnsigned(ulong exifValue)
return (decimal)(exifValue & 0xFFFFFFFFL) / (decimal)((exifValue & 0xFFFFFFFF00000000L) >> 32);
public enum ColorRepresentation
sRGB,
Uncalibrated
public enum FlashMode
FlashFired,
FlashNotFire
[/quote]