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?
LVL 1
cyberbumAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.