|
|
目前正在做一个信号处理的工作,要求将信号数据以谱图形式显示。当收到新的数据后,根据每组数据的大小计算出应该显示的颜色,同时将原来位图上移一位,在picturebox控件最下方显示出新的颜色点,达到平滑移动的效果。我目前采用了GDI的双缓存技术,但是画图的速度远远没有跟的上接收数据的速度,希望大家能够给我提一些更好的改进方案,提高我画图效率。(对另外两种画图方式,我还不是很了解,在此希望大家能够多多指教,在这里请各位Directx的高人指点)
class CWBSpecView : public CFormView
{
CDC MemDC;
CBitmap MemBitmap;} //MemDC, MemBitmap为全局变量,
void CWBSpecView::OnInitialUpdate() //内存图层初始化
{
m_nScreenx=GetSystemMetrics(SM_CXSCREEN);
m_nScreeny=GetSystemMetrics(SM_CYSCREEN);
//内存图层初始化
CWnd *Specpic=this->GetDlgItem(IDC_PIC_SPEC);
CDC *SpecpicDC=Specpic->GetDC();
Specpic->GetClientRect(Rect2);
int w=Rect2.Width();
int h=Rect2.Height();
MemDC.CreateCompatibleDC(NULL);
MemBitmap.CreateCompatibleBitmap(SpecpicDC,m_nScreenx,m_nScreeny);
}
画图函数:
///////////////////////////////////////////////////////////////////
void drawpicSpec()
{ int count;
int nLevel;
count=4096;
CDrawpictureData* DrawpictureData=GetDrawpictureData();
ASSERT(DrawpictureData);
CMainFrame *pFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
CWBSpecView *pView=(CWBSpecView *)(pFrame->m_pWBSpecview);
CWnd *Specpic=pView->GetDlgItem(IDC_PIC_SPEC);
CDC *SpecpicDC=Specpic->GetDC();
CRect Rect2;
Specpic->GetClientRect(Rect2);
int w=Rect2.Width();
int h=Rect2.Height();
CBitmap *poldBit=pView->MemDC.SelectObject(&pView->MemBitmap);
for(int i=0;i<count;i++)
{
MSG message;
while(: eekMessage(&message,NULL,0,0,PM_REMOVE))
{
::TranslateMessage(&message);
: ispatchMessage(&message);
}
nLevel=ColorConf->Comppow(float(DrawpictureData->uiSonaData)); //此处计算色素索引值
pView->MemDC.SetPixelV(i*Rect2.right/count,Rect2.Height()-1,ColorConf->m_nColor[nLevel]); //根据色素索引值在最下一行画出
}
pView->MemDC.BitBlt(0,Rect2.top-1,w,h,&pView->MemDC,0,0,SRCCOPY); //将内存中图像上移一行
SpecpicDC->BitBlt(0,Rect2.top,w,h,&pView->MemDC,0,0,SRCCOPY);//将内存中图像显示
Specpic->ReleaseDC(SpecpicDC);
}
程序启动2个线程来工作,一个线程用来接收数据,令一个线程根据接收到的数据进行绘图。画图函数在线程中调用,目前我采用这种方法,每秒只能显示十几帧,根本不能将每秒全部接收的数据显示。请各路高手能帮我修改一下解决方法。在此多谢了。 |
|