如何在C#中显示GIF图像的特定帧?
我想显示一个gif图像的框架。 我搜索并发现以下代码应该可以工作,但它不起作用。 它正确检测帧数,但它显示的是整个gif帧而不是指定的帧。 谢谢大家。
Image[] frames = new Image[36]; Image GG = Image.FromFile(@"C:UsersAdministratorTEST C#TEST2frame2chef.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(),然后更改为以下行:
frames[0] = new Bitmap(GG); pictureBox1.Image = frame[0];
这应该可以解决问题。 请不要忘记处理创建的图像。
哦,它的确有效,但并不像你期望的那样。
当您设置gif图像的活动帧时,它实际上会从该帧重新启动其动画。 例如,通过将pictureBox.IsEnabled
设置为false,您必须在更改帧时停止它。 请尝试以下代码
private Image img; public Form1() { InitializeComponent(); img = Image.FromFile(@"C:UsersAdministratorTEST C#TEST2frame2chef.gif"); pictureBox1.Image = img; } private void button1_Click(object sender, EventArgs e) { var dim = new FrameDimension(img.FrameDimensionsList[0]); img.SelectActiveFrame(dim, 1); pictureBox1.Enabled = false; }
尝试在不同时刻按下按钮,您将看到活动图像框架将发生变化。
上述就是C#学习教程:如何在C#中显示GIF图像的特定帧?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ctvol.com/cdevelopment/941940.html