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 ?
msdn上的doc没有提到透明度。我猜这个模式可以用吗?或者这是一个错误?
Thanks!
1 个解决方案
#1
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.
模式TRANSPARENT表示在绘制画笔之前不会填充背景。但是你的画笔中不包含任何透明像素,无论如何它都会重绘背景像素。 CreateBitmap中的第四个参数在您的示例中设置为1。这意味着位图是单色的。
You need to use 32-bit bitmap to use transparency in brushes. GDI supports transparency with some limits. Use GDI+ for full transparency support.
您需要使用32位位图来使用画笔中的透明度。 GDI支持透明度有一些限制。使用GDI +获得完全透明支持。
#1
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.
模式TRANSPARENT表示在绘制画笔之前不会填充背景。但是你的画笔中不包含任何透明像素,无论如何它都会重绘背景像素。 CreateBitmap中的第四个参数在您的示例中设置为1。这意味着位图是单色的。
You need to use 32-bit bitmap to use transparency in brushes. GDI supports transparency with some limits. Use GDI+ for full transparency support.
您需要使用32位位图来使用画笔中的透明度。 GDI支持透明度有一些限制。使用GDI +获得完全透明支持。