Transparent images in wxPython {Mask}

 ̄綄美尐妖づ 提交于 2019-12-13 02:37:50

问题


I'm tired of searching this on the net and i cant get it to work. I need to turn green pixels into transparent ones, no half transparency needed. Wondering how can effectively use a mask, but the wx docs doesn't help much really...

Hope someone can give me a tip, regards.

Related code

png = wx.Image('sun2.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
#print png.HasMask() fail
png.SetMaskColour((0,255,0))
#mask=wx.Mask(png,wx.Colour(0,255,0))
#png.SetMask(mask)
imge=wx.StaticBitmap(self, -1, png, (10, 5), (png.GetWidth(), png.GetHeight()))

回答1:


You can check the wxpython docs and demo.
In the demo Mask they show a method to use a transparent mask:

    # Now we'll create a mask in a bit of an easier way, by picking a
    # colour in the image that is to be the transparent colour.
    self.bmp_withcolourmask  = images.TestStar2.GetBitmap()
    mask = wx.Mask(self.bmp_withcolourmask, wx.WHITE)
    self.bmp_withcolourmask.SetMask(mask)


来源:https://stackoverflow.com/questions/12029960/transparent-images-in-wxpython-mask

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