Problems saving a bitmap (1 Viewer)

303factory

Registered User.
Local time
Today, 17:02
Joined
Oct 10, 2008
Messages
136
Good morning

I'm having trouble saving a bitmap from my database to file. It's stored as the 'Image' type in my SQL Server 2008 table, and is put into the table by simply dragging a bitmap file into a bound OLE object

To retrieve it I'm trying the following code:

Code:
  Dim strSQL As String
    Set rs = New ADODB.Recordset
    strSQL = "SELECT * FROM tblExhibitPhotos WHERE ID= 93 "
    rs.Open strSQL, gSQLdbase, adOpenKeyset, adLockOptimistic, adCmdText
    MsgBox (rs.RecordCount)
    Set mstream = New ADODB.Stream
    mstream.Type = adTypeBinary
    mstream.Open
    mstream.Write rs.Fields("Image").Value
    mstream.SaveToFile "c:\Image.bmp", adSaveCreateOverWrite
    rs.Close

This creates a bitmap file in the right location, with a file size that looks about right, but it doesnt open. I've scoured the net and some forums imply that the problem is that the image file wont have correct header information etc. Is there a simple way to convert mystream binary data into a bitmap, or more simply just dump the image field content into the same format it was created with?

As always if you could point me in the right direction ill do the leg work

Regards

303
 

DCrake

Remembered
Local time
Today, 17:02
Joined
Jun 8, 2005
Messages
8,632
You may get better results using FileToBlob and BlobToFile. Here is a Demo that uses this feature. May help you.
 

Khalid_Afridi

Registered User.
Local time
Today, 19:02
Joined
Jan 25, 2009
Messages
491
Thanks Mr. David

I download the dbs, but I always get the missing references on my Access-2007

 

Attachments

  • Broken links.jpg
    Broken links.jpg
    40.2 KB · Views: 692

DCrake

Remembered
Local time
Today, 17:02
Joined
Jun 8, 2005
Messages
8,632
You may need to browse to your Windows\system32 folder to register it.

This is the Microsoft Common Dialog control
 

DCrake

Remembered
Local time
Today, 17:02
Joined
Jun 8, 2005
Messages
8,632
Design a module and select Tools > References from the menu. It should say Missing against the offending ocx. Browse to Windows\system32\ to find it and select Ok to register it.
 

Khalid_Afridi

Registered User.
Local time
Today, 19:02
Joined
Jan 25, 2009
Messages
491
David

I found it and fixed it. It was common dialogue control which was giving the problem.




I delete the Missing Reference after registering the Microsoft Windows Common Dialogue 6.0.

Thanks
 

Attachments

  • comondialog.jpg
    comondialog.jpg
    71.5 KB · Views: 447

303factory

Registered User.
Local time
Today, 17:02
Joined
Oct 10, 2008
Messages
136
You may get better results using FileToBlob and BlobToFile. Here is a Demo that uses this feature. May help you.

Thanks kindly for the demo code. I included the MobBLob module in my client and tried the following:

Code:
Dim strSQL As String
    Set rs = New ADODB.Recordset
    strSQL = "SELECT * FROM tblExhibitPhotos WHERE ID= 93 "
    rs.Open strSQL, gSQLdbase, adOpenKeyset, adLockOptimistic, adCmdText
    
    Call BlobToFile(rs.Fields("Image"), "C:\Image.bmp", rs.Fields("Image").ActualSize)
    
    rs.Close
    Set rs = Nothing

However I'm getting the same problem, the image still isnt recognised as a valid bitmap
 

303factory

Registered User.
Local time
Today, 17:02
Joined
Oct 10, 2008
Messages
136
If I were to approach this problem from a different angle.

Is it possible to have a continuous subform with image objects referencing image paths on a hard disk?

I can do this fine for a single form with one image, but I need a 1:many relationship with N images, with a different image appearing on each unit of teh subform.

I assumed this was impossible hence using bound OLE ojects but will change the way it works if getting OLE objects back to file is a massive pain in the backside...
 

Users who are viewing this thread

Top Bottom