none
How could i create an animated .gif file from several other .jpg files in c# express?

    Question

  • How could i create an animated .gif file from several other .jpg files in c# express?



    I am very new to programing so please excuse my lack of knowledge.
    Sunday, January 17, 2010 1:10 PM

Answers

  • Here is basic code to combine image files into an animated GIF.  You'll need the GIF specification, which can be found many places on the web.

        private byte[] GifAnimation = {33, 255, 11, 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48, 3, 1, 0, 0, 0};
        
    private byte[] Delay = {255, 0};
        
    private void button1_Click(object sender, EventArgs e)
        {
          
    string JpegFolder = "C:\\Users\\Public\\Pictures\\Sample Pictures";
          
    string GifFile = "C:\\Users\\Public\\Pictures\\MultiFrame.gif";
          
    string[] Files = Directory.GetFiles(JpegFolder, "*.jpg");
          
    MemoryStream MS = new MemoryStream();
          
    BinaryReader BR = new BinaryReader(MS);
          
    BinaryWriter BW = new BinaryWriter(new FileStream(GifFile, FileMode.Create));
          
    Image.FromFile(Files[0]).Save(MS, ImageFormat.Gif);
          
    byte[] B = MS.ToArray();
          B[10] = (
    byte)(B[10] & 0X78); //No global color table.
          BW.Write(B, 0, 13);
          BW.Write(GifAnimation);
          WriteGifImg(B, BW);
          
    for (int I = 1; I < Files.Length; I++)
          {
            MS.SetLength(0);
            
    Image.FromFile(Files[I]).Save(MS, ImageFormat.Gif);
            B = MS.ToArray();
            WriteGifImg(B, BW);
          }
          BW.Write(B[B.Length - 1]);
          BW.Close();
          MS.Dispose();
        }
        
    public void WriteGifImg(byte[] B, BinaryWriter BW)
        {
          B[785] = Delay[0]; 
    //5 secs delay
          B[786] = Delay[1];
          B[798] = (
    byte)(B[798] | 0X87);
          BW.Write(B, 781, 18);
          BW.Write(B, 13, 768);
          BW.Write(B, 799, B.Length - 800);
        }

    • Marked as answer by Bin-ze Zhao Monday, January 25, 2010 2:24 AM
    • Edited by JohnWein Monday, January 25, 2010 1:21 PM
    Saturday, January 23, 2010 10:10 PM

