tags:

views:

421

answers:

1

Hi,

I can't draw a pattern with a transparent background. This is my snippet :

bitmap.CreateBitmap(8, 8, 1, 1, &bits)
brush.CreatePatternBrush(&bitmap)
hbrush = pCgrCurrentDC->SelectObject(&brush);
// set text color 
TextCol = pCgrCurrentDC->SetTextColor(CgrColourPalRGB);  
int oldBkgrdMode = pCgrCurrentDC->SetBkMode(TRANSPARENT);
//draw polygon 
pCgrCurrentDC->Polygon(CgrBuffer, n);

The doc on msdn doesn't mention anything about transparency. I guess this mode could be used? Or is this a bug ?

Thanks!

+1  A: 

Mode TRANSPARENT means that background will not be filled before your brush is drawn. But your brush does not contain any transparent pixels in it and it redraws background pixels anyway. Fourth argument in CreateBitmap was set to 1 in your sample. That means bitmap is monochrome.

You need to use 32-bit bitmap to use transparency in brushes. GDI supports transparency with some limits. Use GDI+ for full transparency support.

Kirill V. Lyadvinsky