views:

278

answers:

4

Thru VB.net/C# is there any way to read any metadata of off a JPEG to tell if the photo was taken in landscape or portrait?

I would assume a camera would need an accelerometer first of all to even tell what direction is up...correct? Assuming there is that kind of intelligence to detect the angle of tilt, how would I go about reading that info from a JPEG?

I found some samples online to read metadata with vb/.net not sure what to read to find the info i need.

Appreciate any pointers.....

A: 

Would it be sufficient to simply compare the width of the JPG image to its height and if width > height, treat as landscape?

I have done this in C# before (although I can't remember the implementation details now but I remember it wasn't particularly difficult, a couple of lines of code only) for a website I worked on which required uploaded JPGs to be displayed within a frame (such as you might hang on your wall) and we needed to know whether to add the landscape or portrait version of the frame.

Alfamale
Only problem with this is you don't know which way the photographer rotated the camera. I always tend to rotate to the left but my (left handed) wife rotates to the right.. the camera that is :-)
CResults
what if someone held the camera at an oblique angle to take the pic? the width will always exceed the height...w/o being able to sense Z direction you wouldnt be able to tell.
ved
Good points. Thinking about it, the project I was involved with could always assume that the image had been processed before upload and thus would arrive in the correct format.
Alfamale
+3  A: 

Yes, there's an EXIF tag that can store the orientation. Tag number 274, values are documented here. Sample code to read the tags from the JPEG data is available here.

Hans Passant
+2  A: 

This project should do what you want:

http://www.codeproject.com/KB/graphics/exifextractor.aspx

And this guy already has an implementation:

http://dotmac.rationalmind.net/2009/08/correct-photo-orientation-using-exif/

roufamatic
thank you...this is great, now I only need to find out if the camera does indeed output orientation info
ved
+2  A: 

A lot of digital cameras now have sensors within them to detect if the picture was taken in landscape or portrait mode. They then store this information in the header of the JPG. This data is known as EXIF.

Here is a pretty good tutorial on extracting the EXIF data from a JPG file. In addition to portrait/landscape info you can also extract (usually) the model/make of camera, lens settings, time/date etc.

http://www.codeproject.com/KB/graphics/NishExifReader.aspx

CResults