正确使用MFC和GDI +

时间:2014-04-03 23:17:40

标签: bitmap mfc gdi+

我试图在mdi视图中渲染两个不同的位图,有一个标志,如果这个标志为真,我渲染一个位图,如果是,则渲染第二个位图。 我的问题是它只有在我最小化和最大化视图时才能正常工作,例如,如果标志改变,第一个位图不会消失而第二个位图不会出现,只要我最小化并最大化回视图,正确的位图渲染。

有两个colormatrix one,alpha = 0,另一个alpha = 1

void MyAppView::OnDraw(CDC* /*pDC*/)
{
    MyAppViewDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;
    if(flag == true)
    {
        m_pImageRenderer->drawImage(this);
    }

    else
    {
        m_pImageRenderer->drawOtherImage(this);
    }

}


void Renderer::drawImage(CWnd* pWnd)
{

    int X = GetSystemMetrics( SM_CXSCREEN );
    int Y = GetSystemMetrics( SM_CYSCREEN );


        CClientDC dc(pWnd);
        Gdiplus::Graphics graphics(dc);

        imageVisibleAttributes->SetColorMatrix(m_pColorMatrixVisible);
        imageInvisibleAttributes->SetColorMatrix(m_pColorMatrixInvisible);
        graphics.DrawImage(m_pConnectionNotAvailable, Rect(0, 0, 140, 140), 0, 0, 140, 140, UnitPixel, imageInvisibleAttributes);
        graphics.DrawImage(m_pConnectionAvailable, Rect(0, 0, 140, 140), 0, 0, 140, 140, UnitPixel, imageVisibleAttributes);
}


void ImageHandler::drawOtherImage(CWnd* pWnd)
{

    CClientDC dc(pWnd);
    Gdiplus::Graphics graphics(dc);
    imageVisibleAttributes->SetColorMatrix(m_pColorMatrixVisible);
    imageInvisibleAttributes->SetColorMatrix(m_pColorMatrixInvisible);
    graphics.DrawImage(image, Rect(0, 0, 140, 140), 0, 0, 140, 140,     UnitPixel, imageInvisibleAttributes);
    graphics.DrawImage(image2, Rect(0, 0, 140, 140), 0, 0, 140, 140, UnitPixel, imageVisibleAttributes);
}

0 个答案:

没有答案