显示动态gif图片
2014-04-15 15:57
387 查看
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资源 //显示gif HDC 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 //利用两个定时器,分别显示多帧的gif BOOL 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; }
相关文章推荐
- c# winform 显示动态gif图片的方法
- 将gif图片,放入ppt,就显示动态效果了吗?
- c# winform 显示动态gif图片的方法
- java实现gif动画效果(java显示动态图片)
- gif动态图片显示
- Label,PushButton,ToolButton 实现动态图片按钮,Label显示gif动画
- Android 显示Gif 动态图片
- QT 显示动态gif图片 (release版)
- java实现gif动画效果(java显示动态图片)
- ios中用三种方式显示gif动态图片
- 实现动态的GIF 图片显示到窗体中
- windows mobile 平台显示GIF动态图片
- Android三步显示gif动态图片
- Java之简单的图片动态显示(实现类似GIF动画结果)
- C/C++实现显示GIF动态图片
- c# winform 显示动态gif图片的方法
- Qt显示动态gif图片
- .C#窗体上怎么显示动态图片如gif
- Android中显示gif动态图片
- QT 显示动态gif图片