How to create a large DC compatible memory in GDI programming?

I want to create a large CompatibleDC, draw a large image on it, and then add part of the image to another DC in order to achieve high performance.

I use the following code to create a compatible DC. But when the rectangle becomes very large, etc .: 5000 * 5000, the created CompatibleDC becomes unstable. sometimes it’s normal, sometimes it fails. is there something wrong with my code?

input :pInputDC
output:pOutputMemDC

{
    pOutputMemDC=new CDC();
    VERIFY(pOutputMemDC->CreateCompatibleDC(pInputDC));

    CRect rect(0,0,nDCWidth,nDCHeight);
    CBitmap bitmap; 
    if (bitmap.CreateCompatibleBitmap(pInputDC, rect.Width(), rect.Height()))
    {
        pOutputMemDC->SetViewportOrg(-rect.left, -rect.top);
        m_pOldBitmap = pOutputMemDC->SelectObject(&bitmap);
    }
    CBrush brush;
    VERIFY(brush.CreateSolidBrush(RGB(255,0, 0)));
    brush.UnrealizeObject();
    pOutputMemDC->FillRect(rect, &brush);
}
+3
source share
3 answers

, DC blitting , DC, DC , DC, , , , blit-. (-x, -y) , . (100 200) - (400 400) , DC (300x200) (-100, -200).

: -, . -, GDI DC ( ). , , , .

, DC - - (, JPEG), . , , , / / . - DC, DC DC. , , , .

+2

5000x5000 . 100 . , , .

1 , , , . . ? , , ?

, , .

0

Make sure you select all the original GDI objects for the domain controllers.

The problem may be that your Bitmap is still selected in pOutputMemDC when it is destroyed, and one or both of them cannot be deleted properly. Therefore, memory problems may begin.

0
source

Source: https://habr.com/ru/post/1708624/


All Articles