Rational numbers in exif info.

  • Thread starter Thread starter Martin Stainsby
  • Start date Start date
M

Martin Stainsby

I'm not sure whether I am approaching this correctly?

I'm trying to get the focal length from exif info stored in an image.

The Visual studio help says it is stored in "An array of two Byte objects
that represent a rational number".
Yet there are eight bytes in the info? shown below.

89 00 00 00 0A 00 00 00

Are these supposed to be 2 byte or 4 byte objects, or am I completely
misunderstanding this rational number gizmo?


Both these if statements below retrieve the correct focal length 13.7 that I
expect, I'm just not sure if I am approaching the problem correctly in
either case?


if(propertyItem.Id == 0x920A)
{
int a = BitConverter.ToInt32(propItems[count].Value,0);
int b = BitConverter.ToInt32(propItems[count].Value,4);
double focalLength = (double)a/b;
}


if(propertyItem.Id == 0x920A)
{
short a = BitConverter.ToInt16(propItems[count].Value,0);
short b = BitConverter.ToInt16(propItems[count].Value,4);
double focalLength = (double)a/b;
}


Some guidance would be really appreciated.
Thanks
Martin.
 
I've now noticed that where Visual studio's help states.

"An array of two Byte objects that represent a rational number".


The Exif standard has it as.

"Two Long's".

Assuming that a long in this case is 4 bytes (32 bits) then that would make
more sense for 8 bytes of data.

One more question:
What is an SRational or an SLONG. How do these differ from a Rational or
LONG?
 
You need to be using 4 byte values, so int is correct, not short. So your
first if statement is the correct one.

Chris R.
 
The 'S' stands for signed, so that, actually, Rational should use uint/uint
and SRational should use int/uint.
SLONG, in the case of exif, jpeg, and tif files, is a 4 byte signed int
(Int32). LONG is equivalent to UInt32.

Chris R.
 
Chris R said:
The 'S' stands for signed, so that, actually, Rational should use uint/uint
and SRational should use int/uint.
SLONG, in the case of exif, jpeg, and tif files, is a 4 byte signed int
(Int32). LONG is equivalent to UInt32.

Chris R.

Thanks Chris that's been most helpful
 
Back
Top