-
Re: [VB6] - animated gif function errors:(
Your code would be a lot easier to read if you use Select Case insteat of a bunch of If statements
Code:
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
Stop
'ActualFrame = PreviousFrame + TransparentActualFrame '
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.BackColor <> LSDLogicalScreenDescription.BackColor 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
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 2 ' Restore Background
'
Case 3 ' Restore Previous
'
Case Else ' Error
'
End Select
Next i
I disagree with your method for transparency. You may think it works but I believe later you will find that it won't be what you expected.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Your code would be a lot easier to read if you use Select Case insteat of a bunch of If statements
Code:
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
Stop
'ActualFrame = PreviousFrame + TransparentActualFrame '
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.BackColor <> LSDLogicalScreenDescription.BackColor 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
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 2 ' Restore Background
'
Case 3 ' Restore Previous
'
Case Else ' Error
'
End Select
Next i
I disagree with your method for transparency. You may think it works but I believe later you will find that it won't be what you expected.
thanks for the Case...End Select opinion. why you use the "stop" keyword"?
my objective is detect if the backcolor is or not is transparent. and that hallowen.gif image works 100% on positions and frame correctly;)
the down.gif image stills show me a problem, because show me the last frame... so the if isn't 100%:(
thanks for all
(MODERATOR: isn't the 1st time that the text cursor have a strange behavior.... but isn't my fault if your forum detect a spam by this bug:()
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Your code would be a lot easier to read if you use Select Case insteat of a bunch of If statements
Code:
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
Stop
'ActualFrame = PreviousFrame + TransparentActualFrame '
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.BackColor <> LSDLogicalScreenDescription.BackColor 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
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 2 ' Restore Background
'
Case 3 ' Restore Previous
'
Case Else ' Error
'
End Select
Next i
I disagree with your method for transparency. You may think it works but I believe later you will find that it won't be what you expected.
thanks for the Case...End Select opinion. why you use the "stop" keyword"?
my objective is detect if the backcolor is or not is transparent. and that hallowen.gif image works 100% on positions and frame correctly;)
the down.gif image stills show me a problem, because show me the last frame... so the if isn't 100%:(
thanks for all
(MODERATOR: isn't the 1st time that the text cursor have a strange behavior.... but isn't my fault if your forum detect a spam by this bug:()
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
thanks for the Case...End Select opinion. why you use the "stop" keyword"?
my objective is detect if the backcolor is or not is transparent. and that hallowen.gif image works 100% on positions and frame correctly;)
the down.gif image stills show me a problem, because show me the last frame... so the if isn't 100%:(
thanks for all
(MODERATOR: isn't the 1st time that the text cursor have a strange behavior.... but isn't my fault if your forum detect a spam by this bug:()
I just forgot to take the Stop out. I use it for testing. The backcolor is never transparent. This is a quote from the official GIF specifications:
The Background Color is the color used for those pixels on the screen that are not covered by an image.
The transparent color is in the color table and you should know that each frame may or may not use the Global Color Table. If a frame does not use the Global Color table then it has it's own Local Color Table. You need to get the transparent color from the color table whether it's from the Global or the Local Color Table. Also, each frame may have a different transparent color. In the case of the hallowen.gif the transparent color is red but you are using the upper left corner (aimg(i).hdc, 0, 0) as the transparent color and that is not correct. if you use the method that you are using you will find that it isn't going to come out correctly for other gif images. I'm just trying to help you understand how a GIF format works and just because hallowen.gif looks like you got it 100% correct it isn't; it just turned out that way.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
I just forgot to take the Stop out. I use it for testing. The backcolor is never transparent. This is a quote from the official GIF specifications:
The Background Color is the color used for those pixels on the screen that are not covered by an image.
The transparent color is in the color table and you should know that each frame may or may not use the Global Color Table. If a frame does not use the Global Color table then it has it's own Local Color Table. You need to get the transparent color from the color table whether it's from the Global or the Local Color Table. Also, each frame may have a different transparent color. In the case of the hallowen.gif the transparent color is red but you are using the upper left corner (aimg(i).hdc, 0, 0) as the transparent color and that is not correct. if you use the method that you are using you will find that it isn't going to come out correctly for other gif images. I'm just trying to help you understand how a GIF format works and just because hallowen.gif looks like you got it 100% correct it isn't; it just turned out that way.
"I'm just trying to help you understand how a GIF format works" and build a new sub for read these files;)
ok... speaking about halloween, i see 2 diferent backcolors. and testing them is the way that i show correctly the frames.... think in these way:
the 2nd frame needs the 1st and the 2nd for be completed... and both backcolor are diferent... it's how i combine them. but for the next frame, i can't use the last frame... that why i use these if... but if you have another sugestion, please tell me;)
-
Re: [VB6] - animated gif function errors:(
Actually, I don't really understand what you are doing. I know you are experimenting around with GIF files but what I don't know is exactly how or what it is that you want to acompolish.
Question: What is the end results of what you are doing? Are you just making a gif animator?
The TransparentBlt API is for copying a picture to another DC and when it "sees" a transparent color on the original picture it wont copy it to the other but you are using this API to copy the background color at location 0,0 of the original picture and that is what I don't understand why you are doing this.
Do me a favor and post the results of Case 1 but only for the first time. I want to see how it looks.
Code:
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
'ActualFrame = PreviousFrame + TransparentActualFrame '
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.BackColor <> LSDLogicalScreenDescription.BackColor 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
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 2 ' Restore Background
'
Case 3 ' Restore Previous
'
Case Else ' Error
'
End Select
Next i
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Actually, I don't really understand what you are doing. I know you are experimenting around with GIF files but what I don't know is exactly how or what it is that you want to acompolish.
Question: What is the end results of what you are doing? Are you just making a gif animator?
The TransparentBlt API is for copying a picture to another DC and when it "sees" a transparent color on the original picture it wont copy it to the other but you are using this API to copy the background color at location 0,0 of the original picture and that is what I don't understand why you are doing this.
Do me a favor and post the results of Case 1 but only for the first time. I want to see how it looks.
Code:
For i = 1 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
'ActualFrame = PreviousFrame + TransparentActualFrame '
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.BackColor <> LSDLogicalScreenDescription.BackColor 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
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 2 ' Restore Background
'
Case 3 ' Restore Previous
'
Case Else ' Error
'
End Select
Next i
what i'm doing is just a gif animator class\module for my 2D Sprite control(i invented);)
but for these i want just draw the frame completed, that's why i need understand more about if theres a transparent backcolor and the methods values;)
-
Re: [VB6] - animated gif function errors:(
if theres a transparent backcolor
There is no transparent backcolor on any gif. I already told you that. It's a back color and not a transparent color.
If you don't post the results that I asked for I can't help you with this because I need to show you something
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
if theres a transparent backcolor
There is no transparent backcolor on any gif. I already told you that. It's a back color and not a transparent color.
If you don't post the results that I asked for I can't help you with this because I need to show you something
i have send you a mail with an image that show you how the frames must be showed... and i show you when the previous image is used or not;)
thanks for all
-
Re: [VB6] - animated gif function errors:(
OK, I looked at the frames you sent me and I can see how they are coming out correctly but as I have said before this may not work in all cases. In this case, using the halloween gif it works because you are using the upper left corner pixel (0,0) of the picturebox as the background color (I thought you were using the background color of the image) and using that as the transparent color. OK, in this case you get away with it but what are you going to do when 0,0 is not the background color of the picturebox? Suppose the upper left corner pixel is part of the image and not the background color? It won't work! What you need to do is to make the background color of the picturebox the same as the transparent color of the gif frame image. That's what I have been trying to tell you; you need to use the image transparent color so there will be no guess work on your part otherwise you may get away with this many times but you will find out that it simply will not work for all gif images. You seem to be creating ways to make it work for your project rather than follow the rules of gif file handling which is OK if that is what you want to do.
Also I still do not understand why you are using pictureboxes when the Image controls already take care of the transparent color for you and you can overlay Image controls because they are themselves transparent so you don't need the TransparentBlt.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
OK, I looked at the frames you sent me and I can see how they are coming out correctly but as I have said before this may not work in all cases. In this case, using the halloween gif it works because you are using the upper left corner pixel (0,0) of the picturebox as the background color (I thought you were using the background color of the image) and using that as the transparent color. OK, in this case you get away with it but what are you going to do when 0,0 is not the background color of the picturebox? Suppose the upper left corner pixel is part of the image and not the background color? It won't work! What you need to do is to make the background color of the picturebox the same as the transparent color of the gif frame image. That's what I have been trying to tell you; you need to use the image transparent color so there will be no guess work on your part otherwise you may get away with this many times but you will find out that it simply will not work for all gif images. You seem to be creating ways to make it work for your project rather than follow the rules of gif file handling which is OK if that is what you want to do.
Also I still do not understand why you are using pictureboxes when the Image controls already take care of the transparent color for you and you can overlay Image controls because they are themselves transparent so you don't need the TransparentBlt.
so you are having forum problems too;)
how you delete that post?
then i just use Transparent Color when Transparent Flag is diferent of '0', right?
-
Re: [VB6] - animated gif function errors:(
Yes I am having Forum problems too. I wound up posting three times. To delete extra posts you click on Edit Post. Then look where it says Delete and click on that.
Here's what you need to make sure of. The background color of the picturebox cannot be a color that is in the gif image otherwise you will wind up making part of the image invisible that should not be invisible. To avoid this you should use the transparent color of the frame as the background color of your picturebox and this will guarantee that you don't make pixels transparent that are not supposed to be transparent. Also, 0,0 may not always be the background; it could be part of the image itself so that would be very bad if you used 0,0 and it is also a color in the image.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Yes I am having Forum problems too. I wound up posting three times. To delete extra posts you click on Edit Post. Then look where it says Delete and click on that.
Here's what you need to make sure of. The background color of the picturebox cannot be a color that is in the gif image otherwise you will wind up making part of the image invisible that should not be invisible. To avoid this you should use the transparent color of the frame as the background color of your picturebox and this will guarantee that you don't make pixels transparent that are not supposed to be transparent. Also, 0,0 may not always be the background; it could be part of the image itself so that would be very bad if you used 0,0 and it is also a color in the image.
Code:
Case 1 ' Leave
If fraFrame(i).GCGraphicControl.TransparentFlag <> 0 Then
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.TransparentColor
aimg(i).Picture = aimg(aimg.Count - 1).Image
aimg(aimg.Count - 1).Cls
End If
now the problem is the color:(
but when i change the picturebox backcolor, the problem is resolved;)
the halloween.gif works 100% fine.. but the down.gif isn't because the method value is 3;)
don't be mad with me and explain, again, the method 2 and 3, please
thanks
-
Re: [VB6] - animated gif function errors:(
"Also I still do not understand why you are using pictureboxes when the Image controls already take care of the transparent color for you and you can overlay Image controls because they are themselves transparent so you don't need the TransparentBlt."
in these case i don't want use the image, speaking on transparency... why, because i want put the complete frame in 1 image;)
if use it in your way, must show some imagesboxes and hidde others(i belive that it's more complicated).... my objective it's show the frame complete on a single image... in same picturebox
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
"Also I still do not understand why you are using pictureboxes when the Image controls already take care of the transparent color for you and you can overlay Image controls because they are themselves transparent so you don't need the TransparentBlt."
in these case i don't want use the image, speaking on transparency... why, because i want put the complete frame in 1 image;)
if use it in your way, must show some imagesboxes and hidde others(i belive that it's more complicated).... my objective it's show the frame complete on a single image... in same picturebox
OK, I understand what your purpose is - it's OK to use pictureboxes and then use the TransparentBLt API which will give you your desired results. Now the next thing is to use the pictureboxes correctly and use the TransparentBLt correctly.
So, let's take this one step at a time starting with the halloween gif.
1) All frames have 1 or Leave as the disposal method. So, you leave each frame as is. You
do not need to do anything with them - just leave them alone - believe me this is the correct
way to do it. You simply copy one frame onto the 1st frame and that is all you have to do
2) Before you load a temp.gif into a picturebox make the picturebox backcolor the same as the
transparent color for that frame then load the temp.gif into the picturebox. The transparent color
is RGB(254, 1, 2) or 131582 or &H000201FE&. Later I will show you how to get the transparent color but for now just use the value I posted above.
3) On your TransparentBlt change the last parameter from GetPixel(aimg(i).hdc, 0, 0) to aimg(i).BackColor
You do not need the GetPixel API.
Code:
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
'
' This assumes that you have followed the above steps 1, 2 , and 3
'
' Leave the 1st picturebox as is then take the second picturebox and do this
'
'ActualFrame = PreviousFrame + TransparentActualFrame '
' I don't know what below does so I will leave it alone
BitBlt aImg(aImg.Count - 1).hdc, 0, 0, aImg(i - 1).ScaleWidth, aImg(i - 1).ScaleHeight, aImg(i - 1).hdc, 0, 0, vbSrcCopy
' You dont need the If statement - just use TransparentBlt for everything
'Not Needed--->If fraFrame(i).GCGraphicControl.BackColor <> LSDLogicalScreenDescription.BackColor 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, _
aImg(i).BackColor
'Not Needed--->Else
'Not Needed---> 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
'Not Needed--->End If
aImg(i).Picture = aImg(aImg.Count - 1).Image
aImg(aImg.Count - 1).Cls
'
'
'
End Select
To simplify what I am saying take a look at the following code. I use Picture1(1) as the first picture which is the closed door. Picture1(2) is the second picture that says Ding Dong. I hard coded the X and Y of picture1(1) to be the same as the Picture1(2) offset just for this example. You do the same thing with the other frames always leaving each frame as is - just copy them like below. Note that I have already made the Picture1(2).BackColor = TransparentColor which is RGB(254, 1, 2) or 131582 or &H000201FE& however one you want to use.
Code:
TransparentBlt Picture1(1).hdc, _
11, _
20, _
Picture1(2).ScaleWidth, _
Picture1(2).ScaleHeight, _
Picture1(2).hdc, _
0, 0, _
Picture1(2).ScaleWidth, _
Picture1(2).ScaleHeight, _
Picture1(2).BackColor
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
NOTE: I forgot to mention. If the frame does not have a Transparent color then you use the Global BackColor or any color that is not part of the image itself for the last parameter of the TransparentBLt API.
I attach example of what I am talking about - run it and just click on each button one at a time to see the results
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
OK, I understand what your purpose is - it's OK to use pictureboxes and then use the TransparentBLt API which will give you your desired results. Now the next thing is to use the pictureboxes correctly and use the TransparentBLt correctly.
So, let's take this one step at a time starting with the halloween gif.
1) All frames have 1 or Leave as the disposal method. So, you leave each frame as is. You
do not need to do anything with them - just leave them alone - believe me this is the correct
way to do it. You simply copy one frame onto the 1st frame and that is all you have to do
2) Before you load a temp.gif into a picturebox make the picturebox backcolor the same as the
transparent color for
that frame then load the temp.gif into the picturebox. The transparent color
is RGB(254, 1, 2) or 131582 or &H000201FE&. Later I will show you how to get the transparent color but for now just use the value I posted above.
3) On your TransparentBlt change the last parameter from GetPixel(aimg(i).hdc, 0, 0) to aimg(i).BackColor
You do not need the GetPixel API.
Code:
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0 ' No Action
'
Case 1 ' Leave
'
' This assumes that you have followed the above steps 1, 2 , and 3
'
' Leave the 1st picturebox as is then take the second picturebox and do this
'
'ActualFrame = PreviousFrame + TransparentActualFrame '
' I don't know what below does so I will leave it alone
BitBlt aImg(aImg.Count - 1).hdc, 0, 0, aImg(i - 1).ScaleWidth, aImg(i - 1).ScaleHeight, aImg(i - 1).hdc, 0, 0, vbSrcCopy
' You dont need the If statement - just use TransparentBlt for everything
'Not Needed--->If fraFrame(i).GCGraphicControl.BackColor <> LSDLogicalScreenDescription.BackColor 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, _
aImg(i).BackColor
'Not Needed--->Else
'Not Needed---> 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
'Not Needed--->End If
aImg(i).Picture = aImg(aImg.Count - 1).Image
aImg(aImg.Count - 1).Cls
'
'
'
End Select
To simplify what I am saying take a look at the following code. I use Picture1(1) as the first picture which is the closed door. Picture1(2) is the second picture that says Ding Dong. I hard coded the X and Y of picture1(1) to be the same as the Picture1(2) offset just for this example. You do the same thing with the other frames always leaving each frame as is - just copy them like below. Note that I have already made the Picture1(2).BackColor = TransparentColor which is RGB(254, 1, 2) or 131582 or &H000201FE& however one you want to use.
Code:
TransparentBlt Picture1(1).hdc, _
11, _
20, _
Picture1(2).ScaleWidth, _
Picture1(2).ScaleHeight, _
Picture1(2).hdc, _
0, 0, _
Picture1(2).ScaleWidth, _
Picture1(2).ScaleHeight, _
Picture1(2).BackColor
BitBlt aImg(aImg.Count - 1).hdc, 0, 0, aImg(i - 1).ScaleWidth, aImg(i - 1).ScaleHeight, aImg(i - 1).hdc, 0, 0, vbSrcCopy
it's just for copy the previous image to the new picturebox. then i put the transparent actual image;)
it's working fine... thanks.
but can you explain to me, again, the methods values... please?
i have a question: if these image have, always, the '0' disposal, why i can't see the image correctly(because i can't nothing down of fire( sorry i don't know some terms)?
(i have anexed an image)
-
Re: [VB6] - animated gif function errors:(
Please send your project with the fire gif so I can test your problem. I can't answer your question as you ask it since I have no way of knowing what or how you are dealing with this situation
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Please send your project with the fire gif so I can test your problem. I can't answer your question as you ask it since I have no way of knowing what or how you are dealing with this situation
heres the entire project;)
errors that i see in 2 images:
1 -halloween34.gif.... i can't see entire image;
2-halloween31.gif... the last frame is strange.
-
Re: [VB6] - animated gif function errors:(
OK, I downloaded your project and I am working on it to see why those gifs are not coming out correctly. I was a little surprised when I looked at your code as I was under the impression that you were using the TransparentsBlt API to do your animation but it doesn't appear like that. I see you are still making the frames visible and invisible in the Timer Sub and didn't you tell me that the reason you wanted to use TransparentBLt was to avoid that?
speaking on transparency... why, because i want put the complete frame in 1 image
if use it in your way, must show some imagesboxes and hidde others(i belive that it's more complicated).
but your code isn't doing what you say above
Code:
Private Sub Timer1_Timer()
Image1(FrameCount).Visible = False
If FrameCount < TotalFrames Then
Image1(FrameCount).Visible = False
FrameCount = FrameCount + 1
Image1(FrameCount).Visible = True
Timer1.Interval = CLng(Image1(FrameCount).Tag)
Else
FrameCount = 0
'For i = 1 To Image1.Count - 1
Image1(tota).Visible = False
'Next i
Image1(FrameCount).Visible = True
Timer1.Interval = Image1(FrameCount).Tag
End If
i = FrameCount
End Sub
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
OK, I downloaded your project and I am working on it to see why those gifs are not coming out correctly. I was a little surprised when I looked at your code as I was under the impression that you were using the TransparentsBlt API to do your animation but it doesn't appear like that. I see you are still making the frames visible and invisible in the Timer Sub and didn't you tell me that the reason you wanted to use TransparentBLt was to avoid that?
speaking on transparency... why, because i want put the complete frame in 1 image
if use it in your way, must show some imagesboxes and hidde others(i belive that it's more complicated).
but your code isn't doing what you say above
Code:
Private Sub Timer1_Timer()
Image1(FrameCount).Visible = False
If FrameCount < TotalFrames Then
Image1(FrameCount).Visible = False
FrameCount = FrameCount + 1
Image1(FrameCount).Visible = True
Timer1.Interval = CLng(Image1(FrameCount).Tag)
Else
FrameCount = 0
'For i = 1 To Image1.Count - 1
Image1(tota).Visible = False
'Next i
Image1(FrameCount).Visible = True
Timer1.Interval = Image1(FrameCount).Tag
End If
i = FrameCount
End Sub
sorry my english:(
that code only do these: hide the previous control and shows the otherone(only show us 1 control). but 1 control have 1 complete frame(with disposal method);)
think on that big image that i give you about halloween... you see 6 frames.... but the 2nd is completed on control and don't depends on previous control;)
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
Do me a favor and download the attached zip I want you to see how I do it using TransparentAPI by just putting one frame on top of the other. This is not a gif animation program it is just a demonstrating of the 6 frames where I put one on top of the other. Run the project and click on each button one at a time and look at the results on the first picture. This is what I thought you were doing similar to this but using your own code. Notice how the transparent color is red which is the correct transparent color for this gif file. You are not using the transparent color as the backColor for the picture but you are using the index to the transparent color which wont work in other cases - you are just lucky on this one that the index value was 0 which gives you a black background color which worked for your halloween picture becaue it is on a black background but that is not what you want, you want the real transparent color which is red like I have.
I think your method in the aniMod is a little confusing although I see what you are doing I think it's more than you need to do. My demo illustrates how it should be done for the halloween gif because it is emulating the Leave method exactly. If you were to put my demo in a timing loop using the correct timing values for each frame you will see how simple the Leave method really is.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Do me a favor and download the attached zip I want you to see how I do it using TransparentAPI by just putting one frame on top of the other. This is not a gif animation program it is just a demonstrating of the 6 frames where I put one on top of the other. Run the project and click on each button one at a time and look at the results on the first picture. This is what I thought you were doing similar to this but using your own code. Notice how the transparent color is red which is the correct transparent color for this gif file. You are not using the transparent color as the backColor for the picture but you are using the index to the transparent color which wont work in other cases - you are just lucky on this one that the index value was 0 which gives you a black background color which worked for your halloween picture becaue it is on a black background but that is not what you want, you want the real transparent color which is red like I have.
I think your method in the aniMod is a little confusing although I see what you are doing I think it's more than you need to do. My demo illustrates how it should be done for the halloween gif because it is emulating the Leave method exactly. If you were to put my demo in a timing loop using the correct timing values for each frame you will see how simple the Leave method really is.
is more or less that i did;)
1 - i put all frames on picturebox array;
2 - now i compare the disposal methods and draw them correctly on picturebox array;
3 - now the timer just need hide or show the right picturebox... and the frame is showed normaly.
i understand the bakcolor is red, my problem is: what i didn't did right?
i did:
Code:
' 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
' NOTE This value is meaningless if TransparentFlag is 0
fraFrame(i).GCGraphicControl.TransparentColor = Asc(Mid$(strFrame, 7, 1))
-
Re: [VB6] - animated gif function errors:(
fraFrame(i).GCGraphicControl.TransparentColor = Asc(Mid$(strFrame, 7, 1))
This is the index to the transparent color. I should have made it this
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(strFrame, 7, 1))
To get the actual transparent color you must:
1) determine if the frame uses the Global Color Table or the Local Color Table.
2) from which ever color table is used, multiple the Index by 3 and add that answer to the base of the color table.
3) extract out 3-bytes from the table. 1st byte = R, 2nd byte = G, and 3rd byte = B or (RGB)
Now these three bytes are in character format so they will need to be converted to ascii and converted to Long variable
So you would use something like this
Dim TransparentColor As Long
TransparentColor = B * 65536 + G * 256 + R
then you would do this:
TransparentBlt ................ , aimg(i).BackColor = TransparentColor
4) if there is a Global Color Table it starts here at position 14 in the file:
5) if there is a Local Color Table (per frame) then you use it (per frame) instead of the Global Color Table.
6) if there is a Local Color Table it starts here (example, Left.gif uses Local Color Table):
Code:
1st Color --+ +--2nd Color +-- Last Color
| | |
+--+----+----+----+----+-+-+-+-+-+-+-+-----+-+-+-+
|2C| | | | | |R|G|B|R|G|B|.....|R|G|B|
+--+----+----+----+----+-+-+-+-+-+-+-+-----+-+-+-+
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
fraFrame(i).GCGraphicControl.TransparentColor = Asc(Mid$(strFrame, 7, 1))
This is the index to the transparent color. I should have made it this
fraFrame(i).GCGraphicControl.TransparentColorIndex = Asc(Mid$(strFrame, 7, 1))
To get the actual transparent color you must:
1) determine if the frame uses the Global Color Table or the Local Color Table.
2) from which ever color table is used, multiple the Index by 3 and add that answer to the base of the color table.
3) extract out 3-bytes from the table. 1st byte = R, 2nd byte = G, and 3rd byte = B or (RGB)
Now these three bytes are in character format so they will need to be converted to ascii and converted to Long variable
So you would use something like this
Dim TransparentColor As Long
TransparentColor = B * 65536 + G * 256 + R
then you would do this:
TransparentBlt ................ , aimg(i).BackColor = TransparentColor
4) if there is a Global Color Table it starts here at position 14 in the file:
5) if there is a Local Color Table (per frame) then you use it (per frame) instead of the Global Color Table.
6) if there is a Local Color Table it starts here (example, Left.gif uses Local Color Table):
Code:
1st Color --+ +--2nd Color +-- Last Color
| | |
+--+----+----+----+----+-+-+-+-+-+-+-+-----+-+-+-+
|2C| | | | | |R|G|B|R|G|B|.....|R|G|B|
+--+----+----+----+----+-+-+-+-+-+-+-+-----+-+-+-+
it's very confuse:(
i belive that theres another way...
do me a favor and change these 2 lines:
Code:
'Now change the backcolor
'aimg(i).BackColor = fraFrame(i).GCGraphicControl.TransparentColorIndex (now it's a comment)
and:
Code:
'Control the Disposal codes
If aimg.Count > 1000 Then
now i have 1 question: why the 2nd frame have white backcolor(still on Halloween46.gif) instead red?
-
1 Attachment(s)
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
heres the entire project;)
errors that i see in 2 images:
1 -halloween34.gif.... i can't see entire image;
2-halloween31.gif... the last frame is strange.
Halloween34 has all frames as 0 (Undefined) and in your code where you process the disposal values I see that Case 0 is empty so in essence you do nothing but retain the pictures in their picture boxes. Now in your Timer code you make invisible each preceeding frame and simply display each frame as though it was the only frame to show and that is incorrect because each frame must be overlayed on the preceeding frame. It worked with Halloween46 because you actually processed each frame in Case 1. Now you have each frame that holds the results of the previous frame so you got away with it in your Timer code and that is why you don't see the entire image
Also, Halloween34 has no transparent color and you need to take that into account.
Not only is the last frame strange some of the others are not correct either. There is nothing in your code to process halloween31. This gif has disposal of 2 (RestoreBackground) but your code only handles disposal 1 (Leave) and that isn't going to work for this gif. What did you expect?
See may attached image - you see that I have it correctly displayed.
Quote:
Originally Posted by
joaquim
is more or less that i did;)
1 - i put all frames on picturebox array;
2 - now i compare the disposal methods and draw them correctly on picturebox array;
3 - now the timer just need hide or show the right picturebox... and the frame is showed normaly.
i understand the bakcolor is red, my problem is: what i didn't did right?
i did:
I guess there is no reason for me to comment on this as I can see you are determined to do it this way. I am not 100% positive that it won't work in all cases but only time will tell. Even if it does work it looks like a lot of extra coding and it is not as simple as to just display each frame onto a canvas one by one then you don't need that extra code in your Timer Sub
Quote:
Originally Posted by
joaquim
it's very confuse:(
i belive that theres another way...
do me a favor and change these 2 lines:
Code:
'Now change the backcolor
'aimg(i).BackColor = fraFrame(i).GCGraphicControl.TransparentColorIndex (now it's a comment)
and:
Code:
'Control the Disposal codes
If aimg.Count > 1000 Then
now i have 1 question: why the 2nd frame have white backcolor(still on Halloween46.gif) instead red?
It isn't really that confusing and you are going to have to follow the rules of gif file processing. You need to test for Global Color Table and Local Color Table and use the one that is appropiate for the frame you are processing - there is no other way. Also, the background color you are using is not the background color of the image; it is the index to the background color and you need to extract it from the color table as I described for you in my previous post.
I do not know what you want me to do with your suggested change above. You want me to comment out that one statement and add the If aimg.Count > 1000 Then statement but then what? You give no code for the If clause.
I can only give you advise and help on your project but only in the sense of the correct way of doing it and not the code you write to process the disposal values because I do not think that method is the correct way of displaying gif images.
Gif anaimation is designed to first have a canvas to receive the frames. A canvas can be a Picturebox, a RTB, a WebBrowser page, or any surface that can hold an image. The area used for the canvas is made the size of the Width and Height of the values in
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
Only the canvas is this size. Then you render each frame image onto this canvas then do as the disposal method says; if it's Leave then leave the image as is; if it's RestoreBackground then simply restore the background color of the canvas, etc. The background color of the canvas is:
1) If image is to be rendered with transparency then make the color of the canvas any color you want except the BackColor of the GIF
2) If the image is to be rendered without transparency the make the color of the canvas the same as the BackColor specified in the GIF specifications.
Also, you need to test each frame to see if it has a transparent color or not. If it does then you use TransparentBlt and if it doesn't you use BitBlt to render the image onto the canvas.
-
Re: [VB6] - animated gif function errors:(
still having problems for login on forum:( :(
i change the code:
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
'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))
ActualFrame = FirstFrame
'if the image isn't animated, then just draw it;)
If InStr(FirstFrame + 2, FileBuffer, Chr(33) & Chr(249)) = 0 Then
aimg(0).Picture = LoadPicture(strFileName)
aimg(0).Tag = 0
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))
'image count
i = 0
ReDim Preserve fraFrame(i)
Do
'get frame string
If InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249)) <> 0 Then
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249)) - 2
Else
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(59)) - 1
End If
strFrame = Mid$(FileBuffer, ActualFrame, Len(FileBuffer) - FirstFrame)
'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
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)) = 0 Then
Exit Do
Else
ActualFrame = InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249))
i = i + 1
If i > 0 Then ReDim Preserve fraFrame(i)
End If
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
End Select
Debug.Print fraFrame(i).GCGraphicControl.Disposal
Next i
Unload aimg(aimg.Count - 1)
End If
End Function
- now i can see that little fire image normaly;)
- the last frame, on the "vampire bed", i can't see it... but i understand that it's the backcolor\transparency problems;
anotherthing: why in some images:
Code:
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256) * 10
give me an Ovverflow error?
and 1 image gives me a loop infinite:(
-
Re: [VB6] - animated gif function errors:(
You have GCGraphicControl.Delay defined as a LOng variable so you shouldn't get an overflow. I have it defined as an Integer variable and I do not get overflow. What image gives you the overflow on the .Delay.
Also, I see that you still are not processing RestoreBackground since you have no Case 2 in your code. If you don't do this you are never going to get your images to animate correctly.
What image gives you an infinite loop?
-
2 Attachment(s)
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
You have GCGraphicControl.Delay defined as a LOng variable so you shouldn't get an overflow. I have it defined as an Integer variable and I do not get overflow. What image gives you the overflow on the .Delay.
Also, I see that you still are not processing RestoreBackground since you have no Case 2 in your code. If you don't do this you are never going to get your images to animate correctly.
What image gives you an infinite loop?
heres how i correct the overflow:
Code:
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256) * 10
If fraFrame(i).GCGraphicControl.Delay > 276520 Or fraFrame(i).GCGraphicControl.Delay = 0 Or fraFrame(i).GCGraphicControl.Delay = "" Then fraFrame(i).GCGraphicControl.Delay = fraFrame(0).GCGraphicControl.Delay
why that const and 0 and ""??? because it's what i get.
can you explain to me the case 2 and 3(again)?
- the brucekik.gif gives me the infinite loop;
- the T-rex.gif give me that const values... overflow errors.
-
Re: [VB6] - animated gif function errors:(
why that const and 0 and ""??? because it's what i get.
Sorry, I don't understand your statement.
Case 2
RestoreBackground means to restore the background color of the canvas that you render the image onto.
The background color of the canvas can be
1) If no transparency in image the BackColor as specified in the GIF specifications
Code:
Fixed Length
+---- GIF Header ---+
| |
Packed byte -----------|--------------+ |
Logical Screen Height -|------------+ | |
Logical Screen Width --|---------+ | | |
| | | | |
+---+---+--+--+-+-+-+
|GIF|89a| | | |X | |
+---+---+--+--+-+-+-+
| |
| |
Background Color Index -----------------+ |
Pixel Aspect Ratio -----------------------+
Take X and multiply it by 3 and add the results to the base of the appropriate color table (Global or Local)
whichever one is to be used. Local Color Table has power over Global Color Table
Extract out the 3-bytes at that offset into the color table and convert each byte to Ascii. This gives you
the R, G, B values of the background color. This is what you use; not the index that you are using.
BTW: use this same method for the transparent color.
2) if transparency in image then the background color of the canvas can be
any color that is not
a) the transparent color or
b) the background color of the image
Case 3
RestorePrevious means to restore the last image that was not disposed. Usually this mean the last image that had a disposal of 0 or 1.
-
Re: [VB6] - animated gif function errors:(
Code:
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256&) * 10&
If fraFrame(i).GCGraphicControl.Delay = 276520 Or fraFrame(i).GCGraphicControl.Delay = 0 Or fraFrame(i).GCGraphicControl.Delay = Empty Then fraFrame(i).GCGraphicControl.Delay = fraFrame(0).GCGraphicControl.Delay
why i compare the 0(zero), 276520 and Empty values???
because is what i get... and i don't know why:(
(i debug it for see the values)
and using:
Code:
On Error Resume Next
i avoid more errors... ok isn't good pratice using these line, but i can't avoid all errors that i don't understand...
thanks for all my friend
-
Re: [VB6] - animated gif function errors:(
Do not avoid errors. If you do then you will find that your animation is going to come out crap and you are not going to know why. You need the errors to tell you what the problem is and then try to code for those circumstances.
Keep this in mind, GIF files are made by many people and companies. They do not always follow the rules and sometimes they even screw up the format because they do not understand what they are supposed to do. There is also the possibility that your code is not correct or complete to handle all GIF files. Only trial and error will get you there.
T-Rex has all frames set to 0 Delay except frame 6 which has an error in the file format which is what causes your value of 27652 then you multiply that by 10 to get 276520 . Rule of thumb: If Delay is 0 or it is greater than 1000 then make the Delay for 10 or 100 whichever you think is best (then times your 10 if that is what you like). T-Rex also has all frames set to RestoreBackground. I told you how to handle this method.
Also, it appears that T-Rex was made by an unregistered copy of Gif Construction Set by someone at Alchemy Mindworks Inc by an amature or it wasn't put together correctly.
Brucekik has two frames, both set to Undefined (which you treat as though it was Leave) and it's Delay is 20 for both frames.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
Do not avoid errors. If you do then you will find that your animation is going to come out crap and you are not going to know why. You need the errors to tell you what the problem is and then try to code for those circumstances.
Keep this in mind, GIF files are made by many people and companies. They do not always follow the rules and sometimes they even screw up the format because they do not understand what they are supposed to do. There is also the possibility that your code is not correct or complete to handle all GIF files. Only trial and error will get you there.
T-Rex has all frames set to 0 Delay except frame 6 which has an error in the file format which is what causes your value of 27652 then you multiply that by 10 to get 276520 . Rule of thumb: If Delay is 0 or it is greater than 1000 then make the Delay for 10 or 100 whichever you think is best (then times your 10 if that is what you like). T-Rex also has all frames set to RestoreBackground. I told you how to handle this method.
Also, it appears that T-Rex was made by an unregistered copy of Gif Construction Set by someone at Alchemy Mindworks Inc by an amature or it wasn't put together correctly.
Brucekik has two frames, both set to Undefined (which you treat as though it was Leave) and it's Delay is 20 for both frames.
now i can see the t-rex animation with that 'if'.... but like you said, my transparency code isn't 100%;)
with brucelikik.gif: sorry, but seems that the program enters in infinite loop... but i will test it and i will tell you more.
thanks for all my friend
-
Re: [VB6] - animated gif function errors:(
with brucelikik.gif: sorry, but seems that the program enters in infinite loop
It isn't the gif; it's your code that isn't capturing the image correctly. I used your code with that gif and it freezes up trying to load the picture but when I use my code it works perfectly.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
with brucelikik.gif: sorry, but seems that the program enters in infinite loop
It isn't the gif; it's your code that isn't capturing the image correctly. I used your code with that gif and it freezes up trying to load the picture but when I use my code it works perfectly.
we know that Chr(33) & Chr(249) it's the frame start unless you use a diferent way;)
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
joaquim
we know that Chr(33) & Chr(249) it's the frame start unless you use a diferent way;)
I use Chr(33) & Chr(249) & Chr(4) because that guarantees the beginning of a gif frame. In t-rex.gif it had an invalid frame and that's why you got that large Delay value. The invalid frame started with Chr(33) & Chr(249) but the next byte was not a Chr(4) which is guaranteed by the specifications to be the 3rd byte. So, when your code processed t-rex it picked up that as a valid frame but it was just garbage in the file.
As far as brucekik.gif goes it has 2 valid frames. It is a valid gif file but your code is not correct in the way you loop through the frames and I am quite surprised that it has worked up till now until you tried to process brucekik.gif.
One thing I have noticed from the very beginning is that when you extract out a frame and then add the header to it you save it as a complete gif file but if I try to use that saved gif it is not a valid gif file because it will not display in the browser or any other gif viewer.
Process any gif file that you have been able to display and save all of the temp.gif files. Now double click on each one of them to see if they are valid - I bet they are not.
You need to re-consider the way you are looping through the frames because somewhere in your code you are not picking up all the data correctly even though you have been able to animate them you have been lucky. Now you try to process brucekik.gif and your code freeze when trying to load the temp.gif back into your image array.
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
I use Chr(33) & Chr(249) & Chr(4) because that guarantees the beginning of a gif frame. In t-rex.gif it had an invalid frame and that's why you got that large Delay value. The invalid frame started with Chr(33) & Chr(249) but the next byte was not a Chr(4) which is guaranteed by the specifications to be the 3rd byte. So, when your code processed t-rex it picked up that as a valid frame but it was just garbage in the file.
As far as brucekik.gif goes it has 2 valid frames. It is a valid gif file but your code is not correct in the way you loop through the frames and I am quite surprised that it has worked up till now until you tried to process brucekik.gif.
One thing I have noticed from the very beginning is that when you extract out a frame and then add the header to it you save it as a complete gif file but if I try to use that saved gif it is not a valid gif file because it will not display in the browser or any other gif viewer.
Process any gif file that you have been able to display and save all of the temp.gif files. Now double click on each one of them to see if they are valid - I bet they are not.
You need to re-consider the way you are looping through the frames because somewhere in your code you are not picking up all the data correctly even though you have been able to animate them you have been lucky. Now you try to process brucekik.gif and your code freeze when trying to load the temp.gif back into your image array.
i can open my temp files normaly;)
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))
ActualFrame = FirstFrame
'if the image isn't animated, then just draw it;)
If InStr(FirstFrame + 2, FileBuffer, Chr(33) & Chr(249)) = 0 Then
aimg(0).Picture = LoadPicture(strFileName)
aimg(0).Tag = 0
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))
'image count
i = 0
ReDim Preserve fraFrame(i)
Do
'get frame string
If InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249)) <> 0 Then
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(33) & Chr(249)) - 2
Else
FrameEnds = InStr(ActualFrame + 2, FileBuffer, Chr(59)) - 1
End If
strFrame = Mid$(FileBuffer, ActualFrame, Len(FileBuffer) - FirstFrame)
'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
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))
i = i + 1
If i > 0 Then ReDim Preserve fraFrame(i)
End If
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 = 0 To aimg.Count - 2
Select Case fraFrame(i).GCGraphicControl.Disposal
Case 0, 1 ' Leave
If i = 0 Then i = 1
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
test these function
-
Re: [VB6] - animated gif function errors:(
i can open my temp files normaly
What does that mean? Are you telling me that those temp.gif files can be displayed in a browser? In a gif viewer? Or are you saying you can open them normally in your program? If you can open them normally then your program would not freeze up on brucekik.gif.
I tested your last code posted. Only some of the frames are coming out OK but others are invalid and cannot be displayed on browser or gif viewer.
Tested t-rex
Following errors occured on 1st frame only
OVERFLOW
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256) * 10
OVERFLOW
fraFrame(i).IDImageDescription.FrameTop = Asc(Mid(strFrame, 12, 1)) + Asc(Mid(strFrame, 13, 1)) * 256
OVERFLOW
fraFrame(i).IDImageDescription.FrameHeight = Asc(Mid(strFrame, 16, 1)) + Asc(Mid(strFrame, 17, 1)) * 256
INVALID PICTURE
aimg(i).Picture = LoadPicture(App.Path & "\temp(" & FrameCounter & ").gif") '<---- TEMP JMS
Tested brucekik.gif
Still freezes when loading picture
Tested coffin
Animation isn't correct probably because you are not doing correct disposal methods plus you have dark background and it should not have that.
Tested Candle
Looks OK
-
Re: [VB6] - animated gif function errors:(
Quote:
Originally Posted by
jmsrickland
i can open my temp files normaly
What does that mean? Are you telling me that those temp.gif files can be displayed in a browser? In a gif viewer? Or are you saying you can open them normally in your program? If you can open them normally then your program would not freeze up on brucekik.gif.
I tested your last code posted. Only some of the frames are coming out OK but others are invalid and cannot be displayed on browser or gif viewer.
Tested t-rex
Following errors occured on 1st frame only
OVERFLOW
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256) * 10
OVERFLOW
fraFrame(i).IDImageDescription.FrameTop = Asc(Mid(strFrame, 12, 1)) + Asc(Mid(strFrame, 13, 1)) * 256
OVERFLOW
fraFrame(i).IDImageDescription.FrameHeight = Asc(Mid(strFrame, 16, 1)) + Asc(Mid(strFrame, 17, 1)) * 256
INVALID PICTURE
aimg(i).Picture = LoadPicture(App.Path & "\temp(" & FrameCounter & ").gif") '<---- TEMP JMS
Tested brucekik.gif
Still freezes when loading picture
Tested coffin
Animation isn't correct probably because you are not doing correct disposal methods plus you have dark background and it should not have that.
Tested Candle
Looks OK
i did resolve the T-rex animation;)
Code:
fraFrame(i).GCGraphicControl.Delay = (Asc(Mid(strFrame, 5, 1)) + Asc(Mid(strFrame, 6, 1)) * 256) * 10
If fraFrame(i).GCGraphicControl.Delay = 276520 Or fraFrame(i).GCGraphicControl.Delay = 0 Or fraFrame(i).GCGraphicControl.Delay = "" Then fraFrame(i).GCGraphicControl.Delay = 250
ok.. i still use "on error resume next", but i will, by time, catch all bugs;)
thanks for all my friend
-
Re: [VB6] - animated gif function errors:(
i belive that i know where is the problem;)
i have these code for see the frame start position:
Code:
FirstFrame = InStr(13, FileBuffer, Chr(33) & Chr(249))
(i said 13, but i belive that i can use the 0(zero);))
but the position is the chr(33) or chr(249)?
what i know is the frames starts from chr(33) and ends with another chr(33) or, if is the file end, chr(59)... but i don't know, exacly, how works instr() function with char comparation results... can you tell me what position is?
(if i correct these, i can read the brucekik.gif;))
-
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:(