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

3

Today when viewing an image in windows 8.1 even if the image is lying down it automatically understands and shows correctly, in windows 7 the image lying down appears. When sending this image to sites like facebook it appears correct. However, 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 standing.

How to make a class / component that understands this photo and turn it automatically?

    
asked by anonymous 05.03.2015 / 16:33

1 answer

2

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.

    
20.03.2015 / 21:42