gyozo kudor
gyozo kudor

Reputation: 6335

Rotate image according to device orientation

I have an app that let's you take pictures and upload them to our server. The problem is sometimes the pictures are upside down, sometimes are rotated left or right. How can i correct this? How can I rotate the image so that it looks ok on the computer after uploaded? Thanks.

Upvotes: 2

Views: 891

Answers (2)

gyozo kudor
gyozo kudor

Reputation: 6335

Here is how i rotated on the server:

    Dim rft As RotateFlipType = RotateFlipType.RotateNoneFlipNone
    Dim properties As PropertyItem() = img.PropertyItems
    For Each prop As PropertyItem In properties
        '274 is the exif id for camera orientation
        If prop.Id = 274 Then
            Dim orientation As Short = BitConverter.ToInt16(prop.Value, 0)
            Select Case orientation
                Case 1
                    rft = RotateFlipType.RotateNoneFlipNone
                    Exit Select
                Case 3
                    rft = RotateFlipType.Rotate180FlipNone
                    Exit Select
                Case 6
                    rft = RotateFlipType.Rotate90FlipNone
                    Exit Select
                Case 8
                    rft = RotateFlipType.Rotate270FlipNone
                    Exit Select
            End Select
            Exit For
        End If
    Next
    If rft <> RotateFlipType.RotateNoneFlipNone Then
        img.RotateFlip(rft)
    End If
    Return rft

Upvotes: -1

yogsototh
yogsototh

Reputation: 15061

You have many solutions:

  • the first is to simply use the current iPhone orientation when the photo is taken. This post should help you. Then use this information to rotate the image when taken on the iPhone.
  • you can also read the EXIF data send to treat this information on the server side.
  • you can also use some javascript to read this EXIF value (which might not be portable).

Upvotes: 2

Related Questions