Rank: Member
Groups: Guest
Joined: 4/20/2007(UTC) Posts: 9
|
Hello everyone! I'm just wondering whether there is a way to convert the metadata retrieved through the ExifDictionary or IptcDictionary into a human readable format. Would I have to write a converter of my own? If so, how do I get information about the type of data I'm dealing with? E.g. if I've found a byte-array in the "user-comment", how do I tell what encoding to use? Any help would be greatly appreciated. prokop
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello, Could you explain which specific tags do you want to display? You can obtain human-readable string for the most of EXIF tags by using ExifDictionary.GetItemString() method. The same method can be used with IptcDictionary. As for user comment tag - it is a very rarely used field, because still digital cameras doesn't provide any comments usually. By EXIF specification this tag can be stored in different formats - unicode, ASCII, JIS. Here is a small code sample, which reads ASCII user comment field. You can use it as start point for your application.: Code:private string ReadUserComment(string filename)
{
if (filename == null)
throw new System.ArgumentNullException(filename);
string result = null;
Aurigma.GraphicsMill.Codecs.JpegReader reader = new Aurigma.GraphicsMill.Codecs.JpegReader(filename);
byte[] userComment = (byte[])reader.Exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.UserComment];
byte[] asciiSignature = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x00, 0x00, 0x00 };
if (CheckSignature(userComment, asciiSignature))
{
System.Text.Decoder decoder = System.Text.ASCIIEncoding.ASCII.GetDecoder();
char[] chars = new char[decoder.GetCharCount(userComment, 8, userComment.Length - 8)];
decoder.GetChars(userComment, 8, userComment.Length - 8, chars, 0);
result = new String(chars);
}
return result;
}
private bool CheckSignature(byte[] userComment, byte[] signature)
{
if (userComment == null)
throw new System.ArgumentNullException("userComment");
if (signature == null)
throw new System.ArgumentNullException("signature");
if (userComment.Length < signature.Length)
return false;
for (int i = 0; i < signature.Length; i++)
if (userComment[i] != signature[i])
return false;
return true;
}
Edited by user Tuesday, December 18, 2007 3:59:24 AM(UTC)
| Reason: Not specified |
|
|
|
|
Rank: Member
Groups: Guest
Joined: 4/20/2007(UTC) Posts: 9
|
Thank you for your help, which I greatly appreciate! I now fully understand the concept of how to decode the byte arrays. But what about aperture or shutterspeed values. They are formatted for example like this "217706/65536" (shutterspeed). Do I have to use specific formulas to turn this into something like "1/250"? I thought this would be translated by the ExifDictionary. Do you have any code-samples, where the entire content of the exif and/or iptc dictionary is turned into something I could present to an end user? Again, thanks for your help so far! prokop
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello, You may use MetaDataViewer sample as an example of EXIF/IPTC usage. According to your question - I am afraid that you have to convert this value manually. However your idea about ready-to-use user friendly output is great and we will think about its implementation in the future versions of Graphics Mill for .NET. |
|
|
|
|
Rank: Member
Groups: Guest
Joined: 4/20/2007(UTC) Posts: 9
|
hi alex, thanks again for your help. i've got one more question: do you have any code samples where you calculate the values for aperture, shutterspeed, etc. from the textual representation of the fraction returned by the ExifDictionary? i know that there is the exif specification out there and i had a look, but i'm not so qualified at math to know how to do these parially pretty weird operations. and btw, I think that this might be a quite common task. thanks again, matthias
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello Matthias, Sorry for delay, I hope that this information will be helpful for you. So you need to represent ApertureValue and ShutterSpeedValue into human readable format. If you advert to EXIF specification you will find that these values conform in APEX (Additive System of Photographic Exposure) unit system as huge improper fractions, so it can be necessary to convert these values into F-Number and ExposureTime. EXIF specification provides formulas for turning APEX into F-Number (for ApertureValue) and APEX into ExposureTime (for ShutterSpeedValue). See Annex C of EXIF specification for details. Formulas: ApertureValue(F-number) = 2^(ApertureValue(APEX) / 2) ShutterSpeedValue(ExposureTime) = 2^(- ShutterSpeedValue(APEX)) Example: EXIF metadata for some image file contains following values in APEX unit system: ApertureValue = 192/32 = 6 (APEX) ShuttedSpeedValue = 32/32 = 1 (APEX) Now we can calculate F-Number and ExposureTime values: ApertureValue = 2^(6/2) = 2^3 = 8 (F-Number) ShuttedSpeedValue = 2^(-1) = 1/2 (ExposureTime) |
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.