Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Toolmaker

MFC: Drawing on offscreen Bitmap

This topic is 5236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to draw on an offscreen bitmap using MFC. After I am done drawing on the bitmap I insert it into an imagelist. However, when I use the bitmap from the image list I only get to see a black square. What am I doing wrong here? This is my code:
    CBitmap      *OldBmp = NULL;
    CBitmap       bmp;
    CClientDC    *pDC = NULL;
    CDC           DC;
    CBrush        Brush;
    CBrush       *OldBrush = NULL;

    // Get DC

    if (::IsWindow(GetSafeHwnd()))
        pDC = new CClientDC(this);
    else
        pDC = new CClientDC(AfxGetMainWnd());

    if (!pDC)
        return;

    if (!DC.CreateCompatibleDC(pDC))
    {
        TRACE("Failed to create Compatible DC\n");
        return;
    }

    if (!bmp.CreateCompatibleBitmap(&DC, 8, 8))
    {
        TRACE("Failed to create Compatible Bitmap\n");
        return;
    }

    OldBmp   = DC.SelectObject(&bmp);
    OldBrush = DC.SelectObject(&Brush);

    CRect Rect(0, 0, 8, 8);
    DC.SetBkColor(RGB(255,0,0));
    DC.FillSolidRect(&Rect, RGB(255, 0, 0));

    DC.SelectObject(OldBmp);
    DC.SelectObject(OldBrush);

    // Dump into ImageList

    m_ImageList.Create(8, 8, ILC_COLOR, 0, 50);
    m_ImageList.Add(&bmp, (COLORREF)0);

    // Release DC

    bmp.DeleteObject();
    DC.DeleteDC();
    Brush.DeleteObject();
    delete pDC;
    pDC = NULL;

    // Attach imagelist to legenda

    m_lstLegenda.SetImageList(&m_ImageList, LVSIL_SMALL);
Toolmaker
-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
Advertisement
I could be wrong, but I don''t think (COLORREF)0 is a valid COLORREF. Try RGB(0, 0, 0) (or 0xFF000000 if you really want to be hardcore ) instead? Some GDI functions seem to be rather anal about this.

Share this post


Link to post
Share on other sites
I got it working! I downloaded Microsoft''s CMemDC example from http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q151/8/56.asp&NoWebContent=1 and used that as a base.

However, I have a new problem. I need to create a bunch of colors(I think the values of 255, 223, 191, 159, 127, 95, 63, 31 would do) using the following pattern:

(Value, 0, 0)
(0, Value, 0)
(0, 0, Value)
(Value, Value, 0)
(Value, 0, Value)
(0, Value, Value)

Where Value ranges from the above list. I can''t find a way to implement this in an algo, any ideas?

Toolmaker




-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!