iOS Question Base64 to rotated image

Mark Turney

Active Member
Licensed User
Having an issue whereby when I save an image from SQL to the iOS photo gallery, it is rotated 90 degrees. What would be the best approach to rotate it prior to saving?

Thanks in advance!

Mark Turney

Active Member
Licensed User
I am taking the image in portrait orientation, and just after clicking Use Photo in the camera app, it displays correctly as portrait.

But after saving to SQL as a base64 encoded string, it is always showing as landscape after decoding ... Rotated 90 degrees. So, i have to rotate it to display it correctly in the Imageview. Seems that base64 encoding strips the orientation defaulting to landscape??
Upvote 0

Mark Turney

Active Member
Licensed User
That makes sense. Instead of saving the base64 encoded image as retrieved from SQL, i will use the image within the imageview already, as it is displayed correctly.

Thanks Erel.
Last edited:
Upvote 0

Mark Turney

Active Member
Licensed User
I finally had a chance to get to a computer and test my change. There's nothing like starting out the New Year dumb ... lol :p. All I had to do was save the canvas that was already rotated to the gallery, as opposed to saving the image as stored in SQL.

Here's the code that retrieves, rotates and displays the image during the flashcard subroutine:
Sub ReadBlob                                                                        'Reads pic and name from SQL
    rs = sql1.ExecQuery("select name, picture from table1")
    Dim rowCnt As Int
    'Dim returnedPic As Bitmap
    Dim InputStream1 As InputStream
    Dim Rect As Rect
    Dim imgRt As Int
    Dim imgBt As Int
    Dim xDiv As Int
    xDiv = 100%x / 6
    rowCnt = 0
    flashCards.Width = 4 * xDiv
    flashCards.Height = 6 * xDiv
    imgRt = flashCards.Left + flashCards.Width
    imgBt = flashCards.Top + flashCards.Height
    Do While rs.NextRow
        rowCnt = rowCnt + 1
        If rowCnt = selectedRndRow Then
            returnedName = rs.GetString("name")
            Buffer = rs.GetBlob("picture")
            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
            'flashCards.Bitmap = returnedPic                                        'For testing without rotation
            canvas1.DrawBitmapRotated(returnedPic, Rect, 90)                        'Rotates image after retrieve from SQL
        End If
End Sub

And here is the save image subroutine:
Sub saveImg_Click
    Dim svBmp As Bitmap
    If fcpan1.Visible = True Then
        svBmp = canvas1.CreateBitmap
        tm.ToastMessageShow(returnedName & " saved to Photo Album", True)
    End If
End Sub

Thanks again Erel for guiding me :)!
Upvote 0