| |

VerySource

 Forgot password?
 Register
Search
View: 2038|Reply: 15

The bitmap created by CreateCompatibleBitmap is black by default. Before drawing up, you must paint the background color

[Copy link]

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-11-25 09:30:02
| Show all posts |Read mode
As the title! ! !
Reply

Use magic Report

0

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-11-25 09:45:01
| Show all posts
The following example is painted with a white background
HDC hMemDC = ::CreateCompatibleDC(hdc);
if(hMemDC == NULL)
return NULL;
CSize cs(GetWidth()+GetPenWidth(),GetHeight()+GetPenWidth());
HBITMAP hBmp = ::CreateCompatibleBitmap(hdc,cs.cx,cs.cy);
         .....

HBITMAP hOldBmp =(HBITMAP) ::SelectObject(hMemDC,hBmp);
To
PatBlt(hMemDC,0,0,cs.cx,cs.cy,WHITENESS);

         ........
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-11-25 10:15:01
| Show all posts
CDC::FillSolidRect will do
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-11-25 11:00:01
| Show all posts
I made a drawing program, using memory DC, the original code is as follows: (in the OnDraw(CDC* pDC) function of C*View) ----- But after running, the entire View area is black?

CDC dc;
CDC* pDrawDC = pDC;
CBitmap bitmap;
CBitmap* pOldBitmap;

CRect rect;
GetClientRect(&rect);
//============================================== ========
if (dc.CreateCompatibleDC(pDC))
{
if (bitmap.CreateCompatibleBitmap(pDC,
                     rect.Width(),
         rect.Height()))
{
OnPrepareDC(&dc,NULL);
pDrawDC =&dc;
pOldBitmap = dc.SelectObject(&bitmap);
}
}
//============================================== ========
pDoc->Draw(pDrawDC,ViewID);
pDrawDC->TextOut(1,1,*str);
dc.DPtoLP(&rect);
//============================================== ========
if (pDrawDC != pDC)
{
pDC->BitBlt( 0, 0,rect.Width(), rect.Height(),
&dc, 0, 0, SRCCOPY);
dc.SelectObject(pOldBitmap);
bitmap.DeleteObject();
}
Please help me, what's the problem?
Reply

Use magic Report

2

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-11-25 11:15:01
| Show all posts
Using CDC::FillSolidRect() does not work at all! How to do?
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-11-25 11:30:01
| Show all posts
Impossible not to work
pOldBitmap = dc.SelectObject(&bitmap);
dc.FillSolidRect(&rect,RGB(255,255,255));
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-25 11:45:02
| Show all posts
If you make it white, it will definitely work. No, you are wrong elsewhere, but if you want to make it into other colors, there will be a problem. I am also struggling with this problem.
You see the following code:
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-25 12:00:01
| Show all posts
void CDBDCView::MemDraw(CDC* pDC)
{
CRect rect;
GetClientRect(rect);
CDC memDC;
CBitmap temBmp;
memDC.CreateCompatibleDC(pDC);
temBmp.CreateCompatibleBitmap(&memDC,rect.Width(),rect.Height());
CBitmap* pOldBmp=memDC.SelectObject(&temBmp);
CBrush brush(RGB(0,255,255));
CBrush* pOldBrush=memDC.SelectObject(&brush);
memDC.Rectangle(rect);
COLORREF oldColor;
oldColor=memDC.SetBkColor(RGB(255,0,0));
memDC.TextOut(100,100,"verysource");
pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memDC,
0,0,SRCCOPY);
memDC.SelectObject(pOldBmp);
memDC.SetBkColor(oldColor);
}
The background of the font set above is red, but it is all black when displayed, and the words are covered.
The defined one can't brush
Help me explain this problem and what is the solution
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-11-25 12:15:01
| Show all posts
Hey, when I did it before, I loaded a 24bit bitmap
Make the bottom canvas.
Reply

Use magic Report

0

Threads

6

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-25 12:30:01
| Show all posts
void CDBDCView::MemDraw(CDC* pDC)
{
CRect rect;
GetClientRect(rect);
   CDC memDC;
   CBitmap temBmp;
   memDC.CreateCompatibleDC(pDC);
>>>temBmp.CreateCompatibleBitmap(&memDC,rect.Width(),rect.Height());
   CBitmap* pOldBmp=memDC.SelectObject(&temBmp);
   CBrush brush(RGB(0,255,255));
   CBrush* pOldBrush=memDC.SelectObject(&brush);
   memDC.Rectangle(rect);
   COLORREF oldColor;
   oldColor=memDC.SetBkColor(RGB(255,0,0));
   memDC.TextOut(100,100,"verysource");
   pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
   memDC.SelectObject(pOldBmp);
>>>memDC.SelectObject(pOldBrush);
   memDC.SetBkColor(oldColor);
}

FROM MSDN:
A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list