ImageList and animated Gifs

M

MrPickwick

Hi there.
If I place a picturebox on my form and load (at design time) an animated gif
into it, it shows and animates allright. If I load my animated gifs in an
Imagelist at design time and at runtime copy the image from the list into a
PictureBox using "MyPictureBox.Image = MyImageList.Images(n)" it will only
show the first frame and not animate at all.
Does this not work at all? Are there alternatives?

Thanks and regards
 
B

Brian Henry

store the image as an embedded resource it's pretty much what image list
does anyways. then access it similar to this

dim bmp as bitmap = new
Drawing.Bitmap(gettype(classname).Assembly.GetManifestResourceStream("Namesp
ace.FileName.BMP")

(didnt verify the class names so that might be a little off)
 
P

Peter Huang

Hi,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to stored a list of
animated gif into an imagelist and use the picturebox to show the picture
in the imagelist.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think ImageList did not support the animated gif so far. To wordaround
the problem, I think in the IDE we can add the GIFs to the project and
changed their "Build Action" property to "Embedded Resource". Then we can
read them out into an arraylist and use them similar as the imagelist.
Here goes the code.
'I add a test.gif into the project.

Dim pics As ArrayList
Dim imgStream As Stream = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
pics = New ArrayList
Dim bmp As Bitmap = Nothing
' get a reference to the current assembly
Dim a As [Assembly] = [Assembly].GetExecutingAssembly()
' get a list of resource names from the manifest
Dim resNames As String() = a.GetManifestResourceNames()
Dim s As String
For Each s In resNames
If s.EndsWith(".gif") Then
' attach to stream to the resource in the manifest
imgStream = a.GetManifestResourceStream(s)
If Not imgStream Is Nothing Then
' create a new bitmap from this stream and
' add it to the arraylist
bmp = Image.FromStream(imgStream) '
If Not bmp Is Nothing Then
pics.Add(bmp)
End If
bmp = Nothing
End If
End If
Next s
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.PictureBox1.Image = pics(0)
End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
imgStream.Close()
imgStream = Nothing
End Sub

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top