English 中文(简体)
先进图书馆
原标题:advanced gif library

I m looking for a .NET C# gif animation library (doesn t have to be free) that will allow me to take a gif file and attach it a frame of jpeg or even another gif file. i will also need to be able to add changing delay between the frames. The answer to similar questions here usually reference to a basic library that only allows you to add a fixed delay between static images.

最佳回答

I ended up modifying http://www.codeproject.com/KB/GDI-plus/NGif.aspx code to get what I needed and it worked! :)

添加了这一方法:

        private bool AddGifFrames(Image image)
    {
        // implementation

        var fd = new FrameDimension(image.FrameDimensionsList[0]);
        int frameCount = image.GetFrameCount(fd);

        var frames = new List<Tuple<int, Image>>();

        if (frameCount > 1)
        {
            frames = new List<Tuple<int, Image>>();

            //0x5100 is the property id of the GIF frame s durations
            //this property does not exist when frameCount <= 1
            byte[] times = image.GetPropertyItem(0x5100).Value;

            for (int i = 0; i < frameCount; i++)
            {
                //selects GIF frame based on FrameDimension and frameIndex
                image.SelectActiveFrame(fd, i);

                //length in milliseconds of display duration
                int length = BitConverter.ToInt32(times, 4 * i);

                //save currect image frame as new bitmap
                frames.Add(new Tuple<int, Image>(length, new Bitmap(image)));
            }
        } // Not animated

        foreach (var frame in frames)
        {
            HandleFrame(frame.Item2, frame.Item1);
        }

        return true;
    }

and as for the custom delays I ve modified this method:

        protected void WriteGraphicCtrlExt(int? delay)
    {
        Fs.WriteByte(0x21); // extension introducer
        Fs.WriteByte(0xf9); // GCE label
        Fs.WriteByte(4); // data block size
        int transp, disp;
        if (Transparent == Color.Empty)
        {
            transp = 0;
            disp = 0; // dispose = no action
        }
        else
        {
            transp = 1;
            disp = 2; // force clear if using transparent color
        }
        if (Dispose >= 0)
        {
            disp = Dispose & 7; // user override
        }
        disp <<= 2;

        // packed fields
        Fs.WriteByte(Convert.ToByte(0 | // 1:3 reserved
                                    disp | // 4:6 disposal
                                    0 | // 7   user input - 0 = none
                                    transp)); // 8   transparency flag

        WriteShort(delay ?? Delay); // delay x 1/100 sec
        Fs.WriteByte(Convert.ToByte(TransIndex)); // transparent color index
        Fs.WriteByte(0); // block terminator
    }

概括地说,这部法典可以通过将它分为框架和增加框架而增加一个框架,还可以增加习俗上的拖延。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签