简体   繁体   English

如何恢复图片框图像的gif winforms C#

[英]How to resume picturebox image's gif winforms C#

When a specific condition is met I disable my picturebox and the image freeze's, whenever it runs again the gif starts all over again not from where it was stopped is there anyway to resume it ? 当满足特定条件时,我禁用了我的图片框,并且图像冻结了,每当它再次运行时,gif都会再次从头开始,而不是从停止的位置开始,是否可以继续它?

Stopping picturebox : http://prntscr.com/b6gg7a "Resuming" picturebox : http://prntscr.com/b6gglb 正在停止图片框: http : //prntscr.com/b6gg7a “正在恢复”图片框: http : //prntscr.com/b6gglb

I believe indeed this is a rather tedious/unlikely to perform with an animated gif. 我相信使用动画gif来执行确实很乏味/不太可能。

What you could/should do IMO is the following: IMO您可以/应该做的事情如下:

Instead of making the background a gif, break it into multiple frames(pictures). 不要将背景制成gif,而是将其分成多个帧(图片)。 Set up a timer that triggers the background to change to the next image. 设置一个计时器,以触发背景更改为下一张图像。 You can pause and resume that timer the same as you would enable and disable the picturebox. 您可以像启用和禁用图片框一样暂停和恢复该计时器。

Your background change function could look something like this: 您的背景更改功能可能如下所示:

int bgCount = 8; //Amount of frames your background uses
int bgCurrent = 0;
string[] bgImg = {
    "bg1.png",
    "bg2.png",
    "bg3.png",
    "bg4.png",
    "bg5.png",
    "bg6.png",
    "bg7.png",
    "bg8.png",
};
        void changeBG()
{
    if(bgCurrent > bgCount-1) //If not displaying the last background image go to the next one
    {
        bgCurrent++;
        imgBox.image = bgImg[bgCurrent];
    }else //If displaying the last background image -> Start with the first one
    {
        bgCurrent = 0;
        imgBox.image = bgImg[bgCurrent];
    }
}
}

And you just let the timer trigger this event. 您只需要让计时器触发此事件即可。 And you simply start and stop the timer. 您只需启动和停止计时器。

Sidenote: 边注:

1* You might experiment with, instead of changing the source, just make 8 imageboxed and call/display them as they are needed. 1 *您可以尝试,而不是更改来源,只需制作8个图像框并根据需要调用/显示它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM