显示动态gif图片
来源:互联网 发布:影楼修图用什么软件 编辑:程序博客网 时间:2024/06/02 16:19
DWORD WINAPI GifThread(LPVOID lpParam){//查找资源,加载资源到内存,锁定资源HRSRC hRsrc = FindResourceW(hInst, MAKEINTRESOURCEW(IDR_GIF), L"GIF");HGLOBAL hGlobal = LoadResource(hInst, hRsrc);LPVOID lpResData = LockResource(hGlobal);DWORD dwResSize = SizeofResource(hInst, hRsrc);//获得系统环境路径WCHAR szResPath[MAX_PATH] = L"\0";GetEnvironmentVariableW(L"TEMP", szResPath, sizeof(szResPath));wcscat(szResPath, L"\\hhhhgif.gif");//建立flash资源文件HANDLE hFile = CreateFileW(szResPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL);if (hFile != INVALID_HANDLE_VALUE){DWORD dwWritten;WriteFile(hFile, lpResData, dwResSize, &dwWritten, NULL);}CloseHandle(hFile);FreeResource (hGlobal); //释放flash资源//显示gifHDC hdc = GetDC(g_hwnd);Image *image = new Image(szResPath);if (image == NULL){return -1;}UINT count = 0;count = image->GetFrameDimensionsCount();GUID *pDimensionIDs = (GUID*)new GUID[count];image->GetFrameDimensionsList(pDimensionIDs, count);WCHAR strGuid[39];StringFromGUID2(pDimensionIDs[0], strGuid, 39);UINT frameCount = image->GetFrameCount(&pDimensionIDs[0]);delete []pDimensionIDs;int size = image->GetPropertyItemSize(PropertyTagFrameDelay);PropertyItem *pItem = NULL;pItem = (PropertyItem*)malloc(size);image->GetPropertyItem(PropertyTagFrameDelay,size,pItem);UINT fcount=0;GUID Guid = FrameDimensionTime;while (g_gif){Graphics graphics(hdc);graphics.DrawImage(image, 50, 120, 400, 200);image->SelectActiveFrame(&Guid, fcount++);if (fcount == frameCount)fcount=0;long lPause = ((long*)pItem->value)[fcount]*10;Sleep(lPause);}ReleaseDC(g_hwnd, hdc);return 0;}
#define TIMER_FIR 1#define TIMER_SEC 2//利用两个定时器,分别显示多帧的gifBOOL CALLBACK GifDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){PAINTSTRUCT ps;HDC hdc;HBRUSH hBrush, hOldbrush;RECT rect;static Image *image;static UINT count;static WCHAR strGuid[39];static UINT frameCount;static PropertyItem* pItem=NULL;static UINT fcount;static GUID Guid;static long lPause;static int size;static GUID *pDimensionIDs;//gdi+用到的两个变量GdiplusStartupInput m_gdiplusStartupInput;static ULONG_PTR m_pGdiToken;static WCHAR szResPath[MAX_PATH] = L"\0";switch (message){case WM_INITDIALOG:{//装载gdi+GdiplusStartup(&m_pGdiToken, &m_gdiplusStartupInput, NULL);//查找资源,加载资源到内存,锁定资源HRSRC hRsrc = FindResourceW(hInst, MAKEINTRESOURCEW(IDR_GIF), L"GIF");HGLOBAL hGlobal = LoadResource(hInst, hRsrc);LPVOID lpResData = LockResource(hGlobal);DWORD dwResSize = SizeofResource(hInst, hRsrc);//获得系统环境路径GetEnvironmentVariableW(L"TEMP", szResPath, sizeof(szResPath));wcscat(szResPath, L"\\hhhhgif.gif");//建立flash资源文件HANDLE hFile = CreateFileW(szResPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL);if (hFile != INVALID_HANDLE_VALUE){DWORD dwWritten;WriteFile(hFile, lpResData, dwResSize, &dwWritten, NULL);}CloseHandle(hFile);FreeResource (hGlobal); //释放flash资源SetTimer(hDlg,TIMER_FIR,0,NULL);}break;case WM_TIMER:{switch(wParam){case TIMER_FIR:{hdc=GetDC(hDlg);image=new Image(szResPath);count=0;count=image->GetFrameDimensionsCount();pDimensionIDs=(GUID*)new GUID[count];image->GetFrameDimensionsList(pDimensionIDs,count);StringFromGUID2(pDimensionIDs[0],strGuid,39);frameCount=image->GetFrameCount(&pDimensionIDs[0]);delete []pDimensionIDs;size=image->GetPropertyItemSize(PropertyTagFrameDelay);//PropertyItem* pItem=NULL;// pItem=(PropertyItem*)malloc(size);pItem=(PropertyItem*)new PropertyItem[size];image->GetPropertyItem(PropertyTagFrameDelay,size,pItem);fcount=0;Guid=FrameDimensionTime;Graphics graphics(hdc);graphics.DrawImage(image,0,0);image->SelectActiveFrame(&Guid,fcount++);if(fcount==frameCount)fcount=0;lPause=((long*)pItem->value)[fcount]*10;ReleaseDC(hDlg,hdc);KillTimer (hDlg, TIMER_FIR) ;SetTimer(hDlg,TIMER_SEC,lPause,NULL);InvalidateRect (hDlg, NULL, FALSE) ;break;}case TIMER_SEC:{image->SelectActiveFrame(&Guid,fcount++);if(fcount==frameCount)fcount=0;lPause=((long*)pItem->value)[fcount]*10;KillTimer(hDlg,TIMER_SEC);SetTimer(hDlg,TIMER_SEC,lPause,NULL);InvalidateRect (hDlg, NULL, FALSE) ;}}}break; case WM_PAINT:{hdc = BeginPaint(hDlg, &ps);// TODO: 在此添加任意绘图代码...//hBrush = CreateSolidBrush(RGB(68,68,68)); //创建新画刷//GetClientRect(hDlg, &rect); //获得主窗口的面积//hOldbrush = (HBRUSH)SelectObject(hdc, hBrush); //把画刷选入设备//Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);//FrameRect(hdc, &rect, hBrush); //重画窗口边框//SelectObject(hdc, hOldbrush); //把旧画刷选入设备Graphics graphics(hdc);graphics.DrawImage(image,0,0);EndPaint(hDlg, &ps);}break;}return FALSE;}
0 0
- gif动态图片显示
- 动态显示图片gif
- 显示动态gif图片
- Android 显示Gif 动态图片
- Qt显示动态gif图片
- windows mobile 平台显示GIF动态图片
- form中显示GIF动态图片
- Android中动态显示gif图片
- Android中显示gif动态图片
- Android三步显示gif动态图片
- Android三步显示gif动态图片
- Android中显示gif动态图片
- 【VBA研究】显示GIF动态图片
- C/C++实现显示GIF动态图片
- 在MFC中用GDI+显示动态GIF图片
- 实现动态的GIF 图片显示到窗体中
- 动态gif图片在html中显示拖影
- ios中用三种方式显示gif动态图片
- 《Java解惑》系列——01表达式之谜——谜题03:长整除
- 单元测试
- Document(文档)、View(视图)、Frame(框架)、App(应用)之间相互访问
- 压缩
- swing皮肤substance的应用
- 显示动态gif图片
- Win2003系统时间同步间隔的设置
- 清明
- 工作经验(Ashx)= 1
- Java方法继承、方法重载、方法覆盖小总结
- 软考复习之路——编译原理
- gcc 链接库的时候 位置 出错
- oracle中查询一个日期的24个小时
- Free Pascal (Lazarus)版Android NDK的应用示例之:常用数据类型的转换