Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

C#
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];
Posted
Comments
Zoltán Zörgő 11-Jan-15 6:49am    
Any news? It is working for me. Please remove your question from the answers (I know there is an issue on CP).

Your code looks strange. Try the one here: C# Get Frames from a GIF[^], it is working for sure.
 
Share this answer
 
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.
 
Share this answer
 
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.

C#
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];

        }


    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900