Using the class EXIFExtractor
implemented and explained here , like this:
var bmp = new Bitmap(pathToImageFile);
var exif = new EXIFextractor(ref bmp, "n");
if (exif["Orientation"] != null)
{
RotateFlipType flip = OrientationToFlipType(exif["Orientation"].ToString());
if (flip != RotateFlipType.RotateNoneFlipNone) // Se a orientação já está correta
{
bmp.RotateFlip(flip);
exif.setTag(0x112, "1");
bmp.Save(pathToImageFile, ImageFormat.Jpeg);
}
}
private static RotateFlipType OrientationToFlipType(string orientation)
{
switch (int.Parse(orientation))
{
case 1:
return RotateFlipType.RotateNoneFlipNone;
break;
case 2:
return RotateFlipType.RotateNoneFlipX;
break;
case 3:
return RotateFlipType.Rotate180FlipNone;
break;
case 4:
return RotateFlipType.Rotate180FlipX;
break;
case 5:
return RotateFlipType.Rotate90FlipX;
break;
case 6:
return RotateFlipType.Rotate90FlipNone;
break;
case 7:
return RotateFlipType.Rotate270FlipX;
break;
case 8:
return RotateFlipType.Rotate270FlipNone;
break;
default:
return RotateFlipType.RotateNoneFlipNone;
}
}
I have taken the example here .
Without EXIF, I think there's no way.