wxpython 之 GDI 画刷Brush(三)
2013-01-19 10:20
302 查看
画笔是在区域中填充的绘图工具。它用于绘制矩形、 椭圆等。 它有一种颜色和样式属性。
一. dc.SetBackground(brush) 利用该方法,保持控件的背景色与父窗口被景色一致。
具体使用方式:
1. 首先获得被景色的画刷,brush = self.GetBackgroundBrush(dc)
2. 在OnPaint方法中,绘制一致的被景色。
二. 利用wx.GCDC绘制半透明效果。普通的DC不带透明效果。
三. DrawBitmp在dc上画透明背景png图像及绘制disable样式的效果。
运行效果:
四. region区域绘图。
运行效果:
一. dc.SetBackground(brush) 利用该方法,保持控件的背景色与父窗口被景色一致。
具体使用方式:
1. 首先获得被景色的画刷,brush = self.GetBackgroundBrush(dc)
def GetBackgroundBrush(self, dc): colBg = self.GetBackgroundColour() brush = wx.Brush(colBg, wx.SOLID) myAttr = self.GetDefaultAttributes() parAttr = self.GetParent().GetDefaultAttributes() myDef = colBg == myAttr.colBg parDef = self.GetParent().GetBackgroundColour() == parAttr.colBg if myDef and parDef: if wx.Platform == "__WXMAC__": brush.MacSetTheme(1) # 1 == kThemeBrushDialogBackgroundActive elif wx.Platform == "__WXMSW__": if self.DoEraseBackground(dc): brush = None elif myDef and not parDef: colBg = self.GetParent().GetBackgroundColour() brush = wx.Brush(colBg, wx.SOLID) return brush
2. 在OnPaint方法中,绘制一致的被景色。
if brush is not None: dc.SetBackground(brush) dc.Clear()
二. 利用wx.GCDC绘制半透明效果。普通的DC不带透明效果。
## #details # 绘制带透明背景的矩形区域 def __DrawAlphaRectangle(self, dc): try: gcdc = wx.GCDC(dc) except: gcdc = dc alphaColor = wx.Color(0, 0, 0, 128)#半透明 brush = wx.Brush(alphaColor) gcdc.SetBrush(brush) gcdc.DrawRectangle(40, 40, 40, 50) def __DrawSimpleRectangle(self, dc): alphaColor = wx.Color(0, 0, 0, 128)#半透明,但是在该dc下不会起效果 brush = wx.Brush(alphaColor) dc.SetBrush(brush) dc.DrawRectangle(100, 100, 40, 50)
运行效果:
三. DrawBitmp在dc上画透明背景png图像及绘制disable样式的效果。
def __DrawPNG(self, dc): bmp = wx.Bitmap('earth.png') dc.DrawBitmap(bmp, 0, 0) image = wx.ImageFromBitmap(bmp) imageutils.grayOut(image) dc.DrawBitmap(wx.BitmapFromImage(image), 240, 0)
运行效果:
四. region区域绘图。
def __DrawInClippedRegion(self, dc): region = wx.RegionFromPoints(((20, 20),(40, 20), (40,0), (100, 200), (20,200))) dc.SetClippingRegionAsRegion(region) #在clipregion 里面作图像 alphaColor = wx.Color(0, 0, 0, 128)#半透明,但是在该dc下不会起效果 brush = wx.Brush(alphaColor) dc.SetBrush(brush) dc.DrawRectangle(0, 0, 500, 500) dc.DestroyClippingRegion()
运行效果:
相关文章推荐
- GDI+ for VCL基础 -- 画刷之SolidBrush
- C#GDI+基础(二)画刷详解
- GDI-Brush
- 创建位图画刷(CreatePatternBrush)
- LinearGradientBrush 线性渐变画刷的使用
- 黑马程序员_学习日记84_814WP7开发(画刷Brush、变换Transform、样式、换肤)
- 一点一滴掌握WPF应用系列 - 画刷使用(1):SolidColorBrush、LinearGradientBrush、RadialGradientBrush
- C# GDI绘图之——画笔和画刷
- d3力导向图,Zoom后brush画刷选取node节点不正常
- c#线性渐变画刷LinearGradientBrush
- C# GDI HatchBrush 对照
- GDI+学习及代码总结之------画刷Brush
- GDI+ for VCL基础 -- 画刷之LinearGradientBrush
- 再学 GDI+[18]: FillEllipse、TGPHatchBrush(阴影画刷)
- C# GDI+入门(2)-画刷的使用
- C# GDI HatchBrush 对照
- wpf SilverLight 中的画刷 brush
- (转载)VS2010/MFC编程入门之五十一(图形图像:GDI对象之画刷CBrush)
- GDI+ for VCL基础 -- 画刷之PathGradientBrush