]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ImageAlpha.py
Use ConvertAlphaToMask
[wxWidgets.git] / wxPython / demo / ImageAlpha.py
1
2 import wx # This module uses the new wx namespace
3 from Main import opj
4
5
6 #----------------------------------------------------------------------
7
8 msg = "Some text will appear in the image's shadow..."
9
10 class TestPanel(wx.Panel):
11 def __init__(self, parent, log):
12 self.log = log
13 wx.Panel.__init__(self, parent, -1)
14
15 self.Bind(wx.EVT_PAINT, self.OnPaint)
16
17
18 def OnPaint(self, evt):
19 dc = wx.PaintDC(self)
20 dc.SetBackground(wx.Brush("WHITE"))
21 dc.Clear()
22
23 dc.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, True))
24 dc.DrawText("Bitmap alpha blending (on wxMSW and wxMac only)",
25 25,25)
26
27 bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
28 if "__WXGTK__" in wx.PlatformInfo:
29 # try to make up for lack of alpha support a bit...
30 img = bmp.ConvertToImage()
31 img.ConvertAlphaToMask(220) #threshold below which alpha will be made fully transparent
32 bmp = img.ConvertToBitmap()
33
34 dc.DrawBitmap(bmp, 25,100, True)
35
36 dc.SetFont(self.GetFont())
37 y = 75
38 for line in range(10):
39 y += dc.GetCharHeight() + 5
40 dc.DrawText(msg, 200, y)
41 dc.DrawBitmap(bmp, 250,100, True)
42
43
44
45 #----------------------------------------------------------------------
46
47 def runTest(frame, nb, log):
48 win = TestPanel(nb, log)
49 return win
50
51 #----------------------------------------------------------------------
52
53
54
55 overview = """<html><body>
56 <h2><center>Images with Alpha</center></h2>
57
58 wxMSW and wxMac now support alpha channels of supported image
59 types, and will properly blend that channel when drawing a
60 bitmap. It is not supported yet on wxGTK, (if you would like to
61 change that please submit a patch!)
62
63 <p>On wxGTK this demo turns the alpha channel into a 1-bit mask, so
64 yes, it looks like crap. Please help us fix it!
65
66 </body></html>
67 """
68
69
70
71 if __name__ == '__main__':
72 import sys,os
73 import run
74 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
75