Link to home
Start Free TrialLog in
Avatar of cyberbum
cyberbum

asked on

Copying a CFont to a CBitmap

I was wondering if there is any way to blit a CFont to a CBitmap. Right now, I can use DrawText but that only outputs to a CDC...is there any way to get the output of the drawtext to the CBitmap?
Avatar of chensu
chensu
Flag of Canada image

Create a memory DC and select the CBitmap into it.

// CBitmap bmp;

CDC MemDC;
MemDC.CreateCompatibleDC(NULL);

CBitmap *pOldBmp = MemDC.SelectObject(&bmp);

// MemDC.DrawText

MemDC.SelectObject(pOldBmp);
Avatar of cyberbum
cyberbum

ASKER

When I do the DrawText, the bitmap ends up having a white rect in it...this is what I do:
      CDC dc;
            dc.CreateCompatibleDC(NULL);


            // Select the bitmap into the DC
            CBitmap * pOldBmp = dc.SelectObject(CBitmap::FromHandle(pImg->m_stImage.m_hBitmap));
            
            // Set Font
            CFont* pOldFont = dc.SelectObject(&m_fontFriends);
             
            // Set TextColor
            dc.SetTextColor(m_crFriendsFont);

            // DrawText
            dc.DrawText(pFriend->GetNickName(), &rectText, 0);

            // Cleanup
            dc.SelectObject(pOldFont);
            dc.SelectObject(pOldBmp);

Also, where did you get your CMemDC class? I can't even construct mine without asserting..
Ok, it was my fault...my font color was the same as the background color:)
Add a comment so I can give you your points
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial