簡體   English   中英

如何恢復圖片框圖像的gif winforms C#

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

當滿足特定條件時,我禁用了我的圖片框,並且圖像凍結了,每當它再次運行時,gif都會再次從頭開始,而不是從停止的位置開始,是否可以繼續它?

正在停止圖片框: http : //prntscr.com/b6gg7a “正在恢復”圖片框: http : //prntscr.com/b6gglb

我相信使用動畫gif來執行確實很乏味/不太可能。

IMO您可以/應該做的事情如下:

不要將背景制成gif,而是將其分成多個幀(圖片)。 設置一個計時器,以觸發背景更改為下一張圖像。 您可以像啟用和禁用圖片框一樣暫停和恢復該計時器。

您的背景更改功能可能如下所示:

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];
    }
}
}

您只需要讓計時器觸發此事件即可。 您只需啟動和停止計時器。

邊注:

1 *您可以嘗試,而不是更改來源,只需制作8個圖像框並根據需要調用/顯示它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM