Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime-error 481: Invalid picture.

Status
Not open for further replies.

rugrats

MIS
Dec 16, 2002
12
MY
Hi all.
Below is the code I use to display image from SQL 7.0 using VB6 (ADO 2.5). When it comes to image captured by MS ACCESS before, I got error message Invalid Picture. Anybody know how to overcome this? Thank you.

Sub GetAndShowPicture(rs As ADODB.Recordset, strTempFilename as String)
Set stm = New ADODB.Stream
With stm
.Open
.Type = adTypeBinary
.Write rs.Fields("BLOB").value
.SaveToFile strTempFilename, adSaveCreateOverWrite
End With
Image1.Picture = LoadPicture(strTempFilename)
Kill strTempFilename
End Sub

 

I use pretty much the same method to save files from the internet. The only difference in your code and mine is that before I open my stream I tell it which type it is...
[tt]
Dim A As ADODB.Stream
Set A = New ADODB.Stream

A.Type = adTypeBinary
A.Open
A.Write XMLHTTPOBJECT.responseBody
A.SaveToFile FileNameToSaveAs, adSaveCreateOverWrite
A.Close

Set A = Nothing
[/tt]

So I do not think that is the problem. The only thing I can suggest is to look up in ADO help the GetChunck method, because the only thing I can think of is you are not getting all of the data so you end up with a corrupt (incomplete) file.

First things first, if you can save a file to the database and remember its size. Then retrieve it with the code you are using and see if it is the correct/same size when you write it back to disk.

I hope this helps, Good Luck


 
Hi vb5prgrmr, thanks for the tips.
Amazingly I've tried the getchunk method.. below is the code I used (there are few others, this is one of them). To display the picture, I call

Call BlobToFile(rs!BLOBField, "c:\BLOB.dat", _
rs!BLOBField.ActualSize, BLOCK_SIZE)
Set picture1.Picture = LoadPicture("c:\BLOB.dat")

..... and I still got the same error message...'Invalid Picture'. The very same codes work fine with images captured by VB itself. However it just didn't work with those images captured by Access 2000. Microsoft products should be able to 'work' with each other...right?...since they are in the same 'family' group.
Any ideas?

Public Sub BlobToFile(Fld As ADODB.Field, ByVal Fname As String, FieldSize As Long, Threshold As Long) ' = 1048576)
Dim F As Long
Dim bData() As Byte
Dim sData As String

F = FreeFile
Open Fname For Binary As #F
If FieldSize > Threshold Then
WriteFromBinary F, Fld, FieldSize
Else
bData = Fld.value
Put #F, , bData
End If
Close #F
End Sub

Public Sub WriteFromBinary(ByVal F As Long, Fld As ADODB.Field, ByVal FieldSize As Long)
Dim Data() As Byte
Dim BytesRead As Long

Do While FieldSize <> BytesRead
If FieldSize - BytesRead < BLOCK_SIZE Then
Data = Fld.GetChunk(FieldSize - BLOCK_SIZE)
BytesRead = FieldSize
Else
Data = Fld.GetChunk(BLOCK_SIZE)
BytesRead = BytesRead + BLOCK_SIZE
End If
Put #F, , Data
Loop
End Sub
 

Your code looks ok to me...

Have you tried to save say a 500kb file to the database and then write it back to disk to see what file size it is?

One other thing that might be going on (I doubt this one but related to the above) is that you do not give the system enough time to do its garbage collection. Meaning that you have not closed your Stream object before trying to load the picture. Try closing down your stream object to flush the buffer before you try to open the file (loadpicture).

After this I think I am out of help so I hope that the rest of the community might have an idea or this works.

Good Luck

 
Well, it does work with those images captured by VB. But when it comes to images captured by Access, I got stuck: Invalid Picture.

The images that we stored only range between 28Kb to 80Kb. I'll try closing the system object as suggested, if it could help....

FYI, I've even tried using DIBs. still the same error message. Invalid Picture. Boy! this is a tough one!

vb5prgrmr, thanks for your support. Enjoy the X-Mas and a Happy New Year. To all too...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top