Ejemplo n.º 1
0
 public void AddFrame(byte T, GifCubeSlice slice)
 {
     slices[T] = slice;
 }
Ejemplo n.º 2
0
        public void Save(string filename)
        {
            AnimatedGifEncoder e = new AnimatedGifEncoder();

            e.Start(filename);
            e.SetDelay(200);
            //-1:no repeat,0:always repeat
            e.SetRepeat(0);

            int lastFrame = 15;

            // find the last interesting frame
            while (lastFrame > 0)
            {
                GifCubeSlice slice = slices[lastFrame];
                if (slice != null)
                {
                    break;
                }
                lastFrame--;
            }

            for (int frame = 0; frame <= lastFrame; frame++)
            {
                GifCubeSlice slice = slices[frame];

                Bitmap       bmp          = new Bitmap(16, 16, PixelFormat.Format8bppIndexed);
                ColorPalette colorPalette = bmp.Palette;
                Rectangle    rect         = new Rectangle(0, 0, bmp.Width, bmp.Height);
                BitmapData   bmpData      = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat);

                // Declare an array to hold the bytes of the bitmap.
                int    numBytes  = Math.Abs(bmpData.Stride) * bmp.Height;
                byte[] rgbValues = new byte[numBytes];
                byte   Idx       = 0;
                for (int Y = 0; Y < 16; Y++)
                {
                    for (int X = 0; X < 16; X++)
                    {
                        ColorRGB col;
                        if (slice != null)
                        {
                            col = slices[frame][X, Y];
                        }
                        else
                        {
                            col = ColorRGB.Black;
                        }

                        colorPalette.Entries[Idx] = Color.FromArgb(col.R, col.G, col.B);
                        rgbValues[Idx]            = Idx;
                        Idx++;
                    }
                }

                // Copy the RGB values back to the bitmap
                System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, bmpData.Scan0, numBytes);

                // Unlock the bits.
                bmp.UnlockBits(bmpData);

                bmp.Palette = colorPalette;
                e.AddFrame(bmp);// Image.FromFile(imageFilePaths[i]));
            }
            e.Finish();


            //@"C:\Users\Laurie\Pictures\fillpinkOUT.gif"
            //bmp.Save(filename, ImageFormat.Gif);
        }