如何在C#中显示指定的gif框架? [英] How to show a specified frame of gif in C#?

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

问题描述

大家好

我想要显示一个gif图像的框架。我搜索并发现以下代码应该可以工作,但它不起作用。它正确检测帧数,但它显示的是gif的整个帧而不是指定的帧。我很感激任何意见。

谢谢大家。



Hi everybody
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. I am grateful of any opinion.
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];

推荐答案

你的代码看起来很奇怪。试试这里: C#从GIF获取帧 [ ^ ],它是工作肯定。
Your code looks strange. Try the one here: C# Get Frames from a GIF[^], it is working for sure.


我的问题已在以下链接中解决。

http://stackoverflow.com/questions/27874353/how-to-show-a-gif-frame [ ^ ]

Zoltan Zorgo,I我很感激你。
My problem has been solved in the below link.
http://stackoverflow.com/questions/27874353/how-to-show-a-gif-frame[^]
Zoltan Zorgo, I am grateful to you.


嗨亲爱的Zoltan Zorgo

我做了你说的话,并将我的代码改为下面。但问题仍然存在。

我期待着你。谢谢。



Hi Dear Zoltan Zorgo
I did what you said and changed my code to below. But the problem remains as before.
I am looking forward from you. Thank you.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TEST2frame2
{


    public partial class Form1 : Form
    {

        Image[] getFrames(Image originalImg)
        {

            int numberOfFrames = originalImg.GetFrameCount(FrameDimension.Time);

            Image[] frames = new Image[numberOfFrames];
            label1.Text = numberOfFrames.ToString();


            for (int i = 0; i < numberOfFrames; i++)
            {

                originalImg.SelectActiveFrame(FrameDimension.Time, i);

                frames[i] = ((Image)originalImg.Clone());

            }



            return frames;

        }

        public Form1()
        {
            InitializeComponent();
            Image[] frame = getFrames(Image.FromFile(@"C:\Users\Administrator\Desktop\Interface\TEST C#\TEST2frame2\chef.gif"));
            pictureBox1.Image = frame[1];

        }


    }
}


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

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