views:

51

answers:

2

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.

+1  A: 

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).
yogsototh
Thanks for the answer for me the most simple was to read the exif data from the uploaded image and rotate on the server. I also tryed rotating the image on the iPhone but then it doesn't look good on the phone only on the computer.
kudor gyozo
A: 

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
kudor gyozo