本文链接:http://user.qzone.qq.com/463450970/blog/1220702709
对于Gif动画图片用CImageDecoder解码显示,网上有些说明资料,这里是我调试过的部分代码,可以播放,算是自己的笔记吧。
头文件中相关变量定义:
TInt iType;
CFbsBitmap* iBitmap;
CFbsBitmap* iBitmapMark;//对应的掩码位图
CGifTimer* iGifTimer;
TTimeIntervalMicroSeconds32 iDisplayTimer;
TFrameInfo iFrameInfo;
TInt iCurFrame;
TInt iFrameCount;
源文件中gif动画播放主要代码:
void CImage::StartGif()
{
Cancel();
delete iDecoder;
iDecoder = NULL;
delete iBitmap;
iBitmap = NULL;
delete iBitmapMark;
iBitmapMark = NULL;
this->iDecoder = CImageDecoder::FileNewL(CEikonEnv::Static()->FsSession(),iFileName,CImageDecoder::EAllowGeneratedMask);
if(iFrameCount == 0)
iFrameCount = this->iDecoder->FrameCount();//得到gif动画图片帧数
if(iCurFrame == iFrameCount)//
iFrameInfo = iDecoder->FrameInfo(iCurFrame);//
iBitmap = new (ELeave) CFbsBitmap();
iBitmap->Create(iFrameInfo.iOverallSizeInPixels,iFrameInfo.iFrameDisplayMode);//注意这里位图创建与掩码位图创建的区别
iBitmapMark = new(ELeave) CFbsBitmap();
iBitmapMark->Create(iFrameInfo.iOverallSizeInPixels,EGray256 );//至于这里的参数,sdk有说明,在下一语句代码中会用到,呵
iDecoder->Convert(&iStatus,*iBitmap,*iBitmapMark,iCurFrame); //看sdk
iState = EDecoding;
SetActive();
}
void CImage::RunL()
{
if(iStatus.Int() == KErrNone)
{
iState = EDecodOver;
this->iObserver.ImageDecodeOver(iStatus.Int());//利用观察器通知绘制图片
if(iType == EGif)
{
iGifTimer->StartL(TTimeIntervalMicroSeconds32(iFrameInfo.iDelay.Int64()));//
}
else
User::Leave(iStatus.Int());
}
void CImage::GifFrameConverState()//
iCurFrame++;//
}
void CGifAppView::Draw( const TRect& /*aRect*/ ) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Gets the control's extent
TRect drawRect( Rect());
// Clears the screen
//gc.Clear( drawRect );//注意这里不要清屏
gc.BitBltMasked(iImage->GetCurFrameTl(),iImage->GetBitmap(),Rect(),
iImage->GetBitmapMark(),EFalse);
}
上面是主要的功能代码,应该很清楚了,希望路过的老大不要笑话。