-
July 19th, 2002, 05:28 AM
#1
Create a CBitmap from a CDC ?
Hi,
I want to create a bitmap in memory from the contents of a device context held in memory, and I'm really struggling. Here's my CDC code :
Code:
CPaintDC dc(this); // device context for painting
m_sCaption = "Some text";
CFont font;
font.CreatePointFont(150, _T("Verdana"));
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SetBkMode(TRANSPARENT);
memDC.SetTextColor(RGB(0, 0, 0));
memDC.SelectObject(&font);
memDC.TextOut(0, 0, m_sCaption);
CSize sz = memDC.GetTextExtent(m_sCaption);
// i now have my text in a device context, and i know the size of the image.
// what code do i add here to copy this into a bitmap ?
Thanks
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
-
July 19th, 2002, 05:37 AM
#2
I think you should create a bitmap and select it into the dc...
e.g. BOOL CreateCompatibleBitmap(
CDC* pDC,
int nWidth,
int nHeight
);
Then use
CBitmap bitmap;
bitmap.CreateCompatableBitmap(dc, widht, height);
CDC memDC;
memDC.SelectObject(bitmap);
memDC.SetBkMode(TRANSPARENT);
memDC.SetTextColor(RGB(0, 0, 0));
memDC.SelectObject(&font);
memDC.TextOut(0, 0, m_sCaption);
CSize sz = memDC.GetTextExtent(m_sCaption);
Now if you draw on the memDC, you will be drawing on the Bitmap
-
August 17th, 2002, 04:48 PM
#3
hey Jase,
I've been collecting everythign useful related to bitmaps in a slightly expanded BDLG sample, it might be helpful.
http://www.sayslaw.com/Thynx/C/bdlg/bdlg.htm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|