-
Re: [VB6] - animated gif function errors:(
You should not depend on just checking for Chr(33) as that will appear many times in the file and have nothing to do with the start of a frame. You need to scan for at least two characters Chr(33) and Chr(249) and then if the 3rd character is a Chr(4) can you be sure you have a start of frame. You use 13 to get the starting point because that is the end of the fixed header portion to scan for the 1st frames after that position (you could have just as well started with position 1, not 0) to get the same answer.
I know you are not picking up the correct data for an image because when I run your code I save each temp.gif file like this temp(1).gif, temp(2).gif, temp(3).gif, etc (I do not Kill the files during testing). Now when I double click on them I get invalid picture from different gif viewer applications and they won't display, they wont even display in the browser so I know they are not complete. It turns out that loading them back into your picturebox works (most of the time) because the picturebox doesn't seem to care but that doesn't mean the frames are correct or complete.
The InStr works the same for text, binary, chr(n) or any data.
VB requires that you at least start at position 1 (there is no position 0)
So,
Offset = Instr(start_position, data_to_scan, data_to_look_for)
start_position must be at least 1
data_to_scan can be any string. What is in the string doesn't matter because all data is binary.
data_to_look_for can be any valid string data like:
1) "you can scan for this"
2) Chr(33)
3) vbCrLf
4) 0 or any number from 0 to 255
If the data is not found in the string then Offset = 0
If the data is found in the string then Offset has the position of the 1st byte of the data_to_look_for.
Dim data_to_scan As String
data_to_scan = "This is a string which contains letters"
Offest = InStr(1, data_to_scan, "contains")
Offset will contain the value 24
Offest = InStr(26, data_to_scan, "contains")
Offset will contain the value 0
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
You should not depend on just checking for Chr(33) as that will appear many times in the file and have nothing to do with the start of a frame. You need to scan for at least two characters Chr(33) and Chr(249) and then if the 3rd character is a Chr(4) can you be sure you have a start of frame. You use 13 to get the starting point because that is the end of the fixed header portion to scan for the 1st frames after that position (you could have just as well started with position 1, not 0) to get the same answer.
I know you are not picking up the correct data for an image because when I run your code I save each temp.gif file like this temp(1).gif, temp(2).gif, temp(3).gif, etc (I do not Kill the files during testing). Now when I double click on them I get invalid picture from different gif viewer applications and they won't display, they wont even display in the browser so I know they are not complete. It turns out that loading them back into your picturebox works (most of the time) because the picturebox doesn't seem to care but that doesn't mean the frames are correct or complete.
The InStr works the same for text, binary, chr(n) or any data.
VB requires that you at least start at position 1 (there is no position 0)
So,
Offset = Instr(start_position, data_to_scan, data_to_look_for)
start_position must be at least 1
data_to_scan can be any string. What is in the string doesn't matter because all data is binary.
data_to_look_for can be any valid string data like:
1) "you can scan for this"
2) Chr(33)
3) vbCrLf
4) 0 or any number from 0 to 255
If the data is not found in the string then Offset = 0
If the data is found in the string then Offset has the position of the 1st byte of the data_to_look_for.
Dim data_to_scan As String
data_to_scan = "This is a string which contains letters"
Offest = InStr(1, data_to_scan, "contains")
Offset will contain the value 24
Offest = InStr(26, data_to_scan, "contains")
Offset will contain the value 0
thanks for all my friend.. these night i will tell you something(it's 12:34PM)
thanks
-
Re: [VB6] - animated gif function errors:(
heres my code updated(with your nice information on instr() function):
Code:
'Special thanks to jmsrickland from www.VBForums.com
Option Explicit
Option Base 0
Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Enum GifType
GIF87A = 0
GIF89A = 1
End Enum
Private Type LogicalScreenDescriptor
GifWidth As Long
GifHeight As Long
GlobalColorSize As Long
SortFlag As Long
ColorResolution As Long
GlobalColorFlag As Long
BackgroundColor As Long
PixelRadio As Long
End Type
Private Type GraphicControl
Disposal As Long
Delay As Long
TransparentColorIndex As Long
UserInput As Long
TransparentFlag As Long
End Type
Private Type ImageDescription
FrameLeft As Long
FrameTop As Long
FrameWidth As Long
FrameHeight As Long
End Type
Private Type Frame
GCGraphicControl As GraphicControl
IDImageDescription As ImageDescription
End Type
Dim fraFrame() As Frame
Public Function LoadGifFile(strFileName As String, aimg As Variant) As Long
Dim GifHeader As GifType
Dim strLogicalScreenDescription As String
Dim LSDLogicalScreenDescription As LogicalScreenDescriptor
'Dim GCGraficControl As GraphicControl
'Dim IDImageDescription As ImageDescription
Dim strGifHeader As String
Dim strFrame As String
Dim fNum As Integer
Dim FileBuffer As String
Dim PictureBuffer As String
Dim PackedField As String
Dim FirstFrame As Long
Dim FrameEnds As Long
Dim ActualFrame As Long
Dim i As Integer
On Error Resume Next
'Test if the file exists
If Dir$(strFileName) = "" Or strFileName = "" Then
MsgBox "File " & strFileName & " not found", vbCritical
Exit Function
End If
'Put all file info to a variable
fNum = FreeFile
Open strFileName For Binary Access Read As fNum
FileBuffer = String(LOF(fNum), Chr(0))
Get #fNum, , FileBuffer
Close fNum
'FileBuffer = Trim(FileBuffer)
'unload all pictureboxes\images
For i = 1 To aimg.Count - 1
Unload aimg(i)
Next i
aimg(0).Visible = True
'Gif Header
strGifHeader = Left$(FileBuffer, 6)
If strGifHeader = "GIF87a" Then
GifHeader = GIF87A
ElseIf strGifHeader = "GIF89a" Then
GifHeader = GIF89A
End If
'Test if the Gif is animated or not
FirstFrame = InStr(13, FileBuffer, Chr(33) & Chr(249) & Chr(4))
'if the image isn't animated, then just draw it;)
If InStr(FirstFrame + 2, FileBuffer, Chr(33) & Chr(249) & Chr(4)) <= 0 Then
LoadGifFile = 1
aimg(0).Picture = LoadPicture(strFileName)
aimg(0).Tag = 0
Exit Function
End If
ActualFrame = FirstFrame
'Logical Screen Description
strLogicalScreenDescription = Mid$(FileBuffer, 7, 7)
LSDLogicalScreenDescription.GifWidth = Asc(Mid(strLogicalScreenDescription, 1, 1)) + Asc(Mid(strLogicalScreenDescription, 2, 1)) * 256
LSDLogicalScreenDescription.GifHeight = Asc(Mid(strLogicalScreenDescription, 3, 1)) + Asc(Mid(strLogicalScreenDescription, 4, 1)) * 256
PackedField = Asc(Mid$(strLogicalScreenDescription, 5, 1))
LSDLogicalScreenDescription.GlobalColorFlag = (PackedField And 128) / 2 ^ 7
LSDLogicalScreenDescription.ColorResolution = (PackedField And 112) / 2 ^ 4
LSDLogicalScreenDescription.SortFlag = (PackedField And 8) / 2 ^ 3
' NOTE - This value is meanless if GlobalColorFlag is 0
LSDLogicalScreenDescription.GlobalColorSize = PackedField And 7
LSDLogicalScreenDescription.GlobalColorSize = 3 * (2 ^ (LSDLogicalScreenDescription.GlobalColorSize + 1))
LSDLogicalScreenDescription.BackgroundColor = Asc(Mid$(strLogicalScreenDescription, 6, 1))
LSDLogicalScreenDescription.PixelRadio = Asc(Mid$(strLogicalScreenDescription, 7, 1))
'image count
i = 0
ReDim Preserve fraFrame(i)
Do
'get frame string
If InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249) & Chr(4)) > 1 Then
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249)) - 1
Else
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(59)) - 1
End If
strFrame = Mid$(FileBuffer, ActualFrame, FrameEnds)
'Get Grafic Control
PackedField = Asc(Mid$(strFrame, 4, 1))
fraFrame(i).GCGraphicControl.Disposal = (PackedField And 12) / 2 ^ 2
' ADDED BY JMS
fraFrame(i).GCGraphicControl.UserInput = (PackedField And 2) / 2 ^ 1
' ADDED BY JMS
fraFrame(i).GCGraphicControl.TransparentFlag = (PackedField And 1)
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256) * 10
If fraFrame(i).GCGraphicControl.Delay = 0 Then fraFrame(i).GCGraphicControl.Delay = 250
'Debug.Print fraFrame(i).GCGraphicControl.Delay
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(strFrame, 7, 1))
'Get Image Description
fraFrame(i).IDImageDescription.FrameLeft = Asc(Mid(strFrame, 10, 1)) + Asc(Mid(strFrame, 11, 1)) * 256
fraFrame(i).IDImageDescription.FrameTop = Asc(Mid(strFrame, 12, 1)) + Asc(Mid(strFrame, 13, 1)) * 256
fraFrame(i).IDImageDescription.FrameWidth = Asc(Mid(strFrame, 14, 1)) + Asc(Mid(strFrame, 15, 1)) * 256
fraFrame(i).IDImageDescription.FrameHeight = Asc(Mid(strFrame, 16, 1)) + Asc(Mid(strFrame, 17, 1)) * 256
'If the image array don't exist then create\load it
If i > 0 Then
Load aimg(i)
End If
'create the image temp
fNum = FreeFile
Open "temp.gif" For Binary As fNum
PictureBuffer = Mid$(FileBuffer, 1, FirstFrame - 1) & Mid$(FileBuffer, ActualFrame, FrameEnds) & Chr(59) '3B
Put #fNum, 1, PictureBuffer
Close fNum
'Now change the backcolor
aimg(i).BackColor = fraFrame(i).GCGraphicControl.TransparentColorIndex
'now load the image
aimg(i).Picture = LoadPicture("temp.gif")
'change the properties
aimg(i).Tag = fraFrame(i).GCGraphicControl.Delay
'test if theres another image
If InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249) & Chr(4)) <= 0 Then
Exit Do
Else
ActualFrame = InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249) & Chr(4))
i = i + 1
If i > 0 Then ReDim Preserve fraFrame(i)
End If
DoEvents
Loop
'now we can delete the temp file
Kill "temp.gif"
LoadGifFile = i + 1
'Control the Disposal codes
If aimg.Count > 1 Then
Load aimg(aimg.Count)
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0, 1 ' Leave
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, vbSrcCopy
End If
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
Case 3
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, vbSrcCopy
aimg(i).Cls
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, GetPixel(aimg(i).hdc, 0, 0)
Else
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, LSDLogicalScreenDescription.BackgroundColor
End If
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
End Select
'Debug.Print fraFrame(i).GCGraphicControl.Disposal
Next i
Unload aimg(aimg.Count - 1)
End If
End Function
now i don't recive very overflows(depend, of course, on gif format company);)
i can see the brucelikik 1st frame... but i still have a infinite loop:(
you said me that brucelikik have 1 invalid frame... how can i test it?
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
heres my code updated(with your nice information on instr() function):
now i don't recive very overflows(depend, of course, on gif format company);)
i can see the brucelikik 1st frame... but i still have a infinite loop:(
you said me that brucelikik have 1 invalid frame... how can i test it?
No, see post #189. I said brucekik has two valid frames and it was your code that has the problem with this one. T-rex has one invalid frame and that is why you got that bad Delay value but when you changed your code to check for Chr(33) & Chr(249) & Chr(4) that caused it to skip over the bad frame and go onto the next one after that.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
No, see post #189. I said brucekik has two valid frames and it was your code that has the problem with this one. T-rex has one invalid frame and that is why you got that bad Delay value but when you changed your code to check for Chr(33) & Chr(249) & Chr(4) that caused it to skip over the bad frame and go onto the next one after that.
i have read it, but i mistake sorry... now i can see the 1st frame on brucekik... but how can i avoid the infinite loop?
(i will see more my code for test)
-
Re: [VB6] - animated gif function errors:(
ok.. i have tested the actualframe position:
that it's less than len(filebuffer).... then why the code is ignored without tell me?
(no error messages... just stop after the 1st cycle... yes stop, nothing more, and vb6 crashes)
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
if i can catch the 1st frame, why i can't catch the other!?!
i made very tests and i see the error:(
heres how i catch the frame limits:
Code:
If InStr(ActualFrame + 3, FileBuffer, Chr(33) & Chr(249) & Chr(4)) >= 1 Then
FrameEnds = InStr(ActualFrame + 3, FileBuffer, Chr(33) & Chr(249) & Chr(4)) - 1
Else
FrameEnds = InStr(ActualFrame, FileBuffer, Chr(59)) - 1
End If
and heres the last frame(the 2nd) result(i can open it on browser and not with loapicture() function:
... now my question is: why i don't get all frame? why i can't open it with loadpicture() but i can with browser?
another thing: you can see all vertical leg, but i can't using the windows browser. i see the frame you see, except all vertical leg... strange
-
Re: [VB6] - animated gif function errors:(
There are going to be more problems that you are going to have to deal with to be able to process all gif files. In addition to the Chr(33) & Chr(246) & Chr(4) string to find the beginning of a frame there is one more string you are going to have to look for and it starts to get somewhat complicated so we will have to deal with that as it occurs.
The other string you need to look for is Chr(33) & Chr(255) & Chr(11).
A lot of images have the Netscape block added to them and that block is a frame but it does not have the same format as the other one does. A good example of a gif that uses this format is meter.gif.
Copy the code I paste below to control your frame logic. This is the logic I use which captures the frame data correctly and it captures brucekik.gif correctly.
Code:
Public Function LoadGifFile(strFileName As String, aimg As Variant) As Long
Static GifImageStart As String
Dim q1 As Long
Dim q2 As Long
Static GifFileHeader As String
Static GifImageString As String
GifImageStart = Chr(33) & Chr(249) & Chr(4)
q1 = InStr(1, FileBuffer, GifImageStart)
GifFileHeader = Left(FileBuffer, q1 - 1)
Do While True
q2 = InStr(q1 + 1, FileBuffer, GifImageStart)
If q2 = 0 Then
'
' No more 21F904 - use remainder of buffer
'
GifImageString = Mid(FileBuffer, q1)
Else
GifImageString = Mid(FileBuffer, q1, q2 - q1)
End If
'
'
' Put your code here to process the frames
'
'
If q2 = 0 Then Exit Function
q1 = q2
Loop
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:(
Quote:
Originally Posted by
jmsrickland
There are going to be more problems that you are going to have to deal with to be able to process all gif files. In addition to the Chr(33) & Chr(246) & Chr(4) string to find the beginning of a frame there is one more string you are going to have to look for and it starts to get somewhat complicated so we will have to deal with that as it occurs.
The other string you need to look for is Chr(33) & Chr(255) & Chr(11).
A lot of images have the Netscape block added to them and that block is a frame but it does not have the same format as the other one does. A good example of a gif that uses this format is meter.gif.
Copy the code I paste below to control your frame logic. This is the logic I use which captures the frame data correctly and it captures brucekik.gif correctly.
Code:
Public Function LoadGifFile(strFileName As String, aimg As Variant) As Long
Static GifImageStart As String
Dim q1 As Long
Dim q2 As Long
Static GifFileHeader As String
Static GifImageString As String
GifImageStart = Chr(33) & Chr(249) & Chr(4)
q1 = InStr(1, FileBuffer, GifImageStart)
GifFileHeader = Left(FileBuffer, q1 - 1)
Do While True
q2 = InStr(q1 + 1, FileBuffer, GifImageStart)
If q2 = 0 Then
'
' No more 21F904 - use remainder of buffer
'
GifImageString = Mid(FileBuffer, q1)
Else
GifImageString = Mid(FileBuffer, q1, q2 - q1)
End If
'
'
' Put your code here to process the frames
'
'
If q2 = 0 Then Exit Function
q1 = q2
Loop
Exit Function
ErrHandler:
MsgBox "Error No. " & Err.Number & " when reading file", vbCritical
LoadGif = False
On Error GoTo 0
End Function
thanks
-
Re: [VB6] - animated gif function errors:(
heres the start of a frame:
Code:
GifImageStart = Chr(33) & Chr(249) & Chr(4)
heres how i read entire file:
Code:
'Put all file info to a variable
fNum = FreeFile
Open strFileName For Binary Access Read As fNum
FileBuffer = String(LOF(fNum), Chr(59))
Get #fNum, 1, FileBuffer
Close fNum
heres how i catch the 1st frame:
Code:
'where is the 1st frame
FirstFrame = InStr(1, FileBuffer, GifImageStart)
ActualFrame = FirstFrame
heres how i see the frame limits:
Code:
'get frame string
If InStr(ActualFrame + 2, FileBuffer, GifImageStart) > 1 Then
FrameEnds = InStr(ActualFrame + 2, FileBuffer, GifImageStart) - 1
Else
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(59)) - 1
End If
strFrame = Mid$(FileBuffer, ActualFrame, FrameEnds)
heres how i create the temp file:
Code:
'create the image temp
fNum = FreeFile
Open "temp.gif" For Binary As fNum
PictureBuffer = Mid$(FileBuffer, 1, FirstFrame - 1) & Mid$(FileBuffer, ActualFrame, FrameEnds) & Chr(59) '3B
Put #fNum, 1, PictureBuffer
Close fNum
and how i see if theres another frame:
Code:
'test if theres another image
If InStr(ActualFrame + 2, FileBuffer, GifImageStart) <= 0 Then
Exit Do
Else
ActualFrame = InStr(ActualFrame + 2, FileBuffer, GifImageStart)
i = i + 1
If i > 0 Then ReDim Preserve fraFrame(i) 'fraFrame(i) is where i save the information
End If
these code seems to be correct... but i can't read the brucekik.gif... so i still confuse on why:(
i have seen your code, but i still having problems:(
-
Re: [VB6] - animated gif function errors:(
Post your most recent version of the aniMod and I will modify it with my code that I posted for you and then I can see if it works or not. I know the way I do it works because I can get both frames of brucekik.
-
Re: [VB6] - animated gif function errors:(
now it's working fine... except that the disposed mehtods isn't:(
Code:
Public Function LoadGifFile2(strFileName As String, aimg As Variant) As Long
Dim GifImageStart As String
Static GifImageString As String
Dim fNum As Integer
Dim FileBuffer As String
Dim PictureBuffer As String
Dim FirstFrame As String
Dim PreviousFrame As String
Dim ActualFrame As String
Dim fraFrame() As Frame
Dim GifHeader As GifType
Dim strGifHeader As String
Dim strLogicalScreenDescription As String
Dim LSDLogicalScreenDescription As LogicalScreenDescriptor
Dim PackedField As String
Dim i As Long
On Error Resume Next
GifImageStart = Chr(33) & Chr(249) & Chr(4)
'Unload all pictureboxes\images
For i = 1 To aimg.Count - 1
Unload aimg(i)
Next i
'and make the 1st visible;)
'if not the static images can't be showed(sometimes)
aimg(0).Visible = True
'Put all file info to a variable
fNum = FreeFile
Open strFileName For Binary Access Read As fNum
FileBuffer = String(LOF(fNum), Chr(59))
Get #fNum, 1, FileBuffer
Close fNum
FirstFrame = InStr(1, FileBuffer, GifImageStart)
'Gif Header and Version
strGifHeader = Left$(FileBuffer, 6)
If strGifHeader = "GIF87a" Then
GifHeader = GIF87A
ElseIf strGifHeader = "GIF89a" Then
GifHeader = GIF89A
End If
'Logical Screen Description
strLogicalScreenDescription = Mid$(FileBuffer, 7, 7)
LSDLogicalScreenDescription.GifWidth = Asc(Mid(strLogicalScreenDescription, 1, 1)) + Asc(Mid(strLogicalScreenDescription, 2, 1)) * 256
LSDLogicalScreenDescription.GifHeight = Asc(Mid(strLogicalScreenDescription, 3, 1)) + Asc(Mid(strLogicalScreenDescription, 4, 1)) * 256
PackedField = Asc(Mid$(strLogicalScreenDescription, 5, 1))
LSDLogicalScreenDescription.GlobalColorFlag = (PackedField And 128) / 2 ^ 7
LSDLogicalScreenDescription.ColorResolution = (PackedField And 112) / 2 ^ 4
LSDLogicalScreenDescription.SortFlag = (PackedField And 8) / 2 ^ 3
' NOTE - This value is meanless if GlobalColorFlag is 0
LSDLogicalScreenDescription.GlobalColorSize = PackedField And 7
LSDLogicalScreenDescription.GlobalColorSize = 3 * (2 ^ (LSDLogicalScreenDescription.GlobalColorSize + 1))
LSDLogicalScreenDescription.BackgroundColor = Asc(Mid$(strLogicalScreenDescription, 6, 1))
LSDLogicalScreenDescription.PixelRadio = Asc(Mid$(strLogicalScreenDescription, 7, 1))
PreviousFrame = FirstFrame
i = 0
ReDim Preserve fraFrame(i)
Do While True
ActualFrame = InStr(PreviousFrame + 1, FileBuffer, GifImageStart)
If ActualFrame = 0 Then
'
' No more 21F904 - use remainder of buffer
'
GifImageString = Mid(FileBuffer, PreviousFrame)
Else
GifImageString = Mid(FileBuffer, PreviousFrame, ActualFrame - PreviousFrame)
End If
'
'
' Put your code here to process the frames
'
'
'Get Grafic Control
PackedField = Asc(Mid$(GifImageString, 4, 1))
fraFrame(i).GCGraphicControl.Disposal = (PackedField And 12) / 2 ^ 2
' ADDED BY JMS
fraFrame(i).GCGraphicControl.UserInput = (PackedField And 2) / 2 ^ 1
' ADDED BY JMS
fraFrame(i).GCGraphicControl.TransparentFlag = (PackedField And 1)
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(GifImageString, 5, 1)) + Asc(Mid(GifImageString, 6, 1)) * 256) * 10
If fraFrame(i).GCGraphicControl.Delay = 0 Then fraFrame(i).GCGraphicControl.Delay = 250
'Debug.Print fraFrame(i).GCGraphicControl.Delay
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(GifImageString, 7, 1))
'Get Image Description
fraFrame(i).IDImageDescription.FrameLeft = Asc(Mid(GifImageString, 10, 1)) + Asc(Mid(GifImageString, 11, 1)) * 256
fraFrame(i).IDImageDescription.FrameTop = Asc(Mid(GifImageString, 12, 1)) + Asc(Mid(GifImageString, 13, 1)) * 256
fraFrame(i).IDImageDescription.FrameWidth = Asc(Mid(GifImageString, 14, 1)) + Asc(Mid(GifImageString, 15, 1)) * 256
fraFrame(i).IDImageDescription.FrameHeight = Asc(Mid(GifImageString, 16, 1)) + Asc(Mid(GifImageString, 17, 1)) * 256
'create the image temp
fNum = FreeFile
Open App.Path & "\temp.gif" For Binary As fNum
PictureBuffer = Mid$(FileBuffer, 1, FirstFrame - 1) & GifImageString & Chr(59) '3B
Put #fNum, 1, PictureBuffer
Close fNum
If i > 0 Then
Load aimg(i)
End If
'Now change the backcolor
aimg(i).BackColor = fraFrame(i).GCGraphicControl.TransparentColorIndex
'now load the image
aimg(i).Picture = LoadPicture(App.Path & "\temp.gif")
'change the properties
aimg(i).Tag = fraFrame(i).GCGraphicControl.Delay
'test if theres another frame
If ActualFrame = 0 Then
If i = 0 And (aimg(i).Tag = 0 Or aimg(i).Tag = Empty) Then aimg(i).Tag = 0
Exit Function
End If
PreviousFrame = ActualFrame
i = i + 1
ReDim Preserve fraFrame(i)
Loop
Kill App.Path & "\temp.gif"
LoadGifFile2 = i + 1
'Control the Disposal codes
If aimg.Count > 1 Then
Load aimg(aimg.Count)
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0, 1 ' Leave
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, GetPixel(aimg(i).hdc, 0, 0)
End If
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
Case 3
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, vbSrcCopy
aimg(i).Cls
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, GetPixel(aimg(i).hdc, 0, 0)
Else
TransparentBlt aimg(aimg.Count - 1).hdc, _
fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, _
aimg(i).ScaleHeight, LSDLogicalScreenDescription.BackgroundColor
End If
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
End Select
'Debug.Print fraFrame(i).GCGraphicControl.Disposal
Next i
Unload aimg(aimg.Count - 1)
End If
End Function
thanks
-
Re: [VB6] - animated gif function errors:(
Change the Exit Function to Exit Do
You are still using TransparentBlt when there is no transparency, Why? I told you in a previous post you have to use BitBlt instead.
Also, I see you are still using GetPixel(aimg(i).hdc, 0, 0) and that isn't going to work
-
Re: [VB6] - animated gif function errors:(
ok.. now works better, but i still need work more or disposed methods;)
Code:
Public Function LoadGifFile2(strFileName As String, aimg As Variant) As Long
Dim GifImageStart As String
Dim FrameEnds As Long
Dim GifImageString As String
Dim fNum As Integer
Dim FileBuffer As String
Dim PictureBuffer As String
Dim FirstFrame As String
Dim PreviousFrame As String
Dim ActualFrame As String
Dim fraFrame() As Frame
Dim GifHeader As GifType
Dim strGifHeader As String
Dim strLogicalScreenDescription As String
Dim LSDLogicalScreenDescription As LogicalScreenDescriptor
Dim PackedField As String
Dim i As Long
On Error Resume Next
GifImageStart = Chr(33) & Chr(249) & Chr(4)
'Unload all pictureboxes\images
For i = 1 To aimg.Count - 1
Unload aimg(i)
Next i
'and make the 1st visible;)
'if not the static images can't be showed(sometimes)
aimg(0).Visible = True
'Put all file info to a variable
fNum = FreeFile
Open strFileName For Binary Access Read As fNum
FileBuffer = String(LOF(fNum), Chr(59))
Get #fNum, 1, FileBuffer
Close fNum
'FirstFrame = InStr(1, FileBuffer, GifImageStart)
'Gif Header and Version
strGifHeader = Left$(FileBuffer, 6)
If strGifHeader = "GIF87a" Then
GifHeader = GIF87A
ElseIf strGifHeader = "GIF89a" Then
GifHeader = GIF89A
End If
'see where is the 1st frame
'it's used for create the temp file
FirstFrame = InStr(1, FileBuffer, GifImageStart)
'test if is an animation gif or not;)
If FirstFrame = 0 Then
aimg(0).Picture = LoadPicture(strFileName)
LoadGifFile2 = 1
Exit Function
End If
'Logical Screen Description
strLogicalScreenDescription = Mid$(FileBuffer, 7, 7)
LSDLogicalScreenDescription.GifWidth = Asc(Mid(strLogicalScreenDescription, 1, 1)) + Asc(Mid(strLogicalScreenDescription, 2, 1)) * 256
LSDLogicalScreenDescription.GifHeight = Asc(Mid(strLogicalScreenDescription, 3, 1)) + Asc(Mid(strLogicalScreenDescription, 4, 1)) * 256
PackedField = Asc(Mid$(strLogicalScreenDescription, 5, 1))
LSDLogicalScreenDescription.GlobalColorFlag = (PackedField And 128) / 2 ^ 7
LSDLogicalScreenDescription.ColorResolution = (PackedField And 112) / 2 ^ 4
LSDLogicalScreenDescription.SortFlag = (PackedField And 8) / 2 ^ 3
' NOTE - This value is meanless if GlobalColorFlag is 0
LSDLogicalScreenDescription.GlobalColorSize = PackedField And 7
LSDLogicalScreenDescription.GlobalColorSize = 3 * (2 ^ (LSDLogicalScreenDescription.GlobalColorSize + 1))
LSDLogicalScreenDescription.BackgroundColor = Asc(Mid$(strLogicalScreenDescription, 6, 1))
LSDLogicalScreenDescription.PixelRadio = Asc(Mid$(strLogicalScreenDescription, 7, 1))
i = 0
ActualFrame = 1
ReDim Preserve fraFrame(i)
Do
'test where the frame starts and ends
ActualFrame = InStr(ActualFrame + 1, FileBuffer, GifImageStart)
FrameEnds = InStr(ActualFrame + 1, FileBuffer, GifImageStart) - 1
If FrameEnds <= 0 Then FrameEnds = Len(FileBuffer) - 1
'now put frame data on a variable
GifImageString = Mid(FileBuffer, ActualFrame, FrameEnds)
If GifImageString = "" Then Exit Do
'Get Grafic Control
PackedField = Asc(Mid$(GifImageString, 4, 1))
fraFrame(i).GCGraphicControl.Disposal = (PackedField And 12) / 2 ^ 2
' ADDED BY JMS
fraFrame(i).GCGraphicControl.UserInput = (PackedField And 2) / 2 ^ 1
' ADDED BY JMS
fraFrame(i).GCGraphicControl.TransparentFlag = (PackedField And 1)
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(GifImageString, 5, 1)) + Asc(Mid(GifImageString, 6, 1)) * 256) * 10
If fraFrame(i).GCGraphicControl.Delay = 0 Then fraFrame(i).GCGraphicControl.Delay = 250
'Debug.Print fraFrame(i).GCGraphicControl.Delay
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(GifImageString, 7, 1))
'Get Image Description
fraFrame(i).IDImageDescription.FrameLeft = Asc(Mid(GifImageString, 10, 1)) + Asc(Mid(GifImageString, 11, 1)) * 256
fraFrame(i).IDImageDescription.FrameTop = Asc(Mid(GifImageString, 12, 1)) + Asc(Mid(GifImageString, 13, 1)) * 256
fraFrame(i).IDImageDescription.FrameWidth = Asc(Mid(GifImageString, 14, 1)) + Asc(Mid(GifImageString, 15, 1)) * 256
fraFrame(i).IDImageDescription.FrameHeight = Asc(Mid(GifImageString, 16, 1)) + Asc(Mid(GifImageString, 17, 1)) * 256
'create the image temp
fNum = FreeFile
Open App.Path & "\temp.gif" For Binary As fNum
PictureBuffer = Mid$(FileBuffer, 1, FirstFrame - 1) & GifImageString & Chr(59) '3B
Put #fNum, 1, PictureBuffer
Close fNum
'load an image\picture control if the index is more than 0(zero)
If i > 0 Then
Load aimg(i)
End If
'Now change the backcolor
aimg(i).BackColor = LSDLogicalScreenDescription.BackgroundColor
'now load the image
aimg(i).Picture = LoadPicture(App.Path & "\temp.gif")
'change the properties
aimg(i).Tag = fraFrame(i).GCGraphicControl.Delay
'test if theres another frame
If InStr(ActualFrame + 1, FileBuffer, GifImageStart) <= 0 Then Exit Do
If ActualFrame = 0 Then
If i = 0 And (aimg(i).Tag = 0 Or aimg(i).Tag = Empty) Then aimg(i).Tag = 0
Exit Function
End If
i = i + 1
ReDim Preserve fraFrame(i)
Loop
Kill App.Path & "\temp.gif"
LoadGifFile2 = i + 1
'Control the Disposal codes
If aimg.Count > 1 Then
Load aimg(aimg.Count)
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0, 1 ' Leave
Debug.Print fraFrame(i).GCGraphicControl.TransparentFlag
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
aimg(aimg.Count - 1).Cls
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
TransparentBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, fraFrame(i).GCGraphicControl.TransparentColorIndex
aimg(i).Cls
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
Else
aimg(aimg.Count - 1).Cls
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
TransparentBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).BackColor
aimg(i).Cls
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
End If
Case 3
End Select
'Debug.Print fraFrame(i).GCGraphicControl.Disposal
Next i
Unload aimg(aimg.Count - 1)
End If
End Function
by some reason i can't use the loop for read static gif images, but with that if i can resolved the problem;)
thanks for all my friend
-
Re: [VB6] - animated gif function errors:(
I ran your code after I changed Exit Function to Exit Do and it worked as far as reading the image into picturebox. The only problem i see so far is that you are using TransparentBlt (which you shouldn't) which made the animation come out wrong.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
I ran your code after I changed Exit Function to Exit Do and it worked as far as reading the image into picturebox. The only problem i see so far is that you are using TransparentBlt (which you shouldn't) which made the animation come out wrong.
so i need see the logic of my code;)
thanks;)
-
Re: [VB6] - animated gif function errors:(
-
Re: [VB6] - animated gif function errors:(
About Transparency(it's hide 1 color):
the gif files have 2 colors: the backcolor and the transparent color(the transparent can be igual to backcolor).
if the transparent flag is 1 then the transparent color exists or is used.
i have 2 questions:
1 - what correct color we use for control backcolor?
2 - the method 0(zero) and 1 works with backcolor or transparent color?
(i have tested and i use the transparent color if flag is diferent of 0(zero) else i use the gif backcolor... works fine with some frames... but i need correct it)
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
About Transparency(it's hide 1 color):
the gif files have 2 colors: the backcolor and the transparent color(the transparent can be igual to backcolor).
I have read where some say that the transparent color is same as background. Maybe they are confused and they really mean "transparent background color" which is not the same as saying that transparent color is the same as the background color.
They can be the same but I don't see the point to it and you should not assume that they are. If they are the same then let's say the background color is red and let's also say that the transparent color is red. Its like displaying the red transparent color image on red. What purpose does that serve? For all that matters, you could have blue as the transparent color and you would get the same results.
I noticed in your code when you use the TransparentBlt API you use the upper left corner pixel (0,0) of the image for the transparent color. This I have told you several times is not correct even if you have gotton away with it; it is still incorrect. You need to use the real transparent color as specified by the transparent index for each frame. It is possible that different frames could have a different transparent color so you always need to get the transparent from the local color table of the frame if there is a Local Color Table otherwise get it from the Global Color Table.
Use the background color of the image as the background color of the canvas you are using to display the image.
NOTE: If there is no Global Color Table then there is no Background color. If there is a Global Color Table then the background color must be retrieved from it.
If Transparent flag = 1 then use the transparent color to display the image on the colored canvas.
If Transparent flag = 0 then the image is displayed as is
NOTE: Regardless of which color you use you must use the color indicated by the index value from either the
Global Color Table or the Local Color Table per frame. If a frame has a Local Color Table then you must use the Transparent color from the Local Color Table and not the Global Color Table.
Local Color Table always has precedence over the Global Color table
Quote:
Originally Posted by
joaquim
i have 2 questions:
1 - what correct color we use for control backcolor?
Answered above
Quote:
Originally Posted by
joaquim
2 - the method 0(zero) and 1 works with backcolor or transparent color?
(i have tested and i use the transparent color if flag is diferent of 0(zero) else i use the gif backcolor... works fine with some frames... but i need correct it)
Has nothing to do with the Method. Method only says what to do with the frame after you have displayed it.
The background color of a gif image is meant to be used as the back ground color of the canvas on which you display the image. It has nothing to do with transparency. Some gif images are meant to be displayed on certain colors so as to get the best appearance possible.
For example, I made an animated gif for a friends birthday and it was to say "Happy Birthday, Dear Friend: but it was written as though you were watching someone write a letter and I made it so it looked good on white because I emailed it to my friend and I assumed the normal color of a email background was white. It was black letters written on a white background to make the black letters stand out at their best appearance. Any other color other than white made a poor image. The background color of the image is white. All frames have transparency so that only the black letters show on white background (providing the gif viewer used the background color).
Unfortunately, from what I have seen, using the background color as the canvas color gives undesired results for many gif images. So what do you do? Don't use the background color.
-
Re: [VB6] - animated gif function errors:(
i all most put the "vampire bed" gif animation working;)
my problem is: why the picturebox show us the big frame on back(speaking on 1st frame)(when changes from method 2 or 3 to method 1)?
Code:
Case 0, 1 ' Leave
aimg(aimg.Count - 1).Cls
If fraFrame(i - 1).GCGraphicControl.Disposal = 2 Then
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
Else
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
End If
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, vbSrcCopy
End If
aimg(i).Cls
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
for me, these draw bug don't makes since:(
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
i all most put the "vampire bed" gif animation working;)
my problem is: why the picturebox show us the big frame on back(speaking on 1st frame)(when changes from method 2 or 3 to method 1)?
Code:
Case 0, 1 ' Leave
aimg(aimg.Count - 1).Cls
If fraFrame(i - 1).GCGraphicControl.Disposal = 2 Then
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
Else
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
End If
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, vbSrcCopy
End If
aimg(i).Cls
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
for me, these draw bug don't makes since:(
Are you paying any attention to what I have said to you many times? It doesn't look like you are. Go back and read my previous post again.
-
Re: [VB6] - animated gif function errors:(
i have found my problem:
Code:
Case 0, 1 ' Leave
aimg(aimg.Count - 1).Picture = Nothing
If fraFrame(i - 1).GCGraphicControl.Disposal = 2 Or fraFrame(i - 1).GCGraphicControl.Disposal = 3 Then
Else
BitBlt aimg(aimg.Count - 1).hdc, 0, 0, aimg(i - 1).ScaleWidth, aimg(i - 1).ScaleHeight, aimg(i - 1).hdc, 0, 0, vbSrcCopy
End If
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
TransparentBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, aimg(i).ScaleWidth, aimg(i).ScaleHeight, fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
aimg(i).ScaleWidth, aimg(i).ScaleHeight, aimg(i).hdc, 0, 0, vbSrcCopy
End If
aimg(i).Picture = Nothing
aimg(i).Picture = aimg(aimg.Count - 1).Image
i have 1 question about CLS method: only clean what picturebox show us or everything that it's in picturebox?
can you tell me how can i calculate the Interlace(and what is in Packed Field) on Image Description?
thanks for all
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
i have 1 question about CLS method: only clean what picturebox show us or everything that it's in picturebox?
CLS clears only what you have painted onto the picturebox. It does not clear the picture property.
Quote:
Originally Posted by
joaquim
can you tell me how can i calculate the Interlace
Interlace? Are you going to try and use the image data from the file?
The interlace is quite complicated and I do not believe that I could explain it to you so that you would understand what I am saying but go to the link below and see if you can understand what is being said.
http://en.wikipedia.org/wiki/Graphic...rchange_Format
Quote:
Originally Posted by
joaquim
(and what is in Packed Field) on Image Description?
l
Code:
Image Descriptor
'
' <---X---> <---Y---> <-Width-> <-Height->
' +----+----+----+----+----+----+----+----+----+----+
' | 2C | xx | xx | xx | xx | xx | xx | xx | xx | xx |
' +----+----+----+----+----+----+----+----+----+----+
' |
' +----------- Local Color Table ----------------+
' |
' | location of image within logical window
' | GIF Image Descriptor (packed byte)
' |
' Bit Pos: 7 6 5 4 3 2 1 0
' | | | | |
' | | | | Palette Bit Depth And with 0 0 0 0 0 1 1 1 = &H07 = 7
' | | | Reserver And with 0 0 0 1 1 0 0 0 = &H18 = 24
' | | Table Sorted And with 0 0 1 0 0 0 0 0 = &H20 = 32
' | Interlaced And with 0 1 0 0 0 0 0 0 = &H40 = 64
' Local Color Table used And with 1 0 0 0 0 0 0 0 = &H80 = 128
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
CLS clears only what you have painted onto the picturebox. It does not clear the picture property.
Interlace? Are you going to try and use the image data from the file?
The interlace is quite complicated and I do not believe that I could explain it to you so that you would understand what I am saying but go to the link below and see if you can understand what is being said.
http://en.wikipedia.org/wiki/Graphic...rchange_Format
Code:
Image Descriptor
'
' <---X---> <---Y---> <-Width-> <-Height->
' +----+----+----+----+----+----+----+----+----+----+
' | 2C | xx | xx | xx | xx | xx | xx | xx | xx | xx |
' +----+----+----+----+----+----+----+----+----+----+
' |
' +----------- Local Color Table ----------------+
' |
' | location of image within logical window
' | GIF Image Descriptor (packed byte)
' |
' Bit Pos: 7 6 5 4 3 2 1 0
' | | | | |
' | | | | Palette Bit Depth And with 0 0 0 0 0 1 1 1 = &H07 = 7
' | | | Reserver And with 0 0 0 1 1 0 0 0 = &H18 = 24
' | | Table Sorted And with 0 0 1 0 0 0 0 0 = &H20 = 32
' | Interlaced And with 0 1 0 0 0 0 0 0 = &H40 = 64
' Local Color Table used And with 1 0 0 0 0 0 0 0 = &H80 = 128
i was thinking(from what i read) that Interlaced is a flag for like '0' or '1'.... and for tells us that we need change the backcolor for draw the image better. and i have tested the backcolor and works.
but now i know how test if the image needs it;)
so: interlaced=(PackedField And 64)
thanks for all
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
i was thinking(from what i read) that Interlaced is a flag for like '0' or '1'.... and for tells us that we need change the backcolor for draw the image better. and i have tested the backcolor and works.
but now i know how test if the image needs it;)
so: interlaced=(PackedField And 64)
thanks for all
I don't know where you read that but it is not correct. The Interlaced flag tells you if the image is interlaced or not. It has absolutely nothing to do with changing the backcolor. Look at the following table and if you can understand it OK but what do you think you are going to do with it. It is only meaningfull if you decide to encode the graphics data to render your image instead of using the method you use now (loading re-made files with each frame).
Code:
Interlaced Images.
The rows of an Interlaced images are arranged in the following order:
Group 1 : Every 8th. row, starting with row 0. (Pass 1)
Group 2 : Every 8th. row, starting with row 4. (Pass 2)
Group 3 : Every 4th. row, starting with row 2. (Pass 3)
Group 4 : Every 2nd. row, starting with row 1. (Pass 4)
The Following example illustrates how the rows of an interlaced image are
ordered.
Row Number Interlace Pass
0 ----------------------------------------- ----> 1
1 ----------------------------------------- ----------------------> 4
2 ----------------------------------------- ----------------> 3
3 ----------------------------------------- ----------------------> 4
4 ----------------------------------------- ----------> 2
5 ----------------------------------------- ----------------------> 4
6 ----------------------------------------- ----------------> 3
7 ----------------------------------------- ----------------------> 4
8 ----------------------------------------- 1
9 ----------------------------------------- 4
10 ----------------------------------------- 3
11 ----------------------------------------- 4
12 ----------------------------------------- 2
13 ----------------------------------------- 4
14 ----------------------------------------- 3
15 ----------------------------------------- 4
16 ----------------------------------------- 1
17 ----------------------------------------- 4
18 ----------------------------------------- 3
19 ----------------------------------------- 4
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
see these image...
if backcolor is black, you see some squars arrow the image. but if it's white, the image is drawed correctly. these happens with very images and i thot that the right term was Interlaced.
(if my explication is confused, test it on that image and you see what i mean)
-
Re: [VB6] - animated gif function errors:(
The background color is not black; it is off-white. The color of the background is R=251, G=251, B=251 which is not quite pure white.
Here's a rule you should go by. If the 1st frame has transparency then do not use background color; use the color of the canvas instead. If the 1st frame does not have transparency then use the background color of the image as the color of your canvas.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
The background color is not black; it is off-white. The color of the background is R=251, G=251, B=251 which is not quite pure white.
Here's a rule you should go by. If the 1st frame has transparency then do not use background color; use the color of the canvas instead. If the 1st frame does not have transparency then use the background color of the image as the color of your canvas.
we have the GifBackColor:
Code:
LSDLogicalScreenDescription.BackgroundColor = Asc(Mid$(strLogicalScreenDescription, 6, 1))
and we have the frame transparent color:
Code:
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(GifImageString, 7, 1))
now how can calculate the frame backcolor?
-if it's in picturebox image, we use:
Code:
GetPixel(aimg(i).hdc,0,0)
heres how i change the backcolor:
Code:
'Now change the backcolor
If fraFrame(i).GCGraphicControl.TransparentFlag = 1 Then
aimg(i).BackColor = fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
aimg(i).BackColor = GetPixel(aimg(i).hdc,0,0)
End If
If fraFrame(i).GCGraphicControl.Disposal = 2 Then aimg(i).BackColor = vbWhite
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
we have the GifBackColor:
Code:
LSDLogicalScreenDescription.BackgroundColor = Asc(Mid$(strLogicalScreenDescription, 6, 1))
No! That is not the background color. I have told you many times in my earlier posts about that. Go back and read my previous post #81, page 4
Quote:
Originally Posted by
joaquim
and we have the frame transparent color:
Code:
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(GifImageString, 7, 1))
Same thing as background color above
Quote:
Originally Posted by
joaquim
now how can calculate the frame backcolor?
-if it's in picturebox image, we use:
Code:
GetPixel(aimg(i).hdc,0,0)
No! You cannot use GetPixel(). I have also told you about that many times. It won't work
Quote:
Originally Posted by
joaquim
heres how i change the backcolor:
Code:
'Now change the backcolor
If fraFrame(i).GCGraphicControl.TransparentFlag = 1 Then
aimg(i).BackColor = fraFrame(i).GCGraphicControl.TransparentColorIndex
Else
aimg(i).BackColor = GetPixel(aimg(i).hdc,0,0)
End If
If fraFrame(i).GCGraphicControl.Disposal = 2 Then aimg(i).BackColor = vbWhite
No! Your code is wrong! I told you before that Disposal values have nothing to do with the color of anything.
If you are not going to pay attention to what I have been telling you then I see no point is continueing on because you keep asking questions based on incorrect logic and you will never get your code to work correctly for all gif files. Just because it has appeared to work on some, notice I said appeared to work, it doesn't work. If you do not obey the rules of gif specifications then what is your point?
Once you get it straight in your head how these things work and you start using the correct logic you will find that many of your previous problems will disappear. I'm not saying that all problems will be resolved but at least get it correct from what I have told you then we can go forward but as it is you are just standing still.
-
Re: [VB6] - animated gif function errors:(
i have update my code and now works for all method '0'(except the meter... i must do 1 exact for the '0') and '1'. but the '2' isn't 100% by 1 reason:
Code:
aimg(aimg.Count - 1).Picture = Nothing
BitBlt aimg(aimg.Count - 1).hdc, fraFrame(i).IDImageDescription.FrameLeft, fraFrame(i).IDImageDescription.FrameTop, _
fraFrame(i).IDImageDescription.FrameWidth, fraFrame(i).IDImageDescription.FrameHeight, aimg(i).hdc, 0, 0, vbSrcCopy
aimg(i).Picture = aimg(aimg.Count - 1).Image
the picturebox use, always the same size and i can't control the size correctly:(
any advice?
-
Re: [VB6] - animated gif function errors:(
There is no Method 2 in the meter.gif
Methods 0 and 1 can be treated as the same.
Meter.gif has 1st frame as Leave and all others are Undefined. No transparency in file. Each of the small meter rating pieces (frames 2 - 68) must be exactly the correct size and placed exactly correctly since they have no transparency they must overlay the 1st image in it's exact position.
I see no reason why your positions are incorrect if you extracted the correct positions from the file for frames 2 - 68
Just for testing check the positions of frames 2 - 6. They should be
2) 2,48,10,3
3) 16,48,10,3
4) 30,48,10,3
5) 44,48,10,3
6) 44,44,10,3
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
There is no Method 2 in the meter.gif
Methods 0 and 1 can be treated as the same.
Meter.gif has 1st frame as Leave and all others are Undefined. No transparency in file. Each of the small meter rating pieces (frames 2 - 68) must be exactly the correct size and placed exactly correctly since they have no transparency they must overlay the 1st image in it's exact position.
I see no reason why your positions are incorrect if you extracted the correct positions from the file for frames 2 - 68
Just for testing check the positions of frames 2 - 6. They should be
2) 2,48,10,3
3) 16,48,10,3
4) 30,48,10,3
5) 44,48,10,3
6) 44,44,10,3
thanks for explain to me the meter. i can see the frames(in files), but by some reason the frame it's the same. test the code using the 'i' on files temp and don't kill them. and you see what i mean.
but the ball.gif is give me a control size error:(
i know that is the method 2(all frames), but by some reason i can't see the other frames(only the first). i try control the control size, but seems not working:(
-
Re: [VB6] - animated gif function errors:(
joaquim,
since you have updated your project I need to test with your most recent version otherwise the output may be different so please include you most recent updated version
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
joaquim,
since you have updated your project I need to test with your most recent version otherwise the output may be different so please include you most recent updated version
heres my entire project. for test and see the frames delete the code line:
Code:
'destroy the temp file
Kill App.Path & "\Temp" & i & ".gif"
inside of loop;)
i see the error on 2 images:
meter.gif(something isn't correct with frames:()
(that halloween31.gif image is working fine;))
and the ball.gif... because i can't see the animation correctly. only because of control size:(
thanks for all
-
Re: [VB6] - animated gif function errors:(
One problem I see is that you are not making enough frames from meter. There are 68 frames. You only have 67 (0 to 66) should be 0 to 67. You have a missing frame. Has nothing to do with frame alignment however which I will see what is going on. Other gif files don't work either like ball.gif (which you already stated), down, left, right, and up have wrong backcolor (black is not correct, should be transparent) and star3 has error 50003 loading frame 6. Other gif files don't work that I have tested (ones you don't have in your collection).
First, I'll work on meter.gif
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
One problem I see is that you are not making enough frames from meter. There are 68 frames. You only have 67 (0 to 66) should be 0 to 67. You have a missing frame. Has nothing to do with frame alignment however which I will see what is going on. Other gif files don't work either like ball.gif (which you already stated), down, left, right, and up have wrong backcolor (black is not correct, should be transparent) and star3 has error 50003 loading frame 6. Other gif files don't work that I have tested (ones you don't have in your collection).
First, I'll work on meter.gif
when i create a a file, i do:
Code:
PictureBuffer = Mid$(FileBuffer, 1, FirstFrame - 1) & GifImageString & Chr(59) '3B
- Mid$(FileBuffer, 1, FirstFrame - 1): is the heather gif file(not heather frame)
- GifImageString: is the frame string....
the backcolor been incorrect is that in Mid$(FileBuffer, 1, FirstFrame - 1) give us the gif backcolor instead frame backcolor?
-
Re: [VB6] - animated gif function errors:(
It because you are not using the back color (and you are not using the transparent color either); you are using the index to those colors. In many cases the index will be 0 which is black but 0 means to use color 0 from the color table not the index 0.
-
Re: [VB6] - animated gif function errors:(
All image information are in the ImageDescriptor which is identified by 2C but your code does not get all 2C ImageDescriptors. Your code only searches for 21F9 and then assumes that the ImageDescriptor is at a fixed position beyond that but that is not always the case. Also, an ImageDescriptor can be in a field 21FF which your code does not even search for. For meter.gif the first frame is in a ImageDescriptor (2C) which is in a field marked by 21FF (the Netscape block). This caused 2 frames to be in one saved file; the first frame which is in the Netscape block and the 2nd frame which is in the 21F9 block. This why you are missing image frames from meter.gif and it is probably what is causing your weird problem in the animation; you are actually showing the first frame over and over again because it is in every file you make. I'm sure other gif files are made this way also so you need to re-vamp your code somewhat. Also, quit using the index as the color. It appears that since there is a frame in the 21FF block on all your saved files then all of your saved files will have two pictures in them. I'm surprised it worked the way it does but before I can't straighten out the alignment problem the first problem needs to be corrected and that is to in addition to looking for just 21F9 blocks for image data you also need to look for 21FF blocks and extract out the 1st image and then DO NOT include the 21FF in your other output files (that means you need to not include the 21FF block in the other files.
EDIT:
I looked at some of the output files you make for meter.gif and I see that they all have the first frame in them plus not only that they contain multiple 21F9 blocks
EDIT:
I looked at other output files you make from other gifs and I see that they too have more than one 21F9 block.
I thought the purpose of your code was to make a separate file, one for each frame but if that is so then why do these files have multiple 21F9 blocks in them? What are you doing?
-
Re: [VB6] - animated gif function errors:(
what i do is:
Header Block + Logical Screen Descriptor + Global Color Table + actualframe + Trailer
actualframe = Graphics Control Extension + Image Descriptor + Local Color Table + Image Data
the actual frame is what is in strFramestring.
if i need delete or avoid or change some blocks, i don't know:(
-
Re: [VB6] - animated gif function errors:(
What you do is search from one 21F9 to the next 21F9 and assume that is your images data you want and in some cases it will work but in other cases it will not work. Meter.gif is a good example of one that does not work using your method. When I try to use your output files in a Gif Image Viewer they are all invalid gif files but they are OK for just loading them back into a Picturebox because the Picturebox does not care if the file is invalid or not as long as there is an image in it. The fact that you are outputting invalid gif files tells you that your code is not right. I don't know where you got that code but who ever made it didn't understand the gif format completely. In the case of the meter.gif what is happening is you are displaying the same image over and over again but using the Left and Top values of the other frames and that is what is causing the flickering like results.
Here are some of the things you are doing incorrectly:
1) You search for the 1st 21F9 and assume that is the end of the Global Color Table. Then you make that your Header Block but that will not always work (meter.gif is an example). DO NOT use the 1st 21F9 as the end of the Color Table, use the exact length of the table.
2) You only search for 21F9 code and assume that is the image data you need but image data can also appear in a 21FF block so you ignore the image in these blocks and now you have an invalid gif file. This is what happened when you tried to animate the meter.gif; you actually put an image in the Header Block and then attached another image to it from your actualFrame data thus make a 2-image file. When you load that file back into a Picturebox only the 1st image is placed in the Picturebox which is the same image for all of the frames.
3) You are using the Index to the color table as the actual background color and this is incorrect. The Index points to the actual background color in the color table. In most cases you wind up with black because the Index is 0 and 0 is black.
4) You use GetPixel API to get the transparent color (or background color) from the 0,0 of the image and this is incorrect. The transparent color is in the color table and it has an Index to it just like the background color.