xGifInfo_GDIPlus::xGifInfo_GDIPlus(Gdiplus::Bitmap& inPicture)
:xGifInfo()
{
	xGifFrame* fr;
	sLONG nbframe=inPicture.GetFrameCount(&Gdiplus::FrameDimensionTime);
	long propsize;
	Gdiplus::PropertyItem* prop=0;
	
	fLoopCount=0;
	for(long i=0;i<nbframe;i++)
	{
		
		xGif89FrameInfo inInfo;
		sLONG framedelay;
		sBYTE transindex;
		
		inInfo.transparent=0;
		inInfo.delayTime=0;
		inInfo.inputFlag=0;
		inInfo.disposal=0;
		inInfo.transparent_index=0;
		
		
		inPicture.SelectActiveFrame(&Gdiplus::FrameDimensionTime,i);
		fr=new xGifFrame(0,0,inPicture.GetWidth(),inPicture.GetHeight(),false);
		
		
		if(propsize=inPicture.GetPropertyItemSize(PropertyTagFrameDelay))
		{
			prop=(Gdiplus::PropertyItem*)malloc(propsize);
			if(inPicture.GetPropertyItem(PropertyTagFrameDelay,propsize,prop)==Gdiplus::Ok)
			{
				inInfo.delayTime=*((long*)prop->value);
			}
			free((void*)prop);
		}
		if(propsize=inPicture.GetPropertyItemSize(0x5104))
		{
			prop=(Gdiplus::PropertyItem*)malloc(propsize);
			if(inPicture.GetPropertyItem(0x5104,propsize,prop)==Gdiplus::Ok)
			{
				inInfo.transparent_index=*((sBYTE*)prop->value);
			}
			free((void*)prop);
		}
		
		inInfo.transparent=inInfo.transparent_index!=-1;
		
		fr->SetGif89FrameInfo(inInfo);
		fFrameList.push_back(fr);
	}
	if(propsize=inPicture.GetPropertyItemSize(PropertyTagLoopCount))
	{
		prop=(Gdiplus::PropertyItem*)malloc(propsize);
		if(inPicture.GetPropertyItem(PropertyTagLoopCount,propsize,prop)==Gdiplus::Ok)
		{
			fLoopCount=*((short*)prop->value);
		}
		free((void*)prop);
	}
}
Exemple #2
0
BOOL CPictureCtrl::Show(LPCTSTR pcszFile,UINT nDrawFlag)
{
	USES_CONVERSION;

	if (pcszFile == NULL)
	{
		if (m_nTimerId != 0)
		{
			KillTimer(m_nTimerId);
			m_nTimerId = 0;
		}

		if (m_pImage != NULL)
		{
			delete m_pImage;
			m_pImage = NULL;
			Invalidate(FALSE);
		}
			
		m_strFilePath.Empty();
		return TRUE;
	}
	else
	{
		Gdiplus::Bitmap *pSrcImage = Gdiplus::Bitmap::FromFile(T2CW(pcszFile));
		if (pSrcImage == NULL)
			return FALSE;

		if (pSrcImage->GetLastStatus() != Gdiplus::Ok)
		{
			delete pSrcImage;
			return FALSE;
		}

		Gdiplus::Bitmap *pImage = pSrcImage->Clone(0,0,pSrcImage->GetWidth(),
			pSrcImage->GetHeight(),def_gplusPixFormat);
		delete pSrcImage;
		if (pSrcImage == NULL)
			return FALSE;
		
		Show(NULL,0);
		m_nDrawFlag = nDrawFlag;
		m_pImage = pImage;

		UINT nDimCount = m_pImage->GetFrameDimensionsCount();
		
		CArray<GUID,GUID&> dimGuids;
		dimGuids.SetSize(nDimCount);
 
		m_pImage->GetFrameDimensionsList(dimGuids.GetData(), nDimCount);
		m_nFrameCount = pImage->GetFrameCount(dimGuids.GetData());
	
		if (m_nFrameCount > 1)
		{
			m_dimGuid = dimGuids[0];

			int nSize = pImage->GetPropertyItemSize(PropertyTagFrameDelay);
			m_propItem.SetSize(nSize); 

			pImage->GetPropertyItem(PropertyTagFrameDelay, nSize, 
				(Gdiplus::PropertyItem*)m_propItem.GetData());

			m_nCurFrame = 0;
			m_nTimerId = SetTimer(TIMER_ID,GetFrameDelay(),NULL);
		} 
 
		Invalidate(FALSE);
		m_dwSampleTick = GetTickCount();

		m_strFilePath = pcszFile;
		return TRUE;
	}
}