문제

애니메이션 GIF를 .NET의 구성 요소 부품으로 어떻게 분할합니까?

구체적으로 메모리에서 이미지 (System.Drawing.Image)에로드하고 싶습니다.

======================

Slaks의 답변을 바탕으로 나는 이것을 가지고 있습니다

public static IEnumerable<Bitmap> GetImages(Stream stream)
{
    using (var gifImage = Image.FromStream(stream))
    {
        //gets the GUID
        var dimension = new FrameDimension(gifImage.FrameDimensionsList[0]);
        //total frames in the animation
        var frameCount = gifImage.GetFrameCount(dimension); 
        for (var index = 0; index < frameCount; index++)
        {
            //find the frame
            gifImage.SelectActiveFrame(dimension, index);
            //return a copy of it
            yield return (Bitmap) gifImage.Clone();
        }
    }
}
도움이 되었습니까?

해결책

사용 SelectActiveFrame 메소드 an의 활성 프레임을 선택하는 방법 Image 애니메이션 GIF를 보유하는 인스턴스. 예를 들어:

image.SelectActiveFrame(FrameDimension.Time, frameIndex);

프레임 수를 얻으려면 전화하십시오 GetFrameCount(FrameDimension.Time)

애니메이션을 재생하려면 사진 상자에 넣거나 사용할 수 있습니다. ImageAnimator 수업.

다른 팁

// 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;
}

반 관련, WPF에는 이미지의 모든 프레임을 제공하는 Bitmapdecoders가 있습니다.

보다 bitmapdecoder.create 그리고 bitmapdecoder.frames.

Image img = Image.FromFile(@"D:\images\zebra.gif");
//retrieving 1st frame
 img.SelectActiveFrame(new FrameDimension(img.FrameDimensionsList[0]), 1);
 pictureBox1.Image = new Bitmap(img);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top