Click to See Complete Forum and Search --> : inserting images


spuppett
October 25th, 2004, 02:56 PM
Is there a way to insert a picture into a general field in foxpro from within VB? I tried

data1.recordset.fields("pic").value = loadpicture(path)

but I got a type mis-match error.

Anyone have a solution or suggestion?

spuppett
October 26th, 2004, 10:05 AM
Anyone, Anyone at all?

jp140768
October 26th, 2004, 11:36 AM
I don't use Fox Pro, but in Access there is a field of type OLE, which allows me to store long binary information in here.


What I do, is open the image in binary format, read it in and use AppendChunk to write it out to the binary field.


Dim adrImage As ADODB.RecordsetConst BlockSize = 1024
Dim intFreeFile As Integer
Dim lngFileLen As Long
Dim lngNumBlocks As Long
Dim lngLeftOver As Long
Dim lngCount As Long
Dim lngColSize As Long
Dim strData As String

If Dir("c:\temp\imgLoad.img") <> "" Then
Kill "c:\temp\imgLoad.img"
End If
intFreeFile = FreeFile
Open "c:\temp\imgLoad.img" For Binary As intFreeFile

With adrImage
lblAddedWhen = .Fields("AddedWhen")
txtDescription = .Fields("Description")
lngColSize = .Fields("Image").ActualSize lngNumBlocks = lngColSize \ BlockSize
lngLeftOver = lngColSize Mod BlockSize
For lngCount = 1 To lngNumBlocks strData = String(BlockSize, 0)
strData = .Fields("Image").GetChunk(BlockSize)
Put intFreeFile, , strData
Next
strData = String(lngLeftOver, 0) strData = .Fields("Image").GetChunk(lngLeftOver)
Put intFreeFile, , strData
End With
Close intFreeFile
imgPasteImage = LoadPicture("c:\temp\imgLoad.img")


The above will retrieve a picture from the database, but its similar to save a picture. If you want the code to save an image, I can look it out for you.

Actually there is an article in Code Guru which you may be able to use:
http://www.codeguru.com/vb/gen/vb_database/sqlserver/article.php/c7427/

There was another one, about storing BLOBs, but I can't find it.

Hopefully this though should point you in the right direction.