0

I have two animated gifs i created. I want to add them to a new bitmap side by side so i will see both animated gifs animation. Not as stil image but two animation side by side.

This code is in the top of form1 im using now:

public static class BitmapExtensions
    {
        public static Bitmap DoubleBitmap(this Bitmap bm)
        {
            Bitmap bitmap = new Bitmap(bm.Width * 2, bm.Height);
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(bm, Point.Empty);
                g.DrawImage(bm, new Point(bm.Width, 0));
                return bitmap;
            }
        }
        public static Bitmap AppendBitmap(this Bitmap bm, Bitmap rightBitmap)
        {
            Bitmap bitmap = new Bitmap(bm.Width + rightBitmap.Width, Math.Max(bm.Height, rightBitmap.Height));
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.DrawImage(bm, Point.Empty);
                g.DrawImage(rightBitmap, new Point(bm.Width, 0));
                return bitmap;
            }
        }
    }

Then i use it like this:

private void CreateNewImage(string DirOfUrls)
        {
            List<string> files = Directory.GetFiles(DirOfUrls, "RainImage*.*").ToList();
            List<string> files1 = Directory.GetFiles(DirOfUrls, "SatelliteImage*.*").ToList();

                Bitmap bmp = new Bitmap(@"d:\localpath\RainMapGif");//files1[i]);
                Bitmap bmp1 = new Bitmap(@"d:\localpath\SatelliteMapGif");//files[i]);
                //Use it
                //Double the same image
                Bitmap doubledBitmap =  bmp1.DoubleBitmap();
                //Append new image
                Bitmap appendedBitmap = bmp1.AppendBitmap(bmp);
                appendedBitmap.Save(@"d:\localpath\newbitmapGif", System.Drawing.Imaging.ImageFormat.Gif);
        }

RainMapGif and SatelliteMapGif are animated gif's. But when i tried to do it this way i get one new bitmap with two stills images and not two animtions of the two animated gifs.

How can i add both animated gifs to one bitmap and when i open the bitmap on internet explorer for example i will see both animations moving of the two gifs side by side ?

EDIT**

This is how i used it before :

private void CreateNewImage(string DirOfUrls)
        {
            int newImageCounter = 0;
            List<string> files = Directory.GetFiles(DirOfUrls, "RainImage*.*").ToList();
            List<string> files1 = Directory.GetFiles(DirOfUrls, "SatelliteImage*.*").ToList();
            for (int i = 0; i < files.Count; i++)
            {
                if (newImageCounter == 9)
                {
                    CreateNewGif(DirOfUrls);
                    //break;
                }
                Bitmap bmp = new Bitmap(files1[i]);
                Bitmap bmp1 = new Bitmap(files[i]);
                //Use it
                //Double the same image
                Bitmap doubledBitmap =  bmp1.DoubleBitmap();
                //Append new image
                Bitmap appendedBitmap = bmp1.AppendBitmap(bmp);
                appendedBitmap.Save(@"d:\localpath\newbitmap" + newImageCounter.ToString("D6"), System.Drawing.Imaging.ImageFormat.Gif);
                newImageCounter++;
            }

So i have 9 images of both of them the RainMap images and the SatelliteMap images. And the rest of the SatelliteMap images are singles.

Then im using CreateNewGif:

private void CreateNewGif(string urlsdirs)
        {
            List<string> files = Directory.GetFiles(urlsdirs, "RainImage*.*").ToList();
            List<string> files1 = Directory.GetFiles(urlsdirs, "SatelliteImage*.*").ToList();
            List<string> test = files;
            test.RemoveRange(0, files1.Count);
            List<string> newbitmap = Directory.GetFiles(localdir, "newbitmap*.*").ToList();
            for (int i = 0; i < test.Count; i++)
            {
                newbitmap.Add(test[i]);

            }
            uf.MakeGIF(newbitmap, localdir + "newbitmapGif", 50, true);
        }

And make new animated gif:

uf.MakeGIF(newbitmap, localdir + "newbitmapGif", 50, true);

But the new animated gif is not good since the rain images ending before the satellite images so the new animated gif show both animation and after 9 frames only one is continue.

How can i make that the one with the 9 images will keep continue animated over and over again and the second one will keep animated untill the end ?

This is the problem veljkoz wrote about before. One animation count is shorter then the other one. But how can i solve it ?

user2760148
  • 427
  • 2
  • 9
  • 19
  • 3
    Rather than combining the two images, why not just display them side by side? –  Sep 19 '13 at 07:19
  • Mike W display them on Form1 ? The idea was to create a bitmap/image with the two animations so i can later upload the bitmap with the two animations to a forum. – user2760148 Sep 19 '13 at 07:31

1 Answers1

0

Only gif can have animation. Bitmap doesn't and never will.

Furthermore, there's the issue of extracting all of the gif slides (see this answer), putting them side by side in another gif (see this answer), and deciding what will you do if the slide count isn't a match (which would most probably be the case).

Personally, I would go with what @Mike W is suggesting in the comment...

Edit: You have to have in mind that the resulting gif will have a single number of frames after which it repeats itself. So, both gifs you're trying to add have to somehow fit there. There's only a few options here:

  • Repeat inserting all frames of both gifs until they reach at the end at the same time (e.g. if one has 6 frames and the other 9 - the result will have 18 frames. The the first one would repeat itself 3 times, the other 2). This is (obviously) prolonging the length & size of the gif, which is probably not something you want, but it would give you best results. When the numbers are prime numbers you'd get the worst count - e.g. 53 & 59 frame gifs when joined will last for 3127 frames.

  • Change the timing of the frames so they end at the same time. This would of course speed-up / slow down parts of the gifs. (e.g. 6&9 frames gifs: the result has 9 slides - you could repeat the first 3 slides of 1st gif to last two frames - which means 1st slide will last 2 frames (#1 & #2), second one also (#3 & #4) as well as third (#5 & #6). Then copy the rest of the slides - frame 4 displayed at #7, 5->#8, 6->#9 and that's the end).

  • Remove some of the slides - shorten the gifs by removing some of the slides so the count matches...

Community
  • 1
  • 1
veljkoz
  • 8,384
  • 8
  • 55
  • 91
  • What does Mike mean by display them side by side ? He mean on a Form ? – user2760148 Sep 19 '13 at 07:28
  • veljkoz i did what you suggest before and i got one bitmap with the two animations the problem is as you wrote one ofthe animation count is smaller then the other one so after some frames the second animation is gone and when the first one end they both start over again. Then what should i do with the shortest count animation ? How can i make that it will keep animated over and over again ? – user2760148 Sep 19 '13 at 07:30
  • Updated my question please look at it. – user2760148 Sep 19 '13 at 07:37