Discussion:
Create and draw a bitmap in memory, please help!!!!
(too old to reply)
x***@gmail.com
2007-01-18 08:22:17 UTC
Permalink
Best programmers,

I'm really really desperate on this topic.
Please help me out, I don't understand the whole concept of creating a
CBitmap.
I need to create a bitmap in MEMORY, draw something and that save it on
file. I've to do that, so I can place a drawingobject (pushpin) in
mappoint, which loads the bitmap from file (there is no other way) and
that during run-time.

I've searched a lot in google, codeproject.com, codeguru.com etc... but
someway or somehow I can't get a grip on how to handle the CBitmap.

I only know how I have to make a CDC object, so I can draw something.
But when I call the member CBitmap::CreateBitmap( int nWidth, int
nHeight, UINT nPlanes, UINT nBitcount, const void* lpBits );
I just understanf nWidth and nHeight, but the rest of it is for me like
Chinese. You all know how MSDN is, it's like a dictionary, no
explanation.

Please help me, thank you.
x***@gmail.com
2007-01-22 11:43:39 UTC
Permalink
Hi I managed to write this code:

{
CBitmap MyBmp;
CBitmap *pOldBmp;
CDC MemDC;
CDC *pDC = GetDC();
CString csTxt = "Hello";

MemDC.CreateCompatibleDC(pDC);
MyBmp.CreateCompatibleBitmap(&MemDC, 50, 50 );
pOldBmp = MemDC.SelectObject(&MyBmp);

CRect rect;
rect.SetRect (0,0,50,50);

MemDC.SetTextColor(RGB(0,0,255));
MemDC.DrawText((LPCTSTR)csTxt,6, &rect, DT_CENTER );

GetDC()->BitBlt(10, 10, 50, 50, &MemDC, 0, 0, SRCAND);

//When done, than::
MemDC.SelectObject(pOldBmp);
ReleaseDC(pDC);
MemDC.DeleteDC();
}

It works, except the color stays black. How can I change the color of
the text?
And why is the rest of the rectangle black?
Thank you!
Post by x***@gmail.com
Best programmers,
I'm really really desperate on this topic.
Please help me out, I don't understand the whole concept of creating a
CBitmap.
I need to create a bitmap in MEMORY, draw something and that save it on
file. I've to do that, so I can place a drawingobject (pushpin) in
mappoint, which loads the bitmap from file (there is no other way) and
that during run-time.
I've searched a lot in google, codeproject.com, codeguru.com etc... but
someway or somehow I can't get a grip on how to handle the CBitmap.
I only know how I have to make a CDC object, so I can draw something.
But when I call the member CBitmap::CreateBitmap( int nWidth, int
nHeight, UINT nPlanes, UINT nBitcount, const void* lpBits );
I just understanf nWidth and nHeight, but the rest of it is for me like
Chinese. You all know how MSDN is, it's like a dictionary, no
explanation.
Please help me, thank you.
Loading...