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)
.Mode = adModeReadWrite
.Type = adTypeBinary
.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
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.