• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

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?
0
cyberbum
Asked:
cyberbum
  • 2
  • 2
1 Solution
 
chensuCommented:
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);
0
 
cyberbumAuthor Commented:
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..
0
 
cyberbumAuthor Commented:
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
0
 
chensuCommented:
Thank you.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now