Home > Software engineering >  How to improve efficiency of drawing
How to improve efficiency of drawing

Time:09-16

 
Void InitBackgroundImage (pDC) CDC *
{
If (m_nModMove==VIEW_MOD_MOVE)
return;

DestroyBackgroundImage ();
CRect rectClient;
GetClientRect (& amp; RectClient);
The CDC dcBkgnd;
M_dcMemory. CreateCompatibleDC (pDC);
ASSERT (m_dcMemory GetSafeHdc ());
M_bitmapTemp. CreateCompatibleBitmap (pDC, m_nScreenWidth m_nScreenHeight);
ASSERT (m_bitmapTemp GetSafeHandle ());
M_pOldBitmap=m_dcMemory. SelectObject (& amp; M_bitmapTemp);
M_dcMemory. FillSolidRect (0, 0, m_nScreenWidth m_nScreenHeight, VIEWCOLOR);
DrawBox (& amp; M_dcMemory);//draw a custom background picture
}
Void OnPaint ()
{
InitBackgroundImage (& amp; Dc);//back to the background, the background does not change when not draw

The CDC dcMemory;
DcMemory. CreateCompatibleDC (& amp; M_dcMemory);
CBitmap BMP.
BMP. CreateCompatibleBitmap (& amp; M_dcMemory m_nScreenWidth, m_nScreenHeight);
CBitmap * pOldBitmap=dcMemory. SelectObject (& amp; BMP);

DcMemory. SetBkMode (TRANSPARENT);
DcMemory. BitBlt (0, 0, m_nScreenWidth m_nScreenHeight, & amp; M_dcMemory, 0, 0, SRCCOPY);//the CDC copy

DrawMoveingBox (& amp; DcMemory);//draw mobile rectangle

Dc. BitBlt (0, 0, m_nScreenWidth m_nScreenHeight, & amp; DcMemory, 0, 0, SRCCOPY);//draw the image to the main DC

DcMemory. SelectObject (pOldBitmap);
DcMemory. DeleteDC ();
BMP. DeleteObject ();
}

As shown in the code is m_dcMemory member variables, generated in order to save the background in the InitBackgroundImage function, need not frequent painting background, only need to move the rectangle in the picture on background
I think this drawing should be quickly in theory, but actual testing found that such drawing should also will be very card in the rectangular

CodePudding user response:


DrawMoveingBox (& amp; DcMemory);//draw mobile rectangle
The code

CodePudding user response:

Don't need
InitBackgroundImage (& amp; Dc);//back to the background, the background does not change without drawing

CodePudding user response:

DcMemory made class variables and the corresponding bitmap can also
BitBlt background to dcMemory
Then draw
BitBlt to the target DC

For those operations in DrawMoveingBox?

CodePudding user response:

reference zgl7903 reply: 3/f
dcMemory made class variables and the corresponding bitmap can also
BitBlt background to dcMemory
Then draw
BitBlt to the target DC

For those operations in DrawMoveingBox?

Yes, the corresponding bitmap is also a class member variable
The CDC m_dcMemory;
CBitmap m_bitmapTemp;
CBitmap * m_pOldBitmap;

CodePudding user response:

refer to the second floor schlafenhamster response:
don't need
InitBackgroundImage (& amp; Dc);//back to the background, the background does not change when not draw

Also will change the background, just less frequent change

CodePudding user response:

reference zgl7903 reply: 3/f
dcMemory made class variables and the corresponding bitmap can also
BitBlt background to dcMemory
Then draw
BitBlt to the target DC

For those operations in DrawMoveingBox?

 
//DrawMoveingBox () is the rectangular drawing mobile, stored in m_vSelectCard vector, test the vector of the size is only 1
Int nBoxCount=m_vSelectCard. The size ();
for (int i=0; I{
//test rectangle
Int l=m_vSelectCard [I] nCrdStartX;
Int t=m_vSelectCard [I] nCrdStartY;
Int r=m_vSelectCard [I] nCrdStartX + m_vSelectCard [I] nCrdWidth;
Int b=m_vSelectCard [I] nCrdStartY + m_vSelectCard [I] nCrdHeight;
CRect BoxRect=CRect (l, t, r, b);
BoxRect. OffsetRect (- m_nScrollPos_X - m_nScrollPos_Y);

PDC - & gt; FillSolidRect (BoxRect SRECTCOLOR);

CPen pen (PS_SOLID, 1, RCLINECOLORS);
CPen * pOldPen=pDC - & gt; SelectObject ((& amp; Pen));
PDC - & gt; MoveTo (BoxRect. Left, BoxRect. Top);
PDC - & gt; LineTo (BoxRect. Right, BoxRect. Top);
PDC - & gt; LineTo (BoxRect. Right, BoxRect. Bottom);
PDC - & gt; LineTo (BoxRect. Left, BoxRect. Bottom);
PDC - & gt; LineTo (BoxRect. Left, BoxRect. Top);
PDC - & gt; SelectObject (pOldPen);
Pen. DeleteObject ();
POldPen=NULL;
PDC - & gt; SetBkMode (TRANSPARENT);
}
  • Related