Loop through images to simulate video

Jan 29, 2014 at 10:09 PM
So I have a series of 20 weather images (GIF files with accompanying world files) and if I load one it looks great on my map. What I am trying to do now is simulate a "video" of the weather as it moves. My first shot is going to be to loop through each image, open each image, clear the image layer, then load the new image into the layer. Is something that someone has done before and if so whats the best approach to do this kind of functionality?

Jan 30, 2014 at 10:47 AM

I wonder if it would be faster or smoother to load all the images and then just turn the layers on and off in rapid sequence?

Jan 30, 2014 at 9:38 PM
well that may be what I'm doing? I am loading an image and adding as a layer. i then cycle through my other images and open those up with the same image object so I think it's still using the one layer but the reference to the image has been changed? Unless I am effectively clearing the current image before adding another. Can you take a look and see how this looks to you? It seems to work pretty well but I may be using more resources than I should. I am trying also to account for the case where the user clicks on the button more than once to replay the "video" more than once.
'global variables
Dim img As MapWinGIS.Image 
Dim hnd As Integer

 Private Sub btnLoadImages_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadImages.Click
            Dim gifFile As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath(), "Wx\radar.gif")

            If My.Computer.FileSystem.FileExists(gifFile) Then
                If img IsNot Nothing Then
                    img= New MapWinGIS.Image
                End If

                If img.Open(gifFile, MapWinGIS.ImageType.USE_FILE_EXTENSION) Then
                    hnd = mapMain.AddLayer(img, True)
                    MsgBox("Could not load image." & crlf & img.ErrorMsg(img.LastErrorCode), MsgBoxStyle.Critical)
                End If

                'cycle through the collection of images
                For i As Integer = 1 To 28 Step 1

                    gifFile = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath(), "Wx\radarNTS" & i & ".gif")

                    img.Open(gifFile, MapWinGIS.ImageType.USE_FILE_EXTENSION)

                Next i

                MsgBox("Done.", MsgBoxStyle.Information)
                MsgBox("Image file does not exist.", MsgBoxStyle.Exclamation)
            End If
        Catch ex As Exception
            MsgBox("There was an error encountered." & ControlChars.CrLf & ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
Feb 3, 2014 at 6:45 PM
How about loading all images as separate layers and move the one you want to show to the top and enable?
If you lock and unlock the map prior to the move, the user shouldn't notice anything.

When moving the layer instead of reloading it you don't need mapMain.Redraw() or mapMain.Refreh(), just Application.DoEvents().

Reading back this topic it seems Dan suggested the same ;)

So load each image in its own layer instead of re-using the image object of the same layer.

Feb 4, 2014 at 2:53 PM
I want to stay away from loading all images as one layer. the number of images could be from 20 to 100 to cycle through an entire collection. I wanted to display that on my legend and that will create as many clickable layers in the legend. I tested it just changing the image reference and it seems to work. I will tweak it some more and report back my results.
Feb 4, 2014 at 3:55 PM
Edited Feb 4, 2014 at 3:58 PM
I took a video of thew result. Take a look at it here and let me know what you think. The Flash video looks best in Chrome but crappy in IE.
Feb 10, 2014 at 10:41 AM
In MapWindow we have an option to show a layer in the legend or not.
Are you using the MapWindow legend or a custom one?

I will have a look at you video when I have a compatible browser. FF is not working either ;)

Feb 10, 2014 at 7:41 PM
I am using the built in Legend. The thing is I do want to show this layer in the legend. So far just changing the image and keeping the same layer seems to work ok. Don't know if that's any less resources or not.