加载动画
easyx库本身并没有给出gif的加载函数,所以我们需要通过另一种方式实现gif的“播放”
通过将gif图提取出相应关键帧,然后对关键帧进行逐帧播放
以下是代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <graphics.h> #include <conio.h> #include <stdio.h> #include <iostream>
IMAGE images[92]; bool isLoaded = 0; void loadImg() { wchar_t filename[20]; for (int i = 0; i < 92; i++) { wsprintf(filename, _T("../gif/%d.png"), i + 1); loadimage(&images[i], filename, 1080, 810); } }
void loading() { std::cout << "窗口初始化中..." << std::endl; if (!isLoaded) { isLoaded = 1; loadImg(); } HWND hwnd = initgraph(1080, 810); MoveWindow(hwnd, 380, 200, 1096, 849, false); BeginBatchDraw();
for (int i = 0; i < 92; i++) { cleardevice(); putimage(0, 0, &images[i]); FlushBatchDraw(); Sleep(25); } EndBatchDraw(); std::cout << "窗口初始化完毕" << std::endl; }
|
辅助函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <codecvt> #include <comutil.h> #include <string> #pragma comment(lib, "comsuppw.lib") #define _MIN(x,y) (((x)<(y))?(x):(y))
std::string wstringTostring(const std::wstring& ws) { _bstr_t t = ws.c_str(); char* pchar = (char*)t; std::string result = pchar; return result; }
std::wstring stringTowstring(const std::string& s) { _bstr_t t = s.c_str(); wchar_t* pwchar = (wchar_t*)t; std::wstring result = pwchar; return result; }
|