How to split an animated gif in .net?

后端 未结 4 1450
眼角桃花
眼角桃花 2020-12-06 14:09

How do you split an animated gif into its component parts in .net?

Specifically I want to load them into Image(s) (System.Drawing.Image) in memory.

=========

4条回答
  •  无人及你
    2020-12-06 14:25

    // Parses individual Bitmap frames from a multi-frame Bitmap into an array of Bitmaps
    
    private Bitmap[] ParseFrames(Bitmap Animation)
    {
        // Get the number of animation frames to copy into a Bitmap array
    
        int Length = Animation.GetFrameCount(FrameDimension.Time);
    
        // Allocate a Bitmap array to hold individual frames from the animation
    
        Bitmap[] Frames = new Bitmap[Length];
    
        // Copy the animation Bitmap frames into the Bitmap array
    
        for (int Index = 0; Index < Length; Index++)
        {
            // Set the current frame within the animation to be copied into the Bitmap array element
    
            Animation.SelectActiveFrame(FrameDimension.Time, Index);
    
            // Create a new Bitmap element within the Bitmap array in which to copy the next frame
    
            Frames[Index] = new Bitmap(Animation.Size.Width, Animation.Size.Height);
    
            // Copy the current animation frame into the new Bitmap array element
    
            Graphics.FromImage(Frames[Index]).DrawImage(Animation, new Point(0, 0));
        }
    
        // Return the array of Bitmap frames
    
        return Frames;
    }
    

提交回复
热议问题