如何在C#中显示GIF图像的特定帧? [英] How to show a specific frame of a GIF image in C#?

查看:181
本文介绍了如何在C#中显示GIF图像的特定帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个gif图像的框架.我搜索后发现以下代码应该起作用,但是它不起作用.它可以正确检测帧数,但会显示gif的整个帧,而不是指定的帧.谢谢大家.

I want to show a frame of a gif image. I searched and found that the following code should work, but it doesn't work. it detects the number of frames correctly but it shows the whole frames of gif instead of the specified frame. thanks everybody.

Image[] frames = new Image[36];
Image GG = Image.FromFile(@"C:\Users\Administrator\TEST C#\TEST2frame2\chef.gif");
FrameDimension dimension = new FrameDimension(GG.FrameDimensionsList[0]);
            // Number of frames
int frameCount = GG.GetFrameCount(dimension);
label1.Text = frameCount.ToString();

            // Return an Image at a certain index
GG.SelectActiveFrame(dimension, 1);
frames[1] = ((Image)GG.Clone());
pictureBox1.Image = frames[1];

推荐答案

在调用SelectActiveFrame()之前使用您自己的代码,然后更改为以下行:

Use your own code up until the call of SelectActiveFrame() and after that change to this lines:

frames[0] = new Bitmap(GG);
pictureBox1.Image = frame[0];

这应该可以解决问题.请不要忘记处理创建的图像.

This should do the trick. Please do not forget do dispose the created Images.

这篇关于如何在C#中显示GIF图像的特定帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