How to show a specific frame of a GIF image in C#?

前端 未结 2 1361
清酒与你
清酒与你 2021-01-14 07:57

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

2条回答
  •  被撕碎了的回忆
    2021-01-14 08:06

    Oh it works, but not as you expect it to.

    When you set an active frame of a gif image it actually restarts its animation from that frame. You have to stop it when you change a frame, by setting the pictureBox.IsEnabled to false, for instance. Try the following code

    private Image img;
    
    public Form1()
    {
        InitializeComponent();
        img = Image.FromFile(@"C:\Users\Administrator\TEST C#\TEST2frame2\chef.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;
    }
    

    Try pressing the button in different moments and you will see that the active image frame will change.

提交回复
热议问题