Orientation is wrong when server creates thumbnail for camera images

Posted: March 5, 2015 in .Net/C#

I have this iOS app that uploading camera image to server and server will create a thumbnail from the uploaded image. The original image is in portrait, but the thumbnail generated is rotated as landscape.

After some search i found that it’s because of the EXIF orientation flag in digital camera images. For details on EXIF orientation, can be found here. http://www.impulseadventure.com/photo/exif-orientation.html

Below is the sample code to rotate the image in C#.

public static void rotateImageIfNecessary(Image image)
    if (image.PropertyIdList.Contains<int>(0x0112))
         int rotationValue = image.GetPropertyItem(0x0112).Value[0];
         switch (rotationValue)
              case 1: //landscape
              case 3: //bottoms up
                   image.RotateFlip(rotateFlipType: RotateFlipType.Rotate180FlipNone);
              case 6: //rotated 90 left
                   image.RotateFlip(rotateFlipType: RotateFlipType.Rotate90FlipNone);
              case 8: //rotated 90 right
                   image.RotateFlip(rotateFlipType: RotateFlipType.Rotate270FlipNone);

Credit: http://stackoverflow.com/questions/17186568/upload-from-ios-picture-to-net-app-rotate


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s