在Symbian OS中绘制图形减少闪烁的方法有两种:
使用双缓存进行图形的绘制
使用CDirectScreenAccess类对屏幕进行直接绘制。
CDirectScreenAccess类在SDK种的解释如下:
Direct screen access is a way of drawing to the screen without using the window server. As this avoids client-server communication, it is much faster, and may be useful for games and video. Note that some interaction with the window server is needed in order to prevent the application from drawing over other application's data.
此外,使用CDirectScreenAccess还可以截获系统的通知消息(如菜单弹出、电话拨入、信息收到等)的对话框弹出事件,从而避免不必要的刷新工作。
一、CDirectScreenAccess的简单使用
CDirectScreenAccess使用起来非常简单,下面的几格步骤将介绍CDirectScreenAccess的使用方法:
在Carbide C++中使用向导生成GUI应用程序
在View类中创建成员变量CDirectScreenAccess* iDSA;
在View类中创建私有方法void DrawGraphics();代码如下:
void CTestDirectDrawAppView::DrawGraphics()
{
CFbsBitGc* gc = iDSA->Gc(); TRgb colorRed= AKN_LAF_COLOR(35);
gc->SetPenColor(colorRed);
gc->DrawRect(TRect(0, 0, 100, 100));
iDSA->ScreenDevice()->Update();
}
在View类的ConstructL方法里加入以下代码:
CEikonEnv* env = CEikonEnv::Static();
iDSA = CDirectScreenAccess::NewL(env->WsSession(), *(env->ScreenDevice()), this->Window(), *this);iDSA->StartL();
DrawGraphics();
在View类中创建以下两个私有方法:
void Restart(RDirectScreenAccess::TTerminationReasons aReason);
void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);
实现如下:
void CTestDirectDrawAppView::Restart(RDirectScreenAccess::TTerminationReasons aReason)
{
iDSA->StartL();
DrawGraphics();
}
void CTestDirectDrawAppView::AbortNow(RDirectScreenAccess::TTerminationReasons aReason)
{
iDSA->Cancel();
}