Hey everyone, I just wanted to say that VBforums is awesome! Out of every online community I have been in, this one has been the most supportive. Thanks!

Anyway, I have been trying for a couple of days now at work to compile a series of images into an animated GIF using the GDI+ library. I don't have access to any other image processing libraries so if at all possible I'd like to stick to using that one. I am putting together a program to automate some on screen actions in a 3D program and take screen shots at the same time. Those screen shots are saved to the Hard drive and are named chronologically. So far this functionality has been developed and is working well.

At this point though I am not sure what to do. I have seen some online examples in C# using the GDI+ library but I don't understand it. I have been studying and testing portions of code from the following link:

http://www.dreamincode.net/forums/to...ssing-program/

Specifically the Assemble() subroutine where according to the author is where the animated GIF is made (Below it can be viewed).

There is miscellaneous code in there pertaining to Form controls, but besides those, it seems like the images are being looped through one at a time and being opened with BinaryWriter, and eventually saved to a MemoryStream in the format of a GIF. At the end of the subroutine it looks like the compiled GIF is displayed in a PictureBox form control. At least this is what I gathered so far.

I don't quite understand how the image is being assembled though. I have never used MemoryStream or BinaryWriter before and it looks the image is saved to MemoryStream before it's finally displayed. Also, what are the Bytes data type for and what does that accomplish?

Can somebody help me make sense of what is going on this code. Is this going to help me create and save an animated GIF with my screenshots or should I resort to using something else?

Thank you for your time.

Code:
    Public Sub Assemble(ByVal But As Integer)
        Me.Cursor = Cursors.WaitCursor
        'Variable declaration
        Dim memoryStream As MemoryStream
        Dim binaryWriter As BinaryWriter
        Dim image As Image
        Dim buf1 As [Byte]()
        Dim buf2 As [Byte]()
        Dim buf3 As [Byte]()
        memoryStream = New MemoryStream()
        buf2 = New [Byte](18) {}
        buf3 = New [Byte](7) {}
        buf2(0) = 33
        'extension introducer
        buf2(1) = 255
        'application extension
        buf2(2) = 11
        'size of block
        buf2(3) = 78
        'N
        buf2(4) = 69
        'E
        buf2(5) = 84
        'T
        buf2(6) = 83
        'S
        buf2(7) = 67
        'C
        buf2(8) = 65
        'A
        buf2(9) = 80
        'P
        buf2(10) = 69
        'E
        buf2(11) = 50
        '2
        buf2(12) = 46
        '.
        buf2(13) = 48
        '0
        buf2(14) = 3
        'Size of block
        buf2(15) = 1
        '
        buf2(16) = 0
        '
        buf2(17) = 0
        '
        buf2(18) = 0
        'Block terminator
        buf3(0) = 33
        'Extension introducer
        buf3(1) = 249
        'Graphic control extension
        buf3(2) = 4
        'Size of block
        buf3(3) = 9
        'Flags: reserved, disposal method, user input, transparent color
        buf3(4) = 10 ' 88 
        If ckSlide.Checked = True Then
            'Delay time low byte
            buf3(5) = 1
            'Delay time high byte
            buf3(6) = 0
        Else
            'Delay time low byte
            buf3(5) = 0 '1 
            'Delay time high byte
            buf3(6) = 255
        End If

        'Transparent color index
        buf3(7) = 0
        'Block terminator

        NewName = GetNewName1()
        lbOutput.Text = NewName
        binaryWriter = New BinaryWriter(File.Open(NewName, FileMode.Create))

        For picCount As Integer = 0 To ImageArray.Count - 1 'stringCollection.Count - 1

            Select Case But
                Case 1
                    'Animate
                    image = Bitmap.FromFile(ImageArray(picCount))
                    If ckDark.Checked = True Then image = Dark(image)
                    If rbSepiaTone.Checked = True Then image = Sepia(image)
                    If rbGrayScale.Checked = True Then image = Grayscale(image)
                    If ckGhost.Checked = True Then Ghost(image)
                    If ckFlip.Checked = True Then image.RotateFlip(RotateFlipType.RotateNoneFlipX)
                Case 2
                    If MemPic IsNot Nothing Then
                        image = MemPic(picCount)
                        If ckDark.Checked = True Then image = Dark(image)
                        If rbSepiaTone.Checked = True Then image = Sepia(image)
                        If rbGrayScale.Checked = True Then image = Grayscale(image)
                        If ckGhost.Checked = True Then Ghost(image)
                        If ckFlip.Checked = True Then image.RotateFlip(RotateFlipType.RotateNoneFlipX)
                    Else
                        MessageBox.Show("Please Select Something")
                    End If

            End Select
            image.Save(memoryStream, ImageFormat.Gif)
            buf1 = memoryStream.ToArray()

            If picCount = 0 Then
                'only write these the first time....
                binaryWriter.Write(buf1, 0, 781)
                'Header & global color table
                'Application extension
                binaryWriter.Write(buf2, 0, 19)
            End If
            binaryWriter.Write(buf3, 0, 8)
            'Graphic extension
            binaryWriter.Write(buf1, 781, buf1.Length - 782)
            'Image data
            ' If picCount = stringCollection.Count - 1 Then
            If picCount = ImageArray.Count - 1 Then
                'only write this one the last time....
                'Image terminator
                binaryWriter.Write(";")
            End If


            memoryStream.SetLength(0)
            Progress.Value = 100 * picCount / ImageArray.Count
        Next

        binaryWriter.Close()
        pbSelect.Invalidate()
        memoryStream.Close()
        Me.Cursor = Cursors.Default
        pbSelect.Image = image.FromFile(ImageArray(N))
        pbSelect.Refresh()
        Progress.Value = 0
    End Sub