How can I draw a patternBrush with transparent backround (GDI)?

跟風遠走 提交于 2019-12-11 17:45:00

问题


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:


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.



来源:https://stackoverflow.com/questions/1013245/how-can-i-draw-a-patternbrush-with-transparent-backround-gdi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!