troubleshooting Question

Remove Exif Orientation before adding image to db

Avatar of JedNebula
JedNebulaFlag for United Kingdom of Great Britain and Northern Ireland asked on
Visual Basic Classic* vb6
9 Comments1 Solution675 ViewsLast Modified:
We use the following VB6 function to add images to a SQL database.

Public Function AddJPEGImageToDatabase(strPath As String, Optional ImageID As Long = -1) As Long
    Dim rec As New ADODB.Recordset
    Dim picStream As New ADODB.Stream
    Dim conn As ADODB.Connection
    Dim strSQL As String
    Dim Pic As StdPicture

        Set conn = GetADOConnectionObject
        strSQL = "SELECT * FROM dbo.ImageData WHERE ImageID = " & ImageID
        rec.Open strSQL, conn, adOpenDynamic, adLockOptimistic
        Set Pic = LoadPicture(strPath)
        With picStream
            .Mode = adModeReadWrite
            .Type = adTypeBinary
            Call .LoadFromFile(strPath)
            .Position = 0
            If ImageID = -1 Then rec.AddNew
            rec("ImageData") = .Read
            rec("ImageX") = (Pic.Width / 1000) * (567 / Screen.TwipsPerPixelX)
            rec("ImageY") = (Pic.Height / 1000) * (567 / Screen.TwipsPerPixelY)
            strPath = GetRightBit(strPath, "\")
            strPath = Replace(strPath, " ", "-")
            strPath = ReplaceIllegalKeystrokes(strPath, True, True)
            rec("ImageFileName") = strPath
            AddJPEGImageToDatabase = rec("ImageID")
            Set rec = Nothing
            Set Pic = Nothing
            Set picStream = Nothing
        End With

End Function

Recently, we have had a few reports of users saying that images they have taken with their own digital cameras are importing into our software rotated 90 degrees. We since found out that is down to the EXIF data stored in the jpeg by the camera.

Up until now, we have been able to fob the clients off with a utility to remove this EXIF data themselves before importing, but it is starting to require a better solution now.

I have done a little bit of Googling about rotating a StdPicture object in VB6 and haven't been able to find a simple solution. Most of the suggestions include drawing the image manually on the form (but rotated). However, as I am hoping to store the image in the database (with the correct orientation) I think I either need to rotate the actual stdPicture, or remove the EXIF orientation tag before loading.

Thoughts welcome & appreciated.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros