• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

BitBlt cannot copy color?

when i use BitBlt copy a graphic from a bitmap device context into client device context, the color in the source DC is lost.The graphic changed into black and white.

this is the code:

void CBrushTestView::OnDraw(CDC* pDC)
{
      CBrushTestDoc* pDoc = GetDocument();
      ASSERT_VALID(pDoc);
      if (!pDoc)
            return;

      CBitmap bmp;
      CDC dcBmp;
      CBrush brush;
      RECT rect={0,0,100,100};
      LOGBRUSH lb;
      lb.lbColor = RGB(255,0,0);
      lb.lbHatch = HS_BDIAGONAL;
      lb.lbStyle = BS_SOLID;
      brush.CreateBrushIndirect(&lb);

      dcBmp.CreateCompatibleDC(pDC);
      bmp.CreateCompatibleBitmap(&dcBmp, 100, 100);
      dcBmp.SelectObject(&bmp);
      dcBmp.SelectObject(&brush);
      dcBmp.Rectangle(&rect);
      pDC->BitBlt(200,0,100,100,&dcBmp,0,0,SRCCOPY);
      pDC->SelectObject(&brush); // black and white
      pDC->Rectangle(&rect);// red
}
0
friendkey
Asked:
friendkey
  • 4
  • 2
1 Solution
 
Roshan DavisCommented:
Change the "CreateCompatibleBitmap" line to

bmp.CreateCompatibleBitmap(pDC, 100, 100);

Good Luck

0
 
Roshan DavisCommented:
Is that problem solved?
Rosh :)
0
 
friendkeyAuthor Commented:
I get it, thank you!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Roshan DavisCommented:
Please rate this Question

Rosh :)
0
 
friendkeyAuthor Commented:
don't be so impatient :)
0
 
Roshan DavisCommented:
:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now