Upload system with rotate image automatically as in windows 8.1 or facebook

Today when viewing an image in windows 8.1 even if the image is lying it automatically understands and shows correctly, in windows 7 The Lying image appears. When sending this image to sites like facebook it appears correct. But when sending to a normal upload it appears lying down.

I thought the system read the EXIF of the photo but the image was made by a camera that apparently had no system to know if it was lying or in foot.

How to make a class / component that understands that photo and automatically turns it over?

Author: Dorathoto, 2015-03-05

1 answers

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 took the example from here .

Without the EXIF I think there is no way.

 2
Author: Leonel Sanches da Silva, 2015-03-20 20:42:08