All replies

  • Hi,

    You have a good approach in this article : http://bloggingabout.net/blogs/rick/archive/2005/05/10/3830.aspx

    Hope this helps,

    Mathieu
    Mathieu Francesch Sharplog Engineering
    Sunday, January 17, 2010 1:17 PM
  • How could i create an animated .gif file from several other .jpg files in c# express?



    I am very new to programing so please excuse my lack of knowledge.
    you have to use, the control timer...to do that....



    Just Be Humble Malange!
    Sunday, January 17, 2010 2:15 PM
  • Add them frame by frame to a gif file using the GifBitmapEncoder.
    Sunday, January 17, 2010 3:40 PM
  • if your new to prgramming then this will probably be difficult for you.

    Plus there is a open source program called unfreeze written in C++, you could look at that for some ideas
    http://code.google.com/p/notepadenhanced/downloads/list
    Sunday, January 17, 2010 6:47 PM
  • HI sorry about delay in responding

    i have been playing with that code but cant get it to work and it seams that knowone else can ether!
    any other suggestions?

    I am very new to programing so please excuse my lack of knowledge.
    Tuesday, January 19, 2010 2:49 PM
  • Add the delays PropertyItem to the Gif produced by the code in this thread:  merging jpg file and produce 1 tiff file http://social.msdn.microsoft.com/Forums/en-IE/winforms/thread/8c5d34e3-f72b-4166-86fa-99d9b606a35d
    Tuesday, January 19, 2010 4:20 PM
  • 1: is a tiff the same as giff?
    2: the code is in vs i think ive only ever used c#

    I am very new to programing so please excuse my lack of knowledge.
    Tuesday, January 19, 2010 7:32 PM
  • Hi,

    Is a tiff the same as giff?
    http://deadline.3x.ro/adsense/graphs.html


     the code is in vs i think ive only ever used c#?

    Download code convertor to do it for you(vb to c#)

    Thanks
    Binze


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, January 21, 2010 3:28 AM
  • How could i create an animated .gif file from several other .jpg files in c# express?
    In the advent that you just want to create a wait type gif which goes around in a circle, such as used by websites. Check out http://www.ajaxload.info/ . From that site you can choose many different styles, depending on the browser you can see it real time; and download an animated gif to use. No costs involved. HTH

    William Wegerson (www.OmegaCoder.Com)
    Thursday, January 21, 2010 4:00 AM
    Moderator
  • Here is basic code to combine image files into an animated GIF.  You'll need the GIF specification, which can be found many places on the web.

        private byte[] GifAnimation = {33, 255, 11, 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48, 3, 1, 0, 0, 0};
        
    private byte[] Delay = {255, 0};
        
    private void button1_Click(object sender, EventArgs e)
        {
          
    string JpegFolder = "C:\\Users\\Public\\Pictures\\Sample Pictures";
          
    string GifFile = "C:\\Users\\Public\\Pictures\\MultiFrame.gif";
          
    string[] Files = Directory.GetFiles(JpegFolder, "*.jpg");
          
    MemoryStream MS = new MemoryStream();
          
    BinaryReader BR = new BinaryReader(MS);
          
    BinaryWriter BW = new BinaryWriter(new FileStream(GifFile, FileMode.Create));
          
    Image.FromFile(Files[0]).Save(MS, ImageFormat.Gif);
          
    byte[] B = MS.ToArray();
          B[10] = (
    byte)(B[10] & 0X78); //No global color table.
          BW.Write(B, 0, 13);
          BW.Write(GifAnimation);
          WriteGifImg(B, BW);
          
    for (int I = 1; I < Files.Length; I++)
          {
            MS.SetLength(0);
            
    Image.FromFile(Files[I]).Save(MS, ImageFormat.Gif);
            B = MS.ToArray();
            WriteGifImg(B, BW);
          }
          BW.Write(B[B.Length - 1]);
          BW.Close();
          MS.Dispose();
        }
        
    public void WriteGifImg(byte[] B, BinaryWriter BW)
        {
          B[785] = Delay[0]; 
    //5 secs delay
          B[786] = Delay[1];
          B[798] = (
    byte)(B[798] | 0X87);
          BW.Write(B, 781, 18);
          BW.Write(B, 13, 768);
          BW.Write(B, 799, B.Length - 800);
        }

    • Marked as answer by Bin-ze Zhao Monday, January 25, 2010 2:24 AM
    • Edited by JohnWein Monday, January 25, 2010 1:21 PM
    Saturday, January 23, 2010 10:10 PM
  •  in the wrong group again, yi gads... guess I need to be more careful :)

    Well the good news is the Multi Image Tiff works fine, the bad news is I
    have only found one program that can display it past the first page.

    The other good news is the one program that does display it can save as a
    Animated Gif (saves a step) so it's a little easier now, the bad news is it
    does not allow me to create on the fly.

    If Explorer could display it then it would not be a problem but Explorer
    wants to use QuickJunk to display it and it only displays the first page.
    Stange because the Windows Fax and Image viewer can display Animated Gif and
    seems to like the first page of the Tif you would think it would display it.

    Well thanks anyway, leaned something new and I now know how to get the list
    of filenames that can be decode, wow!
    Sunday, January 24, 2010 8:43 PM
  •  in the wrong group again, yi gads... guess I need to be more careful :)

    Well the good news is the Multi Image Tiff works fine, the bad news is I
    have only found one program that can display it past the first page.

    The other good news is the one program that does display it can save as a
    Animated Gif (saves a step) so it's a little easier now, the bad news is it
    does not allow me to create on the fly.

    If Explorer could display it then it would not be a problem but Explorer
    wants to use QuickJunk to display it and it only displays the first page.
    Stange because the Windows Fax and Image viewer can display Animated Gif and
    seems to like the first page of the Tif you would think it would display it.

    Well thanks anyway, leaned something new and I now know how to get the list
    of filenames that can be decode, wow!

    I don't understand this post.  Can you explain how this relates to the previous posts in this thread, particularly my last post?
    Sunday, January 24, 2010 9:10 PM
  • sorry i shouldnt have asked the question when im so busy,
    this was the answer for me it works v well i will spend some time inproving on it and making it more user freindley.
    thank you John!


    I am very new to programing so please excuse my lack of knowledge.
    Monday, January 25, 2010 10:03 AM
  • ps in yor first line private   byte{ ] GifAnimation = {33, 255, 11, 78, 69, 84, 83, 67, 65, 80, 69, 50, 46, 48, 3, 1, 0, 0, 0};
    you have typed { insted of [

    just thought i would mention it as its a simple mistake that can bee missed.

    I am very new to programing so please excuse my lack of knowledge.
    Monday, January 25, 2010 11:07 AM