[VB.NET] How to merge many GIF Files into one file

I need to create a software that it merge many GIF File into one file container.

 

My application has this form

I want that when i click "Add File" it shows an OpenFileDialog and that add file's path in the ListBoxAnd when I click "Merge File" It merge all GIF file present in ListBox

And when I click "Split File" it split all GIF File present in a File Container and that It save GIF Files in the same directory of the File Container

I tried to write the code but it change any bytes of the GIF Files when I merge :( and i don't know how to use Split Function in VB.NET

[Off-Topic]I'm new in VB.NET and i don't know fine this new programming language

Best Regards Flash



Answer this question

[VB.NET] How to merge many GIF Files into one file

  • Awais786

    What do you mean with "merge" If you try to create an animated GIF with multiple frames, you're out of luck, .NET can only do this for TIFF files (use Bitmap.SaveAdd).



  • Ben Amor Bassem

    yes i mean directory. ;)

    How do i do to merge many GIF Files into one file in VB.NET


  • Ash8Fee

    That is the way the serialization code marks the type of object that was stored. So it knows that it was a bitmap that was written, and what its type, size, resolution etc was. Why do you care It is just a bunch of binary data anyway...



  • kira2

    You lost me again. Ummm, data that was written with the Serialize() method can only be read with the Deserialize() method. I showed you an example of how to use Deserialize() before...



  • Wyo

    I didn't understand how to call Deserialize

    Can you give me a complete example,please ;)

    Thanks


  • JeffK_

    Ok, next hurdle: "file container". Do you mean directory (aka folder)



  • durnurd

    You mean something like a zip file where you can store many files into one and extract them afterwards

    If so there's a free .NET zip component called SharpZip Lib:

    http://www.icsharpcode.net/OpenSource/SharpZipLib/

    You can use it to create zip files easily.



  • SOAC

    Here's some sample code to get you started. It shows how to put an image in an "archive" and how to get it back out again:

    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim sw As New IO.FileStream("c:\temp\archive.bin", IO.FileMode.Create)
    Dim bmp As New Bitmap("c:\temp\test.bmp")
    Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    fmt.Serialize(sw, bmp)
    sw.Close()
    End Sub

    Private Sub Load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim sr As New IO.FileStream("c:\temp\archive.bin", IO.FileMode.Open)
    Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    Dim bmp As Bitmap = CType(fmt.Deserialize(sr), Bitmap)
    sr.Close()
    PictureBox1.Image = CType(bmp, Image)
    End Sub

    Call the Serialize method for each image you want to save. Call the Deserialize method as long as sr.Position < sr.Length-1. Good luck.



  • Tomorrow Shi

    No i want to create a file container with many GIF.

    I dont' want to create a gif with many frame but i need merge many


  • laja

    But if i have file's path to merge in a ListBox. How do i do

    Imports System.IO

    Public Class Form1

    Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_add.Click

    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

    Dim S() As String = OpenFileDialog1.FileNames 'un array che contiene i nomi dei file scelti

    Dim File As String

    Dim sr As New IO.FileStream(OpenFileDialog1.FileName, IO.FileMode.Open)

    Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter

    For Each File In S

    ListBox1.Items.Add(File)

    Next

    sr.Close()

    End If

    End Sub

    Private Sub btn_create_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_create.Click

    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

    Dim sw As New IO.FileStream(SaveFileDialog1.FileName, IO.FileMode.Create)

    Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter

    sw.Close()

    End If

    End Sub

    End Class


  • Daveskis

    Private Sub btn_create_Click(...
    ...
    Dim sw As New IO.FileStream(SaveFileDialog1.FileName, IO.FileMode.Create)
    Dim fmt As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
    Dim bmp As Bitmap
    For Each item As String In ListBox1.Items
    bmp = CType(Bitmap.FromFile(item), Bitmap)
    fmt.Serialize(sw, bmp)
    Next
    sw.Close()
    End Sub



  • Naveenkm

    I want to create an arhive file but without compressing the gif :)
  • danych

    The code goes fine ^_^ but if i merge GIF File with a HEX Editor i see this string before GIF Merged i can add other lines of code after  For Each ...Next and i read all text and i delete this string:

     ......................QSystem.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a......System.Drawing.Bitmap.....Data.................'...

    How can i do


  • JHarjung

    Thanks!!!!!!!!!!!!!!!!

    But I have another problem, when i merge GIF Files into a file, my software add this text:

    ......................QSystem.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a......System.Drawing.Bitmap.....Data.................'...

    I don't want that this text come added. How do i do


  • [VB.NET] How to merge many GIF Files into one file