469,964 Members | 1,754 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

ImageList and animated Gifs

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
Nov 20 '05 #1
4 7413
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.GetMani festResourceStream("Namesp
ace.FileName.BMP")

(didnt verify the class names so that might be a little off)
"MrPickwick" <td*@odic.tc> wrote in message
news:eP**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #2
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.GetMani festResourceStream("Namesp
ace.FileName.BMP")

(didnt verify the class names so that might be a little off)
"MrPickwick" <td*@odic.tc> wrote in message
news:eP**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #3
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.

Nov 20 '05 #4
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.

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by John J. Hughes II | last post: by
2 posts views Thread by Koen Hoorelbeke | last post: by
reply views Thread by MrPickwick | last post: by
2 posts views Thread by Scirious | last post: by
3 posts views Thread by ZikO | last post: by
4 posts views Thread by Jeff | last post: by
27 posts views Thread by Phil | last post: by
reply views Thread by helraizer1 | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.