[WPF]EXIF情報の取得の仕方


C#/WPFは標準でEXIFなどのメタ情報を画像ファイルから取得する機能があります。
該当するクラスは以下です。

BitmapMetadata

画像ファイルからこのクラスのインスタンスを取得するには以下のように行います。

using (var stream = new FileStream(szFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
BitmapFrame image = BitmapFrame.Create(new Uri(szFile), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
BitmapMetadata metaData = (BitmapMetadata)m_Image.Metadata;
}

szFile には絶対パスが入ります。 **


メタ情報は以下のよう取得します。

private object GetMetaInfo(string infoQuery)
{
if (m_MetaData.ContainsQuery(infoQuery))
return m_MetaData.GetQuery(infoQuery);
else
return null;
}

上記の関数でEXIFの横幅情報を得るには以下のようにします。

object obj = GetMetaInfo("/app1/ifd/exif/subifd:{uint=40962}");
int Width = Convert.ToUInt32(obj);

参考
Code Project Retrieving EXIF information of an image in .NET 3.0

0 件のコメント :

コメントを投稿