15,978
社区成员
发帖
与我相关
我的任务
分享
class CGif : public Image
{
public:
virtual void AddRef(void);
virtual void Release(void);
//这里会返回下一帧和当前帧和时间间隔 用来在画的时候控制 anFramePosition表示当前要画第一帧
virtual long Draw(HDC hdc, const RECT& arcRect, unsigned int& anFramePosition);
public:
CGif(const wchar_t* filename, bool useEmbeddedColorManagement = false);
bool IsAnimatedGIF() { return m_nFrameCount > 1;}//这里判断是不是Gif
private:
void Initialize();
bool TestForAnimatedGIF();
private:
long mulRef;
bool m_bIsInitialized;
PropertyItem* m_pPropertyItem;
unsigned int m_nFrameCount;
unsigned int m_nFramePosition;
};
CGif::CGif(const wchar_t* filename, bool useEmbeddedColorManagement)
:Image(filename, useEmbeddedColorManagement)
{
mulRef = 0;
AddRef();
Initialize();
m_bIsInitialized = true;
TestForAnimatedGIF();
}
void CGif::Initialize()
{
m_nFrameCount = 0;
m_bIsInitialized = false;
m_pPropertyItem = NULL;
m_nFramePosition = 0;
}
bool CGif::TestForAnimatedGIF()
{
unsigned int count = 0;
count = GetFrameDimensionsCount();
GUID* pDimensionIDs = new GUID[count];
// Get the list of frame dimensions from the Image object.
GetFrameDimensionsList(pDimensionIDs, count);
// Get the number of frames in the first dimension.
m_nFrameCount = GetFrameCount(&pDimensionIDs[0]);
// Assume that the image has a property item of type PropertyItemEquipMake.
// Get the size of that property item.
int nSize = GetPropertyItemSize(PropertyTagFrameDelay);
// Allocate a buffer to receive the property item.
m_pPropertyItem = (PropertyItem*) malloc(nSize);
GetPropertyItem(PropertyTagFrameDelay, nSize, m_pPropertyItem);
delete [] pDimensionIDs;
return m_nFrameCount > 1;
}
void CGif::AddRef(void)
{
InterlockedIncrement(&mulRef);
}
void CGif::Release(void)
{
InterlockedDecrement(&mulRef);
if(mulRef == 0)
{
delete this;
}
}
long CGif::Draw(HDC hdc, const RECT& arcRect, unsigned int& anFramePosition)
{
GUID pageGuid = FrameDimensionTime;
if (hdc)
{
Graphics graphics(hdc);
graphics.DrawImage(this, arcRect.left, arcRect.top, arcRect.right - arcRect.left, arcRect.bottom - arcRect.top);
}
SelectActiveFrame(&pageGuid, anFramePosition++);
if (anFramePosition == m_nFrameCount)
anFramePosition = 0;
long lPause = ((long*)m_pPropertyItem->value)[anFramePosition] * 10;
return lPause;
}