-
[VB6] - animated gif function errors:(
i have found these animated gif function on internet:
Code:
Option Explicit
Public RepeatTimes As Long 'This one calculates,
' but don't use in this sample. If You need, You
' can add simple checking at Timer1_Timer Procedure
Public TotalFrames As Long
Public Function LoadGif(sFile As String, aImg As Variant) As Boolean
LoadGif = False
If Dir$(sFile) = "" Or sFile = "" Then
MsgBox "File " & sFile & " not found", vbCritical
Exit Function
End If
On Error GoTo ErrHandler
Dim fNum As Integer
Dim imgHeader As String, fileHeader As String
Dim buf$, picbuf$
Dim imgCount As Integer
Dim i&, j&, xOff&, yOff&, TimeWait&
Dim GifEnd As String
GifEnd = Chr(0) & Chr(33) & Chr(249)
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
'incorrect
j = InStr(1, buf, GifEnd) + 1
fileHeader = Left(buf, j)
'.....
If Left$(fileHeader, 3) <> "GIF" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
LoadGif = True
i = j + 2
If Len(fileHeader) >= 127 Then
RepeatTimes& = Asc(Mid(fileHeader, 126, 1)) + (Asc(Mid(fileHeader, 127, 1)) * 256&)
Else
RepeatTimes = 0
End If
Do ' Split GIF Files at separate pictures
' and load them into Image Array
imgCount = imgCount + 1
j = InStr(i, buf, GifEnd) + 3
If j > Len(GifEnd) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + j - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, j - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, j - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256&)) * 10&
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256&)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256&)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
' Use .Tag Property to save TimeWait interval for separate Image
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
i = j
End If
DoEvents
Loop Until j = 3
' If there are one more Image - Load it
If i < Len(buf) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + Len(buf) - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, Len(buf) - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256)) * 10
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
End If
TotalFrames = aImg.Count - 1
Exit Function
ErrHandler:
MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
LoadGif = False
On Error GoTo 0
End Function
but i found, at least, 1 error:
Code:
'incorrect
j = InStr(1, buf, GifEnd) + 1
fileHeader = Left(buf, j)
'.....
why i know that isn't correct??? because i have test 1 static gif and the fileHeader result was "G" instead "GIF". that's why i know that isn't correct.
can anyone advice me?
-
Re: [VB6] - animated gif function errors:(
can't you compare if it has a G as the first letter then? (im not sure how this works i havent tried it)
Code:
j = InStr(1, buf, GifEnd) + 1
fileHeader = Left(buf, j)
'.....
If Left$(fileHeader, 1) <> "G" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
I know this will not make SURE it is a gif file
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
Max187Boucher
can't you compare if it has a G as the first letter then? (im not sure how this works i havent tried it)
Code:
j = InStr(1, buf, GifEnd) + 1
fileHeader = Left(buf, j)
'.....
If Left$(fileHeader, 1) <> "G" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
I know this will not make SURE it is a gif file
thanks for that sugestion;)
but i still having problems reading more gif files:(
can anyone advice me?
-
Re: [VB6] - animated gif function errors:(
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
What are you doing?
updating my Sprite control on windows 7. because some tools\controls that i have don't works on windows seven:(
-
Re: [VB6] - animated gif function errors:(
So what does that have to do with your request animated gif function errors
What are you doing with gif images that you get error?
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
So what does that have to do with your request animated gif function errors
What are you doing with gif images that you get error?
i found that code on internet for read animated gif's files(can't read some files and methods gif files(animated gif files diferent formats)).
these function put all subimages in a picturebox array. then, using a timer, i show what subimage i need;)
-
Re: [VB6] - animated gif function errors:(
In the call statement
LoadGif(sFile As String, aImg As Variant)
what is aImg? Is it a value? A Image control? What?
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
In the call statement
LoadGif(sFile As String, aImg As Variant)
what is aImg? Is it a value? A Image control? What?
can be a picturebox\imagebox
-
Re: [VB6] - animated gif function errors:(
That's what I thought it was but when I pass it the name of an Image array (three images - Image1(0), Image1(1), Image1(2)) like this
LoadGif App.Path & "\Animated.gif", Image1
it fails here:
Code:
For i = 1 To aImg.Count - 1
Unload aImg(i) '<----------- Fails when trying to unload Image1(1) - That doesn't make sense
Next i
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
That's what I thought it was but when I pass it the name of an Image array (three images - Image1(0), Image1(1), Image1(2)) like this
LoadGif App.Path & "\Animated.gif", Image1
it fails here:
Code:
For i = 1 To aImg.Count - 1
Unload aImg(i) '<----------- Fails when trying to unload Image1(1) - That doesn't make sense
Next i
i know why:
you need an if that put that for in it:
Code:
if aImg.Count >1 then
For i = 1 To aImg.Count - 1
Unload aImg(i) '<----------- Fails when trying to unload Image1(1) - That doesn't make sense
Next i
end if
sorry about that
-
Re: [VB6] - animated gif function errors:(
What problems are you having?
Why do you say this is incorrect?
Code:
'incorrect
j = InStr(1, buf, GifEnd) + 1
fileHeader = Left(buf, j)
'.....
I got it to work by commenting out some code lines.
Code:
Public Function LoadGif(sFile As String, aImg As Object) As Boolean 'Variant) As Boolean
LoadGif = False
If Dir$(sFile) = "" Or sFile = "" Then
MsgBox "File " & sFile & " not found", vbCritical
Exit Function
End If
On Error GoTo ErrHandler
Dim fNum As Integer
Dim imgHeader As String, fileHeader As String
Dim buf$, picbuf$
Dim imgCount As Integer
Dim i&, j&, xOff&, yOff&, TimeWait&
Dim GifEnd As String
GifEnd = Chr(0) & Chr(33) & Chr(249) ' my animated gif has 04 00 3B
cc = aImg.Count
' For i = 1 To aImg.Count - 1
' Unload aImg(i)
' Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
'incorrect
j = InStr(1, buf, GifEnd) + 1
fileHeader = Left(buf, j)
'.....
If Left$(fileHeader, 3) <> "GIF" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
LoadGif = True
i = j + 2
If Len(fileHeader) >= 127 Then
RepeatTimes& = Asc(Mid(fileHeader, 126, 1)) + (Asc(Mid(fileHeader, 127, 1)) * 256&)
Else
RepeatTimes = 0
End If
Do ' Split GIF Files at separate pictures
' and load them into Image Array
imgCount = imgCount + 1
j = InStr(i, buf, GifEnd) + 3
If j > Len(GifEnd) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + j - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, j - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, j - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256&)) * 10&
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256&)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256&)
' Load aImg(imgCount - 1)
' aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
' aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
' Use .Tag Property to save TimeWait interval for separate Image
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
i = j
End If
DoEvents
Loop Until j = 3
' If there are one more Image - Load it
If i < Len(buf) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + Len(buf) - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, Len(buf) - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256)) * 10
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256)
' Load aImg(imgCount - 1)
' aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
' aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
End If
TotalFrames = aImg.Count - 1
Exit Function
ErrHandler:
MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
LoadGif = False
On Error GoTo 0
End Function
-
Re: [VB6] - animated gif function errors:(
That doesn't make any difference because I already had more than 1
Code:
if aImg.Count >1 then
For i = 1 To aImg.Count - 1
Unload aImg(i) '<----------- Fails when trying to unload Image1(1) - That doesn't make sense
Next i
end if
That error should not occur as I have had several objects on the Form and have been able to unload all of them except Index 0 so I don't understand why that caused an error.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
That doesn't make any difference because I already had more than 1
Code:
if aImg.Count >1 then
For i = 1 To aImg.Count - 1
Unload aImg(i) '<----------- Fails when trying to unload Image1(1) - That doesn't make sense
Next i
end if
don't forget that index can start from 0(zero);)
and i correct some errors hehehe
Code:
Option Explicit
Public RepeatTimes As Long 'This one calculates,
' but don't use in this sample. If You need, You
' can add simple checking at Timer1_Timer Procedure
Public TotalFrames As Long
Public Function LoadGif(sFile As String, aImg As Variant) As Boolean
LoadGif = False
If Dir$(sFile) = "" Or sFile = "" Then
MsgBox "File " & sFile & " not found", vbCritical
Exit Function
End If
On Error GoTo ErrHandler
Dim fNum As Integer
Dim imgHeader As String, fileHeader As String
Dim buf$, picbuf$
Dim imgCount As Integer
Dim i&, j&, xOff&, yOff&, TimeWait&
Dim GifEnd As String
GifEnd = Chr(0) & Chr(33) & Chr(249)
If aImg.Count > 1 Then
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
End If
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
j = InStr(1, buf, GifEnd) + 1
fileHeader = left(buf, j)
If left$(fileHeader, 1) <> "G" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
LoadGif = True
i = j + 2
If Len(fileHeader) >= 127 Then
RepeatTimes& = Asc(Mid(fileHeader, 126, 1)) + (Asc(Mid(fileHeader, 127, 1)) * 256&)
Else
RepeatTimes = 0
End If
Do ' Split GIF Files at separate pictures
' and load them into Image Array
imgCount = imgCount + 1
j = InStr(i, buf, GifEnd) + 3
If j > Len(GifEnd) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + j - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, j - i)
Put #fNum, 1, picbuf
imgHeader = left(Mid(buf, i - 1, j - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256&)) * 10&
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256&)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256&)
Load aImg(imgCount - 1)
aImg(imgCount - 1).left = aImg(0).left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).top = aImg(0).top + (yOff * Screen.TwipsPerPixelY)
End If
' Use .Tag Property to save TimeWait interval for separate Image
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
i = j
End If
DoEvents
Loop Until j = 3
' If there are one more Image - Load it
If i < Len(buf) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + Len(buf) - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
Put #fNum, 1, picbuf
imgHeader = left(Mid(buf, i - 1, Len(buf) - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256)) * 10
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256)
Load aImg(imgCount - 1)
aImg(imgCount - 1).left = aImg(0).left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).top = aImg(0).top + (yOff * Screen.TwipsPerPixelY)
End If
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
End If
TotalFrames = aImg.Count - 1
Exit Function
ErrHandler:
On Error GoTo 0
aImg(0).Picture = Nothing
aImg(0).Picture = LoadPicture(sFile)
TotalFrames = aImg.Count - 1
End Function
now if the image static gives me an error, i can show it in tradicional way lol
thanks
seems that works fine. but now i must do the method stuff for read all animated gifs;)
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
I modified your .bas code to catch when a image is not animated. This is the case with the following images:
image 1(these image don't read correctly, that's why on error i use the loadpicture()).gif
image 2(these image don't read correctly, that's why on error i use the loadpicture()).gif
Nível2.gif
SonicTheHedgehog.gif
They load OK it's just that the code didn't allow for non animated images:
Code has this in it:
Code:
'
'
'
GifEnd = Chr(0) & Chr(33) & Chr(249) '<---only for animated GIF's
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
j = InStr(1, buf, GifEnd) + 1 '<----- j = 1 or 0 if not an animated gif ---- j > 1 if it is an animated gif
'
'
'
I added a catch for that. I restored your Error trap back to the way it was and moved the code you put there up above because it is really not an error:
Code:
Option Explicit
Public RepeatTimes As Long 'This one calculates,
' but don't use in this sample. If You need, You
' can add simple checking at Timer1_Timer Procedure
Public TotalFrames As Long
Public Function LoadGif(sFile As String, aImg As Variant) As Boolean
LoadGif = False
If Dir$(sFile) = "" Or sFile = "" Then
MsgBox "File " & sFile & " not found", vbCritical
Exit Function
End If
On Error GoTo ErrHandler
Dim fNum As Integer
Dim imgHeader As String, fileHeader As String
Dim buf$, picbuf$
Dim imgCount As Integer
Dim i&, j&, xOff&, yOff&, TimeWait&
Dim GifEnd As String
GifEnd = Chr(0) & Chr(33) & Chr(249)'<---only for animated GIF's
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
j = InStr(1, buf, GifEnd) + 1 '<--- j = 1 or 0 if not a animated gif ---- j > 1 if it is an animated gif
If j < 2 Then
aImg(0).Picture = LoadPicture(sFile)
TotalFrames = aImg.Count - 1
aImg(0).Tag = 0
LoadGif = True
frmTest.Label1.Caption = "Gif is not animated"
Exit Function
End If
fileHeader = Left(buf, j)
If Left$(fileHeader, 1) <> "G" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
LoadGif = True
i = j + 2
If Len(fileHeader) >= 127 Then
RepeatTimes& = Asc(Mid(fileHeader, 126, 1)) + (Asc(Mid(fileHeader, 127, 1)) * 256&)
Else
RepeatTimes = 0
End If
Do ' Split GIF Files at separate pictures
' and load them into Image Array
imgCount = imgCount + 1
j = InStr(i, buf, GifEnd) + 3
If j > Len(GifEnd) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + j - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, j - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, j - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256&)) * 10&
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256&)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256&)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
' Use .Tag Property to save TimeWait interval for separate Image
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
i = j
End If
DoEvents
Loop Until j = 3
' If there are one more Image - Load it
If i < Len(buf) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + Len(buf) - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, Len(buf) - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256)) * 10
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
End If
TotalFrames = aImg.Count - 1
frmTest.Label1.Caption = ""
Exit Function
ErrHandler:
MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
LoadGif = False
On Error GoTo 0
End Function
Add a Label1 to your Form to show that images is not animated
Ok, that takes care of that. Now, the other problem with this image:
halloween46(these image use methods).gif
This image is not like the other ones. It uses 6 frames as shown in the attached image. Each image has an attribute set that says "Leave" which means to leave the current frame as is and put the next frame on top of it which results in all frames being put on top of each other. Your Timer1 code does not allow for this so you wind up getting a new frame without any background to it so you get that funny look when it shows frames 2, 5, and 6. Note the red color. This is the transparent color so if frame 2 was placed on top of frame 1 you would see the door behind the words Ding Dong because the red allows the door to show through any red color but you don't do this; you make the previous frame invisible. This approach works for the other gif images but not for this one. The problem is the gif code you have doesn't take this into consideration and as far as your code goes (your Timer1 code) it doesn't know the differeence between the two types of images. Unfortunately I don't know how to solve this problem with in the gif code you have. I have a method that works but then it will fail for the other gif images and you have no way of knowing which routine to use.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
I modified your .bas code to catch when a image is not animated. This is the case with the following images:
image 1(these image don't read correctly, that's why on error i use the loadpicture()).gif
image 2(these image don't read correctly, that's why on error i use the loadpicture()).gif
Nível2.gif
SonicTheHedgehog.gif
They load OK it's just that the code didn't allow for non animated images:
Code has this in it:
Code:
'
'
'
GifEnd = Chr(0) & Chr(33) & Chr(249) '<---only for animated GIF's
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
j = InStr(1, buf, GifEnd) + 1 '<----- j = 1 or 0 if not an animated gif ---- j > 1 if it is an animated gif
'
'
'
I added a catch for that. I restored your Error trap back to the way it was and moved the code you put there up above because it is really not an error:
Code:
Option Explicit
Public RepeatTimes As Long 'This one calculates,
' but don't use in this sample. If You need, You
' can add simple checking at Timer1_Timer Procedure
Public TotalFrames As Long
Public Function LoadGif(sFile As String, aImg As Variant) As Boolean
LoadGif = False
If Dir$(sFile) = "" Or sFile = "" Then
MsgBox "File " & sFile & " not found", vbCritical
Exit Function
End If
On Error GoTo ErrHandler
Dim fNum As Integer
Dim imgHeader As String, fileHeader As String
Dim buf$, picbuf$
Dim imgCount As Integer
Dim i&, j&, xOff&, yOff&, TimeWait&
Dim GifEnd As String
GifEnd = Chr(0) & Chr(33) & Chr(249)'<---only for animated GIF's
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
j = InStr(1, buf, GifEnd) + 1 '<--- j = 1 or 0 if not a animated gif ---- j > 1 if it is an animated gif
If j < 2 Then
aImg(0).Picture = LoadPicture(sFile)
TotalFrames = aImg.Count - 1
aImg(0).Tag = 0
LoadGif = True
frmTest.Label1.Caption = "Gif is not animated"
Exit Function
End If
fileHeader = Left(buf, j)
If Left$(fileHeader, 1) <> "G" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
LoadGif = True
i = j + 2
If Len(fileHeader) >= 127 Then
RepeatTimes& = Asc(Mid(fileHeader, 126, 1)) + (Asc(Mid(fileHeader, 127, 1)) * 256&)
Else
RepeatTimes = 0
End If
Do ' Split GIF Files at separate pictures
' and load them into Image Array
imgCount = imgCount + 1
j = InStr(i, buf, GifEnd) + 3
If j > Len(GifEnd) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + j - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, j - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, j - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256&)) * 10&
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256&)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256&)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
' Use .Tag Property to save TimeWait interval for separate Image
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
i = j
End If
DoEvents
Loop Until j = 3
' If there are one more Image - Load it
If i < Len(buf) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + Len(buf) - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, Len(buf) - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256)) * 10
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
End If
TotalFrames = aImg.Count - 1
frmTest.Label1.Caption = ""
Exit Function
ErrHandler:
MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
LoadGif = False
On Error GoTo 0
End Function
Add a Label1 to your Form to show that images is not animated
Ok, that takes care of that. Now, the other problem with this image:
halloween46(these image use methods).gif
This image is not like the other ones. It uses 6 frames as shown in the attached image. Each image has an attribute set that says "Leave" which means to leave the current frame as is and put the next frame on top of it which results in all frames being put on top of each other. Your Timer1 code does not allow for this so you wind up getting a new frame without any background to it so you get that funny look when it shows frames 2, 5, and 6. Note the red color. This is the transparent color so if frame 2 was placed on top of frame 1 you would see the door behind the words Ding Dong because the red allows the door to show through any red color but you don't do this; you make the previous frame invisible. This approach works for the other gif images but not for this one. The problem is the gif code you have doesn't take this into consideration and as far as your code goes (your Timer1 code) it doesn't know the differeence between the two types of images. Unfortunately I don't know how to solve this problem with in the gif code you have. I have a method that works but then it will fail for the other gif images and you have no way of knowing which routine to use.
ok...
1st question: can you tell me how calculate the method type for eatch frame?
2nd question: can you explain to me how the methods types works(i belive that there are 4)?
thanks
-
Re: [VB6] - animated gif function errors:(
I believe you are referring to these:
Undefined
Leave
Restore Background
Restore Previous
• Undefined Directs the browser to do nothing to the background before displaying the next image.
• Leave Directs the browser to leave the previous graphic image as the next is drawn. This choice can create a shadowing effect.
• Restore Background Directs the browser to redraw the original background as the current image is drawn.
• Restore Previous Directs the browser to redraw the previous image as the current image is drawn.
I do not know how to find these settings per frame in a gif image. You might be interested in reading about the format of an animated gif here:
http://en.wikipedia.org/wiki/Graphic...rchange_Format
I looked at it and found some interesting info but wasn't able to find what the method type is for the frame.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
I believe you are referring to these:
Undefined
Leave
Restore Background
Restore Previous
• Undefined Directs the browser to do nothing to the background before displaying the next image.
• Leave Directs the browser to leave the previous graphic image as the next is drawn. This choice can create a shadowing effect.
• Restore Background Directs the browser to redraw the original background as the current image is drawn.
• Restore Previous Directs the browser to redraw the previous image as the current image is drawn.
I do not know how to find these settings per frame in a gif image. You might be interested in reading about the format of an animated gif here:
http://en.wikipedia.org/wiki/Graphic...rchange_Format
I looked at it and found some interesting info but wasn't able to find what the method type is for the frame.
do me a favor and test these code:
http://www.xtremevbtalk.com/showthre...t=animated+gif
(speaking on disposal values)
if you catch the real calculation, maybe i can draw the images correctly;)
anotherthing: is possible avoid the temp files and use a normal variables?
thanks for everything
-
Re: [VB6] - animated gif function errors:(
You should use the one from post #2 testing disposed animated gif files.zip. It handles all of your gif images.
About the disposal values (methods)
Code:
Each frame has the following:
21 F9 04 X1 X2 X3 X4 00
21 F9 these two bytes define the start of the Graphic Control Extension (GCE)
04 this byte tells you there are 4 bytes (to follow) of GCE data
X1 this byte has the Disposal code and whether or not there is a transparent color
X2 X3 delay for animation: not used
X4 value defines which color from the color table is transparent
00 end of GCE block
Following the previous byte is this one
2C called the Image Descriptor
'
'
'
'
Byte X1 is what you are concerned with
If the low order bit is 1 then there is a transparent color so use byte X4 to get that color from the color table.
The following calculation extracts the Disposal code from this byte
DisposalCode = (X1 \ 4) And 3
From above we get one of the following
0 Undefined
1 Leave
2 Restore Background
3 Restore Previous
OK, so much for that
Now, about avoiding temp files. It could be possible but would require a lot of rewriting the code. The code saves extracted frames from the original file. These saved pieces of data are actually made into a new gif file format so it can be reloaded back into an Image control using the LoadPicture method. To avoid this you would need to save the image data in memory using various APIs which only saves the image data and not the attributes you need, like the disposal values, transparent color, etc. You would also have to save the new gif file string in a string variable which corresponds to the image data also saved. Now you need to examine the string containing the file format to get the attributes you need and then load the image data into the Picture property of an Image control. However you would have to do the work yourself of making the transparent color which is done for you using the LoadPicture method. This requires additional efforts on your part which might be a little more complicated than you may want to get into.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
You should use the one from post #2 testing disposed animated gif files.zip. It handles all of your gif images.
About the disposal values (methods)
Code:
Each frame has the following:
21 F9 04 X1 X2 X3 X4 00
21 F9 these two bytes define the start of the Graphic Control Extension (GCE)
04 this byte tells you there are 4 bytes (to follow) of GCE data
X1 this byte has the Disposal code and whether or not there is a transparent color
X2 X3 delay for animation: not used
X4 value defines which color from the color table is transparent
00 end of GCE block
Following the previous byte is this one
2C called the Image Descriptor
'
'
'
'
Byte X1 is what you are concerned with
If the low order bit is 1 then there is a transparent color so use byte X4 to get that color from the color table.
The following calculation extracts the Disposal code from this byte
DisposalCode = (X1 \ 4) And 3
From above we get one of the following
0 Undefined
1 Leave
2 Restore Background
3 Restore Previous
OK, so much for that
Now, about avoiding temp files. It could be possible but would require a lot of rewriting the code. The code saves extracted frames from the original file. These saved pieces of data are actually made into a new gif file format so it can be reloaded back into an Image control using the LoadPicture method. To avoid this you would need to save the image data in memory using various APIs which only saves the image data and not the attributes you need, like the disposal values, transparent color, etc. You would also have to save the new gif file string in a string variable which corresponds to the image data also saved. Now you need to examine the string containing the file format to get the attributes you need and then load the image data into the Picture property of an Image control. However you would have to do the work yourself of making the transparent color which is done for you using the LoadPicture method. This requires additional efforts on your part which might be a little more complicated than you may want to get into.
sorry but what is X1(sorry that table stills confuse me:()?
i did:
Code:
Debug.Print (imgHeader \ 4) And 3
and these:
Code:
If imgCount > 1 Then Debug.Print ((Asc(Mid$(buf, imgHeader + 4, 1)) \ 4) And 3)
but i recive an error:(
-
Re: [VB6] - animated gif function errors:(
X1 is byte 1 that follows the code 04. X2 is byte 2, X3 is byte 3 and X4 is byte 4
The 04 tells you there are 4 bytes that follow. I just used X1 - X4 to denote those 4 bytes
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
X1 is byte 1 that follows the code 04. X2 is byte 2, X3 is byte 3 and X4 is byte 4
The 04 tells you there are 4 bytes that follow. I just used X1 - X4 to denote those 4 bytes
then if i did:
Code:
Debug.Print (imgHeader \ 4) And 3
why i get an error?
(i know that graphic file is a binary files. construtor by bytes(1 symbol=1 byte(i don't know if the string count like a byte)). but i still a little confuse:()
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
sorry but what is X1(sorry that table stills confuse me:()?
i did:
Code:
Debug.Print (imgHeader \ 4) And 3
and these:
Code:
If imgCount > 1 Then Debug.Print ((Asc(Mid$(buf, imgHeader + 4, 1)) \ 4) And 3)
but i recive an error:(
I can see where this one might cause an error
(imgHeader \ 4) And 3
but not so much this one
((Asc(Mid$(buf, imgHeader + 4, 1)) \ 4) And 3)
Anyway those two modules don't parse the file correctly
One line I see that should be corrected is this one
sGifMagic = Chr$(0) & Chr$(&H21) & Chr$(&HF9)
It sould be like this
sGifMagic = Chr$(&H21) & Chr$(&HF9)
It should not have the leading 00 as that may not always be the case and the true value is &H21F9
Here is a detailed breakdown of a gif image I made showing the actual values from the gif file.
Quote:
Code:
FORMAT OF A GIF89a IMAGE - MULTI IMAGE
Default Pixel Aspect Ratio -------------+
Background Color --------------+- |
GCT Follows ----------+ | |
| | |
Address | | |
Location | | |
G I F 8 9 a Width Height | | |
00000000 | 47 49 46 38 39 61 | 14 00 | 19 00 | F7 | 00 | 00 |
<-------------------- Global Color Table (768 Bytes) ---------------------->
Color 0 Color 1 Color 2 Color 3 Color 254 Color 255
0000000D | 00 00 00 | 80 00 00 | 00 80 00 | 80 80 00 | ......... | 00 FF FF | FF FF FF |
<============================ Begin Section for Image 1 ===============================>
End of
GCE Data
4 Bytes of |
GCE Data | Image
| | Descriptor
GCE | Byte: | | UL Corner
Indicator | X1 X2 X3 X4 | | of Image Width Height
| | | | | | | | X Y | |
0000030D | 21 F9 | 04 | 05 32 00 09 00 | 2C | 00 00 00 00 | 13 00 | 19 00 |
Local
Color
Table
| <---- Local Color Table (768 Bytes) for Image 1 ----->
| Color 0 Color 256
0000031E | C7 | 00 00 00 | ...............................| FF FF FF |
Start of
of Image
| End of
| Image Image
| Size Data
| | <-------- Image 1 data -----------> |
0000061F | 08 | 60 | .................................. | 00 |
<============================ Begin Section for Image 2 ===============================>
End of
GCE Data
4 Bytes of |
GCE Data | Image
| | Descriptor
GCE | Byte: | | UL Corner
Indicator | X1 X2 X3 X4 | | of Image Width Height
| | | | | | | | X Y | |
00000682 | 21 F9 | 04 | 09 32 00 09 00 | 2C | 00 00 00 00 | 14 00 | 19 00 |
Local
Color
Table
| <---- Local Color Table (768 Bytes) for Image 2 ----->
| Color 0 Color 256
00000693 | C7 | 00 00 00 | ...............................| FF FF FF |
Start of
of Image
| End of
| Image Image
| Size Data
| | <-------- Image 2 data -----------> |
00000994 | 08 | 4F | .................................. | 00 |
The byte indicated as X1 has the following format
Code:
+------ 0 = Not used
|+----- t = 0 = There is no transparent color
|| t = 1 = There is a transparent color and you need to look at byte X4
0000 dd0t
--
|
+------- Diposal Bits
dd = 00 = Undefined
dd = 01 = Leave
dd = 10 = Restore Background
dd = 11 = Restore Previous
To get the bits that tell you what the disposal value is you need to do this
X4\4 shift off the low order two bits
then And the results with 3
So, from above X1 in the dump you see that it is 09 for image 2
9 \ 4 = 2
2 And 3 = 2
The results 2 tells you it is Disposal code #2 which means Restore Background
Because the low order bit was set to 1 then there is a transparent color and it's table offset is in byte X4
X4 = 09
So, color offset (3-bytes per color) 09 in the color table is the transparent color (not shown in my dump.
-
Re: [VB6] - animated gif function errors:(
I can see where the new VBForum's format screws up the [ code ]....[ /code ] format.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
I can see where the new VBForum's format screws up the [ code ]....[ /code ] format.
thanks to your table a did find the general size on gif file:
Code:
Debug.Print "Width: " & Asc(Mid$(fileHeader, 7, 4))
Debug.Print "Heigth: " & Asc(Mid$(fileHeader, 9, 4))
(still using the 1st function;))
on that table "Local Color Table (768 Bytes) for Image 1", can you tell me if the disposed values are there too?
where did you find that table, or it's yours?
thanks for the help
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
thanks to your table a did find the general size on gif file:
Code:
Debug.Print "Width: " & Asc(Mid$(fileHeader, 7, 4))
Debug.Print "Heigth: " & Asc(Mid$(fileHeader, 9, 4))
(still using the 1st function;))
on that table "Local Color Table (768 Bytes) for Image 1", can you tell me if the disposed values are there too?
where did you find that table, or it's yours?
thanks for the help
First: The size is not 4 bytes each, it's 2 bytes each so your statement should be
Code:
Debug.Print "Width: " & Asc(Mid$(fileHeader, 7, 2))
Debug.Print "Heigth: " & Asc(Mid$(fileHeader, 9, 2))
The disposal codes are exactly where I pointed them out to you. Look at the format map I made. Every section starts with this:
Code:
21 F9 2 bytes = GCE Indicator
followed by
04 1 byte = Number of CGE Data to follow
followed by 4 bytes
X1 X2 X2 X3
09 32 00 09 4 bytes = CGE Data
followed by 1 byte
00 1 byte = End of CGE Data
The 4 bytes of CGE Data I specified them as X1, X2, X3, and X4
X! is the byte that holds the Disposal value
In my example X1 = 09 for the 2nd image section
09 = 0000 1001
So, from above X1 in the dump you see that it is 09 for image 2
0000 1001 \ 4 = 0000 0010 = 2
0000 0010 And 0000 0111 = 2
The results 2 tells you it is Disposal code #2 which means Restore Background
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
First: The size is not 4 bytes each, it's 2 bytes each so your statement should be
Code:
Debug.Print "Width: " & Asc(Mid$(fileHeader, 7, 2))
Debug.Print "Heigth: " & Asc(Mid$(fileHeader, 9, 2))
The disposal codes are exactly where I pointed them out to you. Look at the format map I made. Every section starts with this:
Code:
21 F9 2 bytes = GCE Indicator
followed by
04 1 byte = Number of CGE Data to follow
followed by 4 bytes
X1 X2 X2 X3
09 32 00 09 4 bytes = CGE Data
followed by 1 byte
00 1 byte = End of CGE Data
The 4 bytes of CGE Data I specified them as X1, X2, X3, and X4
X! is the byte that holds the Disposal value
In my example X1 = 09 for the 2nd image section
09 = 0000 1001
So, from above X1 in the dump you see that it is 09 for image 2
0000 1001 \ 4 = 0000 0010 = 2
0000 0010 And 0000 0111 = 2
The results 2 tells you it is Disposal code #2 which means Restore Background
sorry i still having bad results:(
i understand that it's the 3 byte with 4 bytes. but i'm still getting bad results:(
Code:
If imgCount > 1 Then Debug.Print (Asc(Mid(imgHeader, 3, 4))) \ 4 And 3
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
sorry i still having bad results:(
i understand that it's the 3 byte with 4 bytes. but i'm still getting bad results:(
Code:
If imgCount > 1 Then Debug.Print (Asc(Mid(imgHeader, 3, 4))) \ 4 And 3
It's not 4, it's 1
so your statement should be
((Asc(Mid$(imgHeader, 3, 1)) \ 4) And 3)
-
Re: [VB6] - animated gif function errors:(
I made a animated GIF with 5 pictures in it. THe below shows what each section looks like:
Code:
00000000 47 49 46 38 39 61 14 00 19 00 F7 00 00 + Global Color Table
1st Picture
0000030D 21 F9 04 01 32 00 09 00 2C 00 00 00 00 13 00 19 00 C7 + Local Color Table + Image
2nd Picture
00000682 21 F9 04 05 32 00 09 00 2C 00 00 00 00 14 00 19 00 C7 + Local Color Table + Image
3rd Picture
000009E6 21 F9 04 09 32 00 09 00 2C 00 00 00 00 14 00 19 00 C7 + Local Color Table + Image
4th Picture
00000D54 21 F9 04 0D 32 00 09 00 2C 00 00 00 00 14 00 19 00 C7 + Local Color Table + Image
5th Picture
000010C8 21 F9 04 05 32 00 09 00 2C 00 00 00 00 14 00 19 00 40 + Use Global Color Table + Image
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
What do think it should be?
Do this for me:
Add a temp code line like this: CodeByte = Mid(imgHeader, 3, 4)
and post the results of that statement so I can see what the value of the byte is
testing with hallowen image, i, always, recive 5.
-
Re: [VB6] - animated gif function errors:(
It's not 4, it's 1
so your statement should be
((Asc(Mid$(imgHeader, 3, 1)) \ 4) And 3)
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
What do think it should be?
Do this for me:
Add a temp code line like this: CodeByte = Mid(imgHeader, 3, 4)
and post the results of that statement so I can see what the value of the byte is
testing with hallowen image:
|2 ¶
|2 ¶
|2 ¶
|2 ¶
-
Re: [VB6] - animated gif function errors:(
Go back and read my post 31 again
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Go back and read my post 31 again
i did and i still recive incorrect values... always '1':(
Code:
'Method Values :
'0 - No disposal specified. The decoder is _
not required to take any action.
'1 - Do not dispose. The graphic is to be left _
in place.
'2 - Restore to background color. The area used by the _
graphic must be restored to the background color.
'3 - Restore to previous. The decoder is required to _
restore the area overwritten by the graphic with _
what was there prior to rendering the graphic.
'4-7 - To be defined.
Option Explicit
Public Enum GifType
GIF87A = 0
GIF89A = 1
End Enum
Public RepeatTimes As Long 'This one calculates,
' but don't use in this sample. If You need, You
' can add simple checking at Timer1_Timer Procedure
Public TotalFrames As Long
Public GifTypeFile As GifType
Public Function LoadGif(sFile As String, aImg As Variant) As Boolean
If Dir$(sFile) = "" Or sFile = "" Then
MsgBox "File " & sFile & " not found", vbCritical
Exit Function
End If
If Mid$(UCase(sFile), Len(sFile) - 2, 3) <> "GIF" Then Exit Function
On Error GoTo ErrHandler
'On Error Resume Next
Dim fNum As Integer
Dim imgHeader As String, fileHeader As String
Dim buf$, picbuf$
Dim imgCount As Integer
Dim i&, j&, xOff&, yOff&, TimeWait&
Dim GifEnd As String
GifEnd = Chr(0) & Chr(33) & Chr(249) '<---only for animated GIF's
For i = 1 To aImg.Count - 1
Unload aImg(i)
Next i
fNum = FreeFile
Open sFile For Binary Access Read As fNum
buf = String(LOF(fNum), Chr(0))
Get #fNum, , buf 'Get GIF File into buffer
Close fNum
i = 1
imgCount = 0
j = InStr(1, buf, GifEnd) + 1 '<--- j = 1 or 0 if not a animated gif ---- j > 1 if it is an animated gif
If j < 2 Then
aImg(0).Picture = LoadPicture(sFile)
TotalFrames = aImg.Count - 1
aImg(0).Tag = 0
LoadGif = True
Exit Function
End If
fileHeader = Left(buf, j)
If Left$(fileHeader, 1) <> "G" Then
MsgBox "This file is not a *.gif file", vbCritical
Exit Function
End If
'Get gif type
Debug.Print "Width: " & Asc(Mid$(fileHeader, 7, 4))
Debug.Print "Heigth: " & Asc(Mid$(fileHeader, 9, 4))
frmTest.BackColor = Asc(Mid$(fileHeader, 12, 2))
If Left$(fileHeader, 6) = "GIF89a" Then
GifTypeFile = GIF89A
Else
GifTypeFile = GIF87A
End If
LoadGif = True
i = j + 2
If Len(fileHeader) >= 127 Then
RepeatTimes& = Asc(Mid(fileHeader, 126, 1)) + (Asc(Mid(fileHeader, 127, 1)) * 256&)
Else
RepeatTimes = 0
End If
Do ' Split GIF Files at separate pictures
' and load them into Image Array
imgCount = imgCount + 1
j = InStr(i, buf, GifEnd) + 3
If j > Len(GifEnd) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + j - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, j - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, j - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256&)) * 10&
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256&)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256&)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
' Use .Tag Property to save TimeWait interval for separate Image
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
If imgCount > 1 Then Debug.Print Asc(Mid(imgHeader, 3, 1)) \ 4 And 3
'If imgCount > 1 Then Debug.Print (Asc(Mid(imgHeader, 4, 1)) And 28) / 4
Kill ("temp.gif")
i = j
End If
'DoEvents
Loop Until j = 3
' If there are one more Image - Load it
If i < Len(buf) Then
fNum = FreeFile
Open "temp.gif" For Binary As fNum
picbuf = String(Len(fileHeader) + Len(buf) - i, Chr(0))
picbuf = fileHeader & Mid(buf, i - 1, Len(buf) - i)
Put #fNum, 1, picbuf
imgHeader = Left(Mid(buf, i - 1, Len(buf) - i), 16)
Close fNum
TimeWait = ((Asc(Mid(imgHeader, 4, 1))) + (Asc(Mid(imgHeader, 5, 1)) * 256)) * 10
If imgCount > 1 Then
xOff = Asc(Mid(imgHeader, 9, 1)) + (Asc(Mid(imgHeader, 10, 1)) * 256)
yOff = Asc(Mid(imgHeader, 11, 1)) + (Asc(Mid(imgHeader, 12, 1)) * 256)
Load aImg(imgCount - 1)
aImg(imgCount - 1).Left = aImg(0).Left + (xOff * Screen.TwipsPerPixelX)
aImg(imgCount - 1).Top = aImg(0).Top + (yOff * Screen.TwipsPerPixelY)
End If
aImg(imgCount - 1).Tag = TimeWait
aImg(imgCount - 1).Picture = LoadPicture("temp.gif")
Kill ("temp.gif")
End If
TotalFrames = aImg.Count - 1
LoadGif = True
Exit Function
ErrHandler:
MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
LoadGif = False
On Error GoTo 0
End Function
sorry if i'm bored you:(
-
Re: [VB6] - animated gif function errors:(
Then do what I asked you to do which you haven't done yet
Quote:
Do this for me:
Add a temp code line like this: CodeByte = Mid(imgHeader, 3, 4)
and post the results of that statement so I can see what the value of the byte is
This will put 4 bytes into variable CodeByte. I want to see what it contains
EDIT
Better yet post the image as a zip file and I will find the info for you
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Then do what I asked you to do which you haven't done yet
This will put 4 bytes into variable CodeByte. I want to see what it contains
strange. why the results are the same?
|, ¶
|2 ¶
|2 ¶
|2 ¶
|2 ¶
-
Re: [VB6] - animated gif function errors:(
Reread post 35 at the EDIT
-
Re: [VB6] - animated gif function errors:(
I looked at the image halloween46.gif and it has 6 frames. Here is what the beginning of each frame looks like:
Code:
Frame 1 = 21 F9 04 05 2C 01 14 00 2C
Frame 2 = 21 F9 04 05 32 00 14 00 2C
Frame 3 = 21 F9 04 05 32 00 14 00 2C
Frame 4 = 21 F9 04 05 32 00 14 00 2C
Frame 5 = 21 F9 04 05 32 00 14 00 2C
Frame 6 = 21 F9 04 05 2C 01 14 00 2C
Now, if you had read my previous posts you will see that the byte following the 04 above which I told you was indicated by X1 I showed you how to calculate the disposal value. I will show you again.
Byte following 04 above is 05
Code:
05 04
0000 0101 \ 0000 0100 = 0000 0001 = 01
01 03
0000 0001 And 0000 0111 = 0000 0001 = 01
The 01 tell you that the disposal code is 1 which is "Leave"
All frames have the same code
So you statement
(Asc(Mid(imgHeader, 3, 1))) \ 4 And 3 means to start at position 3 for a length of 1 of variable imgHeader divide by 4 then And by 3
I do not know what you have in variable imgHeader but if the 3rd position is 05 then you should get exactly what I illustrated above a value of 1. If the 3rd value is not 05 then the data in that variable is incorrect for what you are doing. You need to post exactly what is in that variable in hex format otherwise I cannot tell you what you are doing wrong.
Also, you statements for Width and Height are incorrect. I told you in Post 26 that you need to change them from a 4 to a 2
This:
"Width: = " & Asc(Mid$(fileHeader, 7, 4))
"Heigth: = " & Asc(Mid$(fileHeader, 9, 4))
Should be this:
"Width: = " & Asc(Mid$(fileHeader, 7, 2))
"Heigth: = " & Asc(Mid$(fileHeader, 9, 2))
-
Re: [VB6] - animated gif function errors:(
OK, your imgHeader is incorrect.
It reads:
Code:
F9 04 05 2C 01 14 00 2C 00 00 00 00 AC 00 C5 00
It should be
Code:
21 F9 04 05 2C 01 14 00 2C 00 00 00 00 AC 00 C5
So, you are off by 1 byte. But that doesn't matter as you can actually start
wherever you want just as long as your statement is correct for what you are doing.
So, using the incorrect header (which is alright) your statement from your post #27
(Asc(Mid(imgHeader, 3, 4))) \ 4 And 3 <--- Wrong! You do not want to use 4 bytes
but you need to change it to a 1 like this:
((Asc(Mid$(imgHeader, 3, 1)) \ 4) And 3) <--- Right! You use only 1 byte
Then it should have given you a result of 1 for all frames.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
OK, your imgHeader is incorrect.
It reads:
Code:
F9 04 05 2C 01 14 00 2C 00 00 00 00 AC 00 C5 00
It should be
Code:
21 F9 04 05 2C 01 14 00 2C 00 00 00 00 AC 00 C5
So, you are off by 1 byte. But that doesn't matter as you can actually start
wherever you want just as long as your statement is correct for what you are doing.
So, using the incorrect header (which is alright) your statement from your post #27
(Asc(Mid(imgHeader, 3,
4))) \ 4 And 3 <--- Wrong! You do not want to use 4 bytes
but you need to change it to a 1 like this:
((Asc(Mid$(imgHeader, 3,
1)) \ 4) And 3) <--- Right! You use only 1 byte
Then it should have given you a result of 1 for all frames.
yes... always '1'... but how can i compare the disposed values(that in these case aren't correct)?:(