You need to examine the image and extract the orientation information from the exif tags.
The first thing you'll need to do is get an exif reader. There's one written in VB.NET on Code Project for example.
If you load the file into an Image
you will be able to read the EXIF properties from the PropertyItems
(as this C# code demonstrates):
using (Image image = Image.FromFile(imageName))
{
// Non property item properties
this.FileName = imageName;
PixelFormat = image.PixelFormat;
this.Width = image.Size.Width;
this.Height = image.Size.Height;
foreach (PropertyItem pi in image.PropertyItems)
{
EXIFPropertyItem exifpi = new EXIFPropertyItem(pi);
this.propertyItems.Add(exifpi);
}
}
Where EXIFPropertyItem
is a class that converts the PropertyItem
. The PropertyItem
's Id
is the EXIF code (Orientation being 0x0112
).
Then look for the the Orientation property and read it's value. Values 5, 6, 7 and 8 are for portrait (vertical) images, 6 being rotate 90 and 8 being rotate -90 for example.
Once you've got the orientation you can then call the appropriate rotation transformation to display the image in the correct orientation.