// 成功返回0, 失败返回 -1
int ScreenDoubleBuffer(void)
{
// screen buffer point
int* p_old_buf = NULL;
int* p_new_buf = NULL;
// screen width and height
int scr_w = 240;
int scr_h = 320;
// screen buffer size
int size = scr_w*scr_h*2;
// 要显示字符串的宽高
int text_w = 0
int text_h = 0;
char* pcText = "Test Screen buffer!";
int ret = -1;
int x,y;
//--<1> get current screen buffer point
p_old_buf = getScreenBuffer();
if( NULL == p_old_buf ){
return ret;
}
//<2>create new screen buffer
p_new_buf = malloc(size);
if( NULL == p_new_buf ){
return MR_FAILED;
}
//<3>set new screen buffer
setScreenBuffer( p_new_buf );
//<4>draw text to new screen buffer
clearScreen( 100, 100,100);
// 得到要显示字符穿的宽高信息
textWidthHeight( pcText, FALSE, MR_FONT_MEDIUM, &text_w,&text_h);
// 居中显示
x = ( scr_w - text_w )/2;
y = ( scr_h - text_h )/2;
// 是指将数据画到 new_buf 中了,并没有刷新界面显示
drawText( pcText, x, y, 255, 255, 255, FALSE, MR_FONT_MEDIUM);
//<5> recover screen buffer
setScreenBuffer(p_old_buf);
memcpy(p_old_buf,p_new_buf,size);
refreshScreen(0,0,240,320); // 刷新屏幕显示
return 0;
}
|