Draw bitmap x-times to screen
I am drawing the same resource bitmap several times at different position to the screen. This is done by calling the 'BitBlt()' function in a for-loop. I have discovered some performance problem. Does anybody know how I could improve the performance?
I have written the following code:
int CAnalysView::ShowData(CDC *pDC , CRect *pRect, bool bFromDocument )
{
CPhaseAnalysDoc *pDoc = GetDocument();
ASSERT( pDoc );
// get information about the maximum values that x and y can take
int xMin;
int xSize;
double yMin;
double ySize;
// select the palette into the device context
CPalette* paletteOld = NULL;
paletteOld = pDC->SelectPalette( m_WFPalette.GetPalette(), TRUE ); // In background
ASSERT( paletteOld );
int numentries = pDC->RealizePalette();
int nCnt = 0;
nCnt = pDoc -> GetCount();
int nxMidle = int( double(m_DrawRect.Width())/2 + 0.5 );
int nyMidle = int( double(m_DrawRect.Height())/2 + 0.5 );
int nRadius = min( m_DrawRect.Width()/2, m_DrawRect.Height()/2 - 10 );
CPhaseAnalysDoc::CComplexEntry *pcmpl;
CPoint pt;
{
int nI, nQ;
CPen penSolid( PS_SOLID, 1, m_ColorPen );
CDCSelect select( pDC, &penSolid );
CBrush brush( m_ColorPen );
CDCSelect select2( pDC, &brush );
// loading a bitmap to reduce the cpu-load
CBitmap bitmap;
bitmap.LoadBitmap(m_nIDBitmap);
// Create a Memory DC and Select the BMP to it
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMemory.SelectObject(&bitmap);
// get the size of the bitmap
BITMAP bm;
bitmap.GetBitmap( &bm );
CSize size( bm.bmWidth, bm.bmHeight );
pDC->DPtoLP( &size ); // convert device units into logical units.
int nWidth = size.cx;
int nHeight = size.cy;
int nOffsetX = nWidth / 2;
int nOffsetY = nHeight / 2;
// draw the bitmap to the different postion.
for( int t = 0; t < nCnt; t++ )
{
pcmpl = pDoc->Get( t );
if( pcmpl )
{
nI = pcmpl->nI;
nQ = pcmpl->nQ;
pt.x = m_DrawRect.left + nxMidle + nI * nRadius / xMax;
pt.y = m_DrawRect.top + nyMidle - nQ * nRadius / yMax;
// drawing a bitmap ( draw the pixels from the memoryDC to the screen )
pDC->BitBlt(pt.x - nOffsetX, pt.y - nOffsetY, nWidth, nHeight, &dcMemory, 0, 0, SRCCOPY);
}
}
dcMemory.SelectObject( pOldBitmap );
}
return 0; // ok
}
thanks for your help.
best regards.
rgwerder

