ExIf Bytes

I am victorious over ExIf! The documentation for ExIf overcomplicates things. While ExIf uses a lot of different types (0x1 through 0xA), it is possible to interact with most common values utilizing only 2 of these, 0x2 and 0x5. 0x2 is the null terminated string, and 0x5 is the 2 pair of Long Ints, acting as a rational. It would also seem that even though the documentation suggests that length only matters for 0x2, it cares for all of them, so it is a must to give the length of the byte array used to carry the long ints. A small error on my part was trying to convert directly from String (because I used System.Window.Forms.TextBox to get the information) to byte[] without passing through the intermediate int, or trying to convert to byte[] from double, which was very nasty. I learned these little tricks about things by reading in ExIf information in the application itself without the aid of any little helper apps that try to clean things up, it make the structure a lot more clear.

For anyone else trying a similar exercise in futility, here is a bit of my code:


if (Type == 0x2)

{

tmpProp.Len = value.Length + 1;

value = value + nullChar;

tmpProp.Value = ASCIIEncoding.ASCII.GetBytes(value);

}

else
if (Type == 0x5)

{

 


Byte[] tmp1 = BitConverter.GetBytes(Convert.ToInt32(value.Split(‘/’)[0]));


Byte[] tmp2 = BitConverter.GetBytes(Convert.ToInt32(value.Split(‘/’)[1]));


Byte[] tmp3 = new
Byte[tmp1.Length + tmp2.Length];

tmp1.CopyTo(tmp3,0);

tmp2.CopyTo(tmp3, tmp1.Length);

 

tmpProp.Value = tmp3;

tmpProp.Len = tmp3.Length;

}

I love C#, so simple, but yet such a pain in the ass, all at once.