Re: Drawing text on a bitmap
Quote:
Originally Posted by
Salvadoravi
Now I got rid off the white border but everytime I draw a text it write on top of the previous text so after few seconds everything is a mess and the time is no longer readable.
Can anyone please tell me what am I doing wrong?
Draw the background before you draw the text. You can use something like memDC.FillSolidRect(...).
Re: Drawing text on a bitmap
Well, it's a bitmap, so what would you expect? You have to "erase" the previous state before you draw the current one. So you have to do as D_Drmmr said, and repaint the rect where the text is drawn before you draw the text again.
Re: Drawing text on a bitmap
Guys,
I've tried,
Code:
CRect rect;
GetClientRect(&rect);
CPaintDC dc(this); // device context for painting
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.FillSolidRect(rect, 0x0000FF);
memDC.SelectObject(m_bmpMyPic);
memDC.SetBkMode(TRANSPARENT);
memDC.TextOut(10,5, szCurrentTime);
dc.BitBlt(0, 0 , 130, 39, &memDC, 0,0, SRCCOPY);
I get the same result.
Code:
CRect rect;
GetClientRect(&rect);
CPaintDC dc(this); // device context for painting
CDC memDC;
memDC.CreateCompatibleDC(&dc);
dc.FillSolidRect(rect, 0x0000FF);
memDC.SelectObject(m_bmpMyPic);
memDC.SetBkMode(TRANSPARENT);
memDC.TextOut(10,5, szCurrentTime);
dc.BitBlt(0, 0 , 130, 39, &memDC, 0,0, SRCCOPY);
Same problem + very bad flickering.
Code:
CRect rect;
GetClientRect(&rect);
CPaintDC dc(this); // device context for painting
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(m_bmpMyPic);
memDC.SetBkMode(TRANSPARENT);
memDC.FillSolidRect(rect, 0x0000FF);
memDC.TextOut(10,5, szCurrentTime);
dc.BitBlt(0, 0 , 130, 39, &memDC, 0,0, SRCCOPY);
This one works but the background is red and not a bitmap.
Can you please guide me what goes wrong??
Re: Drawing text on a bitmap
Quote:
Originally Posted by
Salvadoravi
This one works but the background is red and not a bitmap.
Can you please guide me what goes wrong??
It's red, because you painted it red. Please explain what you want to do.
Re: Drawing text on a bitmap
You need to create another bitmap, something as follows:
- In your onpaint, create a temporary bitmap
- blit your m_bmpMyPic bitmap to this temporary bitmap
- draw the clock on this temporary bitmap
- blit the temporary bitmap to the CPaintDC