MFC GDI + GIF files display "turn"
In the header file which added:
Image* image;
GUID Guid ;
UINT frameCount;
UINT framePos; ULONG_PTR gdiplusToken;
afx_msg void OnTimer(UINT_PTR nIDEvent); void LoadGif();
You need to rely on the header file:
#include <Gdiplusheaders.h>
#include <Gdiplus.h>
using namespace Gdiplus;
Class constructor which added interface:
// start gdi Image :: FromFile else fails
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
image = NULL;
frameCount = 0; framePos = 0;
Add a timer message processing:
BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication1Dlg::OnBnClickedButton1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON2, &CMFCApplication1Dlg::OnBnClickedButton2)
END_MESSAGE_MAP()
Load GIF file:
void CMFCApplication1Dlg::LoadGif()
{
WCHAR strModule[MAX_PATH * 2] = { 0 }; GetModuleFileNameW (NULL, strModule, the MAX_PATH * 2 ); :: PathRemoveFileSpecW (strModule); wsprintfW (strModule + wcslen (strModule), L " \\% s.gif ", L " sVcodec " ); Image = Image :: the FromFile ( strModule); // get the number of dimensions for a dimension to gif COUNT = Image- UINT> GetFrameDimensionsCount (); the GUID of pDimensionIDs = * (* the GUID of) new new the GUID of [COUNT]; Image-> GetFrameDimensionsList (pDimensionIDs, COUNT); strGuid WCHAR [ 39 ]; StringFromGUID2 (pDimensionIDs [ 0], strGuid, 39 ); frameCount = Image-> GetFrameCount (& pDimensionIDs [ 0 ]); // Delete [] pDimensionIDs;// get the time interval between the frames // first obtain the number of time intervals, PropertyTagFrameDelay GIG attribute ID is a predefined value GDI +, showing the delay time of the frame data tag = Image- FrameDelayNums UINT> GetPropertyItemSize (PropertyTagFrameDelay) ; lpPropertyItem the PropertyItem * = new new the PropertyItem [FrameDelayNums]; Image-> GetPropertyItem (PropertyTagFrameDelay, FrameDelayNums, lpPropertyItem); the Guid = FrameDimensionTime; Image-> SelectActiveFrame (& the Guid, framePos The);}
Timer processing:
void CMFCApplication1Dlg::OnTimer(UINT_PTR nIDEvent)
{
if (image)
{
CWnd* pic = GetDlgItem(IDC_STATIC_PIC);
Graphics gh(pic->GetDC()->m_hDC); CRect rect; GetDlgItem(IDC_STATIC_PIC)->GetClientRect(&rect); gh.DrawImage(image, 0, 0, rect.Width(), rect.Height()); //gh.DrawImage(image, 0, 0, image->GetWidth(), image->GetHeight()); //设置当前需要显示的帧数 image->SelectActiveFrame(&Guid, framePos); framePos++; if (framePos == frameCount) { framePos = 0; } } CDialogEx::OnTimer(nIDEvent); }
Start timer:
SetTimer(0, 400, NULL);
LoadGif();
Gdi need to rely on libraries:
gdiplus.lib
Reference Address: https://blog.csdn.net/sz76211822/article/details/51507616
In the header file which added:
Image* image;
GUID Guid ;
UINT frameCount;
UINT framePos; ULONG_PTR gdiplusToken;
afx_msg void OnTimer(UINT_PTR nIDEvent); void LoadGif();
You need to rely on the header file:
#include <Gdiplusheaders.h>
#include <Gdiplus.h>
using namespace Gdiplus;
Class constructor which added interface:
// start gdi Image :: FromFile else fails
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
image = NULL;
frameCount = 0; framePos = 0;
Add a timer message processing:
BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CMFCApplication1Dlg::OnBnClickedButton1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON2, &CMFCApplication1Dlg::OnBnClickedButton2)
END_MESSAGE_MAP()
Load GIF file:
void CMFCApplication1Dlg::LoadGif()
{
WCHAR strModule[MAX_PATH * 2] = { 0 }; GetModuleFileNameW (NULL, strModule, the MAX_PATH * 2 ); :: PathRemoveFileSpecW (strModule); wsprintfW (strModule + wcslen (strModule), L " \\% s.gif ", L " sVcodec " ); Image = Image :: the FromFile ( strModule); // get the number of dimensions for a dimension to gif COUNT = Image- UINT> GetFrameDimensionsCount (); the GUID of pDimensionIDs = * (* the GUID of) new new the GUID of [COUNT]; Image-> GetFrameDimensionsList (pDimensionIDs, COUNT); strGuid WCHAR [ 39 ]; StringFromGUID2 (pDimensionIDs [ 0], strGuid, 39 ); frameCount = Image-> GetFrameCount (& pDimensionIDs [ 0 ]); // Delete [] pDimensionIDs;// get the time interval between the frames // first obtain the number of time intervals, PropertyTagFrameDelay GIG attribute ID is a predefined value GDI +, showing the delay time of the frame data tag = Image- FrameDelayNums UINT> GetPropertyItemSize (PropertyTagFrameDelay) ; lpPropertyItem the PropertyItem * = new new the PropertyItem [FrameDelayNums]; Image-> GetPropertyItem (PropertyTagFrameDelay, FrameDelayNums, lpPropertyItem); the Guid = FrameDimensionTime; Image-> SelectActiveFrame (& the Guid, framePos The);}
Timer processing:
void CMFCApplication1Dlg::OnTimer(UINT_PTR nIDEvent)
{
if (image)
{
CWnd* pic = GetDlgItem(IDC_STATIC_PIC);
Graphics gh(pic->GetDC()->m_hDC); CRect rect; GetDlgItem(IDC_STATIC_PIC)->GetClientRect(&rect); gh.DrawImage(image, 0, 0, rect.Width(), rect.Height()); //gh.DrawImage(image, 0, 0, image->GetWidth(), image->GetHeight()); //设置当前需要显示的帧数 image->SelectActiveFrame(&Guid, framePos); framePos++; if (framePos == frameCount) { framePos = 0; } } CDialogEx::OnTimer(nIDEvent); }
Start timer:
SetTimer(0, 400, NULL);
LoadGif();
Gdi need to rely on libraries:
gdiplus.lib
Reference Address: https://blog.csdn.net/sz76211822/article/details/51507616