What is disposal code 2?
"2 - Restore to background color. The area used by the
graphic must be restored to the background color."
So, you just simply fill a rectangle with the uc's background color. The position & size of the rectangle are the dimensions of the frame about to be replaced. Try it.
Insomnia is just a byproduct of, "It can't be done"
What is disposal code 2?
"2 - Restore to background color. The area used by the
graphic must be restored to the background color."
So, you just simply fill a rectangle with the uc's background color. The position & size of the rectangle are the dimensions of the frame about to be replaced. Try it.
i'm trying, but without sucess
Code:
Load aImg(aImg.Count)
For I = 0 To aImg.Count - 2
Select Case DisposalCode(I)
Case 2:
aImg(aImg.Count - 1).Cls
aImg(aImg.Count - 1).BackColor = GetPixel(aImg(I - 1).hdc, 0, 0)
TransparentBlt aImg(aImg.Count - 1).hdc, 0, 0, aImg(I - 1).Width, aImg(I - 1).Height, aImg(I - 1).hdc, 0, 0, aImg(I - 1).Width, aImg(I - 1).Height, GetPixel(aImg(I).hdc, 0, 0)
aImg(I).Picture = aImg(aImg.Count - 1).Image
End Select
Next I
Unload aImg(aImg.Count - 1)
Call CreateMaskImage(aImg(i), aImg(aImg.Count - 3)) 'error in aimg(i)
"byref argument type mismatch"
can anyone explain to me what isn't right?
ps.:the entire code is in text file.
Last edited by joaquim; Nov 23rd, 2008 at 06:06 AM.
Public Function LoadGif(sFile As String, aImg As PictureBox) As Boolean
i was using variant type instead picturebox...
but now i continue with a problem(but without a msgbox error)...
can anyone test the code and see where is problem(i know that the problem is in little code, but i don't understand what isn't right)?
thanks
Load aImg(aImg.Count)
For i = 1 To TotalFrames - 1
aImg(aImg.Count - 1).Cls
If DisposalCode(i) = 1 Then
aImg(aImg.Count - 1).Cls
aImg(aImg.Count - 1).Picture = aImg(i - 1).Image
TransparentBlt aImg.Count - 1, 0, 0, aImg(i).Width, aImg(i).Height, aImg(i).hdc, 0, 0, aImg(i).Width, aImg(i).Height, GetPixel(aImg(i).hdc, 0, 0)
End If
aImg(i).Picture = aImg(aImg.Count - 1).Image
Next i
Unload aImg(aImg.Count - 1)
how these works:
1-the 1st image is still igual. is why the cicle for starts in 1 instead 0;
2-the if condicional is only for test if the disposalcode(i) is 1;
3-i created 1 more picturebox for put the result;
4-put the previous image(i-1) in last picturebox;
5-i copy the image(i), but transparent(is why i use the transparentblt() API function to the last picturebox(plus the 2 images);
6-then i copy these last picturebox image in image(i).
but i don't have the right results.
can you tell me where is the error?
thanks
If TotalFrames > 1 Then
Load aImg(aImg.Count)
For i = 1 To TotalFrames - 1
aImg(aImg.Count - 1).Picture = Nothing
If DisposalCode(i) = 1 Then
aImg(aImg.Count - 1).Picture = aImg(i - 1).Image
TransparentBlt aImg(aImg.Count - 1).hdc, 0, 0, aImg(i).Width, aImg(i).Height, aImg(i).hdc, 0, 0, aImg(i).Width, aImg(i).Height, GetPixel(aImg(i).hdc, 0, 0)
End If
aImg(i).Picture = aImg(aImg.Count - 1).Image
Next i
Unload aImg(aImg.Count - 1)
End If
but something isn't right.
is like the picture isn't clean
If no one else assists you, keep working on it and I'll take a look at it this Saturday. If you make any more modifications, be sure to upload the new .bas file and other files/codes we may need to see.
Insomnia is just a byproduct of, "It can't be done"
If no one else assists you, keep working on it and I'll take a look at it this Saturday. If you make any more modifications, be sure to upload the new .bas file and other files/codes we may need to see.
ok. i found something in these line(i delete the "on error resume next" and "on error goto 0"):
now i put it to work. but the results isn't 100% ok
Code:
Dim b As Integer
b = 1
If aImg.Count >= 2 Then
Load aImg(aImg.Count)
For a = 1 To aImg.Count - 2
Debug.Print DisposalCode(a)
If DisposalCode(a) = 1 Or DisposalCode(a) = 2 Then
If b = 2 Then
Else
'previous frame + actual frame(transparent) = result frame
aImg(aImg.Count - 1).Picture = Nothing
aImg(aImg.Count - 1).Picture = aImg(a - 1).Image
TransparentBlt aImg(aImg.Count - 1).hDC, aImg(aImg.Count - 1).ScaleWidth \ 2 - aImg(a).ScaleWidth \ 2, aImg(aImg.Count - 1).ScaleHeight \ 2 - aImg(a).ScaleHeight \ 2, aImg(a).ScaleWidth, aImg(a).ScaleHeight, aImg(a).hDC, 0, 0, aImg(a).ScaleWidth, aImg(a).ScaleHeight, GetPixel(aImg(a).hDC, 0, 0)
aImg(a).Picture = Nothing
aImg(a).Picture = aImg(aImg.Count - 1).Image
If b = 2 Then
b = 1
Else
b = b + 1
End If
End If
End If
Next a
Unload aImg.Count
End If
i have tested these image...
some images are showed normaly. but i see some problems:
1 - the last 2 frames are showed incompleted.
Last edited by joaquim; Mar 17th, 2010 at 04:23 PM.
DisposalCode(TotalFrames) = ((Asc(Mid$(sBuff, lngPreviousFind + 4, 1)) \ 4) And 3)
If TotalFrames = 0 And DisposalCode(TotalFrames) = 3 Then DisposalCode(TotalFrames) = 0
i continue with problems
frame1 is complete.
frame2 need the frame1 to be completed(frame1 + frame2(transparent)).
frame3 is complete(but the method value is 1)
heres the method values(after that change):
1
1
1
1
1
1
the 3rd frame(i belive) that should(it is right write?) be 0 and not 1.
and i don't know why i recive\see 1 empty frame(before repeat the animation)
Last edited by joaquim; Jan 30th, 2010 at 04:40 AM.
You will have some serious problems trying to do this without parsing the GIFs palettes and creating a black and white mask from those palettes to use for your uc's MaskPicture.
1. For your uc to work correctly, your maskpicture must be correct.
2. Each frame in a GIF can have a different mask and each frame in the GIF can be rendered at different X,Y coords and different widths/heights.
3. Because of the different disposal codes, you cannot just use the current frame's mask
4. Masks may need to be combined with previous frames' masks for your uc to draw correctly.
Simple GIFs where the disposal code is always 0,1,2 and the frames are always the same size are easy. But when you get disposal codes of 3 or a code of 2 and frame is drawn at different width,heights or different X,Y coords, then that affects the mask.
If you parse out the palette and the transparent index, you can make the palette index for the transparent index White. Then make all other colors in the palette black. This will give you a black & white (B/W) mask where the color white is transparent. That mask can be used for your uc's maskpicture and maskcolor of white.
But you still have to account for codes of 2 and 3.
With a code of 2 it means you must erase the last frame's area. With the current B/W mask, that means drawing a black rectangle equal to the x,y,width,height of the last frame. Then combining the new frame's mask to that mask.
With a code of 3 it means you must save the mask in memory, combine the current mask with the new frame's mask. When that frame is changed, restore the mask from memory and combine the new frame's mask. But code 3 also requires you to save the previous color portion of the image too and replace that when the frame changes.
As I mentioned in previous posts, the GIF parsing routine you use is not really designed for your needs. It can be modified to parse the palette and it can be modified to get the palette entry of the transparent index.
Last but not least, I cannot see how you can get TransparentBLT to work for you with transparent GIFs. How will you know what color to make transparent? The background color of the DC? What if that DCs color is in the GIF too? Each GIF frame can have a different transparency color or none at all. Also, each GIF frame can have a different palette too.
If you choose, you can use GDI+ to process GIFs and since GDI+ draws each frame with all the disposal codes already processed, it would be very easy to create a B/W mask for each frame. But GDI+ does require some learning if you are not familiar with it and GDI+ is installed on XP and above automatically, but on lesser operating systems, it must be downloaded from Microsoft and installed if not already installed. Edited: Since VB allows you to have a multicolor mask, GDI+ would allow you then to simply render the frame (with transparency) to a bitmap and use that bitmap as the mask. However, you'd still have an issue because you need to know what bitmap background color to use that isn't in any of the GIF frames. This sounds easy but can be difficult because though GIF palettes are limited 256 colors, each frame can have its own palette and therefore a current image combining more than one frame can theoretically contain 16million colors. A few years ago, I did find a site where someone actually created a GIF that contained millions of colors, using mulitple frames and multiple palettes.
Last edited by LaVolpe; Jan 30th, 2010 at 04:53 PM.
Insomnia is just a byproduct of, "It can't be done"