CStatic.setBitmap导致矩形在onpaint中闪烁(MFC)

时间:2019-07-08 17:52:51

标签: c++ mfc paint

我试图相对较快地刷新图像(如10fps),并且每隔几帧闪烁一次。我将闪烁的区域缩小到了将位图设置为CStatic中的OnPaint的位置。

代码如下:

void CRadarView::OnPaint()
{

    CPaintDC dc(this); // device context for painting

    if (m_streaming == -1 || m_frameThread.fgArr.size() == 0 || m_frameThread.bgArr.size() == 0 || m_frameThread.subtractedFgArr.size() == 0)
        return;


    CDC *screenDC = GetDC();
    CDC mDC;
    mDC.CreateCompatibleDC(screenDC);
    CMemDC memDC(*screenDC, this);
    CDC& rDC = memDC.GetDC();

    // Raw radar image
    //-----------------

    if (m_showRadar)
    {
        CBitmap b1;
        CImage img1;
        getImage(img1, m_frameThread.fgArr);
        b1.CreateCompatibleBitmap(&rDC, m_imageDisplaySize.x, m_imageDisplaySize.y);

        CBitmap *pob1 = rDC.SelectObject(&b1);
        rDC.SetStretchBltMode(HALFTONE);
        if (zoomed){
            img1.StretchBlt(rDC, 0, 0, m_imageDisplaySize.x, m_imageDisplaySize.y, zoomXStart, zoomYStart, zoomXEnd - zoomXStart, zoomYEnd - zoomYStart, SRCCOPY);
        }
        else{
            img1.StretchBlt(rDC, 0, 0, m_imageDisplaySize.x, m_imageDisplaySize.y, 0, 0, img1.GetWidth(), img1.GetHeight(), SRCCOPY);
        }

        rDC.SelectObject(pob1);
        m_image.SetBitmap((HBITMAP)b1); //THIS IS WHERE THE FLASHING IS OCCURING
    }

0 个答案:

没有答案