]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tests/test_gcDrawBitmap.py
4 ##import os; print "PID:", os.getpid(); raw_input("Press Enter...")
6 class TestPanel(wx
.Panel
):
7 def __init__(self
, *args
, **kw
):
8 wx
.Panel
.__init
__(self
, *args
, **kw
)
9 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
11 self
.SetBackgroundColour("white")
14 self
.bmp1
= getTest2Bitmap()
16 # give this one a mask
17 self
.bmp2
= getTest2Bitmap()
18 self
.bmp2
.SetMaskColour("blue")
20 # now make one in which the opaque pixels from #2 are made
21 # partially transparent
22 bmp
= getTest2Bitmap()
23 bmp
.SetMaskColour("blue")
24 img
= bmp
.ConvertToImage()
26 self
.bmp3
= img
.ConvertToBitmap()
27 pixelData
= wx
.AlphaPixelData(self
.bmp3
)
29 raise RuntimeError("Failed to gain raw access to bitmap data.")
30 for pixel
in pixelData
:
31 red
, green
, blue
, alpha
= pixel
.Get()
33 pixel
.Set(red
, green
, blue
, 128)
35 ##self.bmp3 = wx.Bitmap("bitmaps/toucan.png")
38 def OnPaint(self
, evt
):
39 gc
= wx
.GraphicsContext
.Create(wx
.PaintDC(self
))
41 # draw some lines to use as a background
42 gc
.SetPen(wx
.Pen("navy", 1))
45 while x
< sz
.width
*2 or y
< sz
.height
*2:
46 gc
.StrokeLine(x
,0, 0,y
)
51 for bmp
in [self
.bmp1
, self
.bmp2
, self
.bmp3
]:
52 # draw the plain bitmap
53 gc
.DrawBitmap(bmp
, 20,20,
54 bmp
.GetWidth(), bmp
.GetHeight())
56 # translate and scale by using the w, and h parameters
58 gc
.DrawBitmap(bmp
, 20,20,
59 bmp
.GetWidth()*1.5, bmp
.GetHeight()*1.5)
61 # translate and scale using Scale()
65 gc
.DrawBitmap(bmp
, 20,20,
66 bmp
.GetWidth(), bmp
.GetHeight())
69 # translate and rotate
72 gc
.Rotate(math
.radians(45))
73 gc
.DrawBitmap(bmp
, 20,20,
74 bmp
.GetWidth(), bmp
.GetHeight())
77 # move back to the left side, and down a row
78 gc
.Translate(-350, 150)
83 frm
= wx
.Frame(None, size
=(500,500))
90 #----------------------------------------------------------------------
91 from wx
import ImageFromStream
, BitmapFromImage
92 from wx
import EmptyIcon
98 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00@\x00\x00\x00@\x08\x02\x00\
99 \x00\x00%\x0b\xe6\x89\x00\x00\x00\x03sBIT\x08\x08\x08\xdb\xe1O\xe0\x00\x00\
100 \x08\xeeIDATh\x81\xd5\x9aKl\x1b\xd7\x15\x86\xbf\xcb\xe1\xf0\xa1\xa1(\x91\x92\
101 (\xc9\x96T\xd9q,Ar\xdc\xbarb\xa0F\xd1\xb8\x81\xd3\xa0\xb0\x03gS\x04\xf0>\xd3\
102 \x14\x857Aw\x0e\x8a\x00\xc9*\xe821h\x04\xe8&\x01\xb2k\x10\x07E\xd0\x00u\xb2p\
103 \x16\x85\x1f\x01\x92\xc8\xae\xe3\x1a\xb2\xe5\xca\xa2%\xd3\xa6D\x89\xb4\x863\
104 \xb7\x8b\xa1\xa8!9\x1c\x0ei\xcaA\xff\x15E\xce=\xf7\xff\xcf9\xf71\xe7H\x80\
105 \xe4\xff\x19\xc1N\x19\x923\xa2\xa5\xe7\xc5\xa5\xce8NT"\xe0\xcd\xa0~\xbeV\x19\
106 \xfb\xb7\xdc\xdap\x9f\x02\xca\xb8\xe8\xf8|\xf0q\xe6\xad\xe3\xd1\xae\x8c\xb2\
107 \x00\xbf\xec\xc5k[\x7f\xca\xb3\xe5\x0f\x9dS\xd2\x86\x0c\x7f\x02l\xc7;\xd9;a+\
108 \xa9\x96aJ\x0c\x89\xe9\xe0\xa3]\xf1\xcdI\xb4 \xa3\x99\x00o\xeaNl\x06d\xed\
109 \x00&\xe4M\xb2&k\x16\xa6\xe4\x17\xd7\x00\xbe\x16/\xdb\x0f(\x044\x82I\xc21T\
110 \x05\xa1 T\x02\n\x81-;\x07\xc1w4<\x05\\l\xe6\xf5\xcd_M\xac"\xe6\n\xc6\xb0\
111 \xfc\xd0c\xb27\xc5\x01@%\x90 <J,I8\x8c\xa2\x11\xec#\x12G\x8d\xa0\x94eljp\xa1\
112 [\xa7\xaa\xb1\x80F\xec\xeb\xa8+\xf2\x03\x0f\xd2\x8dpJL\xc7P#(\t\xc2\xe3t\x8f\
113 \xa2\r\xd2U\x96!?\xf0^WN\x19\r\x04x\xfb^\xbc\xf68\xd4\x9dxE\x8ck\x04\x87\xe8\
114 \x1aE\xdbM\xbc"C\x93\x7f\xf5\xa9\xa1\xdd\x83L\x9eU\xda\x1cY\x85\xbf\xc99\xe0\
115 \xb8\x18[d}\x9e5[\xc6\x18\xb1\x9f\x82!Q}l\x8d\x02dk\xee\xdf6\x1c\x17c=\x84\
116 \x86\xe8\x1a\'\xf6G\xf9\xf5\xc2~\x06T/\rv\x10\x02\r\x7f\x7f\xe28\'o\xdf\xa3\
117 \xf0o\x1e^b\x19\x98-\xb2d`4\xdb\x8a\xea\x04\xfcH\xee\xb7\xf1\x0f\xf9\xdfuJ\
118 \x8b\xac\x03\x17\xd7\x9bh\xb0\x13\xc7\xf7\x1a\xa8fo\x9a\x18\x06\x96E \x80\
119 \xaa\xa2tbA\xd86\xcf\xad-\xfcV\x1b\x06f\x0b\xe5\xef\xa7\xf0\xca%\x7f\x02\xaa\
120 \xd9\x1b\x06\x0f\x1e\xb0\xb4D\xb1\x88\xa618HO\x0f\x81\xc7KF\xcbbe\x85L\x86\
121 \xb55\xde\xfb\xee.\x90)\x81\x0f\r>\x048\xd8\x0b\x91\xb6?|\xf5\x95>;\xcb\xca\
122 \n##\xcc\xcc\x10\x8d\x12\x89\xb4I\xbdb\xf3\xda5\xfd\xf2e\xee\xdc!\x1e\xe7\
123 \xfe}\xd6M\xee\xd1\\C3\x01n\xec\x81\xd9Y.]\xa2X\xa4T\xe2\xe9\xa7\xb1\xac\xaa\
124 Av2\x98f\xad1E\xf1\xca\xb7\xc9\xc9\xf4;\xef\xe8W\xaf\x96}\x91\xfe\x17\x7f8\
125 \xc4R\x89\xd9\x02\x02\x14AP\xd0\x1f$P\xad\xc1S@\xe3U{\xef\x1e\xcb\xcbHI\xa1\
126 \x80a 7\xd7\x99iR,\xb2\xb2\xc2\xfd\xfb\xac\xadUiP\x144\x8d\xbe>\xe2q"\x11w\
127 \x19\x85\x02\xab\xab\xe4\xf3\xdc\xbb\xc7\xea*\x7f\xcfp|\x88\xa5\x12\xd7\x8ah\
128 \x01\x92\nZ\x00\xadz`\x9b\x07\x99\xab\x83\x9d!r\xe2\xf4i\x1dPU\x12\t\xc6\xc7\
129 \x19\x1bcx\x98D\x02Uuy\xd8\x0e\xa6m_J,\xc9\x06,\x97\x98\xdb\xe0\'\x1b\xa4T\
130 \xa2\x81\xaa 4\x16\xd0\xca\xa6\x19\x8b\xb9S\xb7\xf1\xf6\xdbi\xe0\xc4\t]\xd3\
131 \xb8u\x8b\xf1q\xa6\xa7\x99\x98``\xc0]\x83\x13\xe7W9\xd2\xcd#\x8bE\x83\x9b\
132 \x8f\x18\r\x11\xaf\x0eB\x07\xde\x89\x0f\x1f\xf6b_\xc1\'\x9f\xa4\x8f\x1e\xd5s\
133 \xb9rv\x01\xc1 \xfd\xfd\xbe\xa60!g2o0\xbf\xc1`u\x10\x1al~\xbe\xddo{\xd7\'\
134 \xbe\xf8"](\xb0\xb8\xc8\xb5k|\xff=w\xefR(4\x1fu~\x15Kn\x05!cP\xb0\xc0y\x95\
135 \xe8T\x81\xa0\x82\x13\'\xf4\x93\'u\xd7\x9fT\x15\xc3`y\x99\xb99n\xdffe\xc5\
136 \xafMg\x10V,\xacM\xcan\x11h%\xfb\xed\x05Z\xc1\x993\xfa[o\xe9\x07\x0ep\xe8\
137 \x10\x9f~\xaa_\xb9R+\xe3\xf3\xcf\xd3\xaa\xca\xc6\x06\x8b\x8b\xdc\xbcI&\xe3k\
138 \x96J\x102\x06\xb76\xc8\x96\xd8\xd8\x14\xd0\x815p\xe1\x82\xbe\x7f?\xe1p\xf9x\
139 \xce\xe7\x81\xad\x1d\xd30tU\xadJ\xb3\xde^\xb2Yr9\xe6\xe7\x99\x9foa"\x13\xf2\
140 \x16\xd9\x12y\x8b\xca\xc1S\x8e\xc0\xe3\x16g\x04\xaaJ_\x1fO=\xc5\xbe}\xec\xdb\
141 \xc7\x9e=\xa4Rh\x1a\xc1 RV\xc5\xe1\xe3\x8f\xd3\x8a\xc2\xa3Gd2\xdc\xba\xd5\
142 \xc2,\x96\xa4$)J\x1eY\x94\\# .\xd9\'R\x9b\x15+E\xf1{\xab\xb3\x05\xe4\xf3d\
143 \xb3\xadMa\xcar\xb9 o\x02\x16\xce+\xd8f\x10:So\xeb8\xce\xaf\x02\x94$\x0fL\
144 \xeel\xb0\xf3\xdb\xef`\x83\x1f\xeb\x85\xc64Q\x14b1\x92\xc9\x16\x07n.\x03\xc8\
145 \x83\xc5\x93\x11Ps\xc5x\xf5U\xbdT"\x18$\x91`d\xa45S\x96\xc4\x94\xfc\xf9\xeei\
146 0\xedr\xc4\xb6\x0b\xa8\xbf =|\x88e\x11\n\x91H00\xf0\xb8\xf6\xb7W\x80\xeb\xf5\
147 \xce0PU\x92I\x86\x86H$Z\xb6y.w\xdc\xf9g\xc7\xfa\x035ht3}\xe1\x05]U\x19\x18`b\
148 \x82\xc9I\xbfw!\x1b_\xe6\x9f\xaf\xffr[\x044b\xff\xe2\x8bz(D\x7f?\x93\x93\xcc\
149 \xcc01\xd1N\x04j\xd0y\x01\x8d\xd8\xbf\xf4\x92\xde\xdb\xcb\x8e\x1d\xec\xda\
150 \xd5\xc2u\xba):,\xc0\x95}%m\xf6\xeee\xdf>v\xed\xf2z\xa1i\x86\x00(\xa0\x82b\
151 \x1fY\x9d\x14\xe0\xcd~j\x8a\x99\x19&\'I&\x1b\xbeR\xfa\x80\x021HB\xcc\xde\x81\
152 j\x05\x08!\xa5l~\x18G\xa3\xc4b\xe5\x0f\xaa\x8ah0\xe2\xd81]\x08\xfa\xfa\xcaI?\
153 5\xd5$m<\xcc\n\xf1<\xd8\x84\x130\x02\t\x08\xb9\x08\xf0\x89\xf1\xf1\xad\x0f\
154 \xf1x\xf9F"\xa5\xee\x0c\xc2\xbb\xef\xeaw\xee\x10\x0e3:\xea7\xe9]\xcdV\xa36\
155 \x02[M\xbe\n\xbc#`Y<|\xc8\xc2B\xf9\x1e\x96L\xb2c\x07\xbd\xbd[\x93\t\x91^_\
156 \xd7\x17\x16\xf8\xe1\x072\x19\xe2q\xc6\xc6\x18\x19!\x99\xf4bo\x9ad\xb3,,\x90\
157 \xcb\x95\x0f\xe9\xa1\xa1\xaaz\xd9\x91n\xbe\xcc\xff\x1a\xe2p\x00~\x03\xcf@\
158 \x17m\x1cdB\x10\x8d\x12\x8f\xa3ih\x1a\xf18\xd1hU\xac76\xf4\x95\x15r9L\x93X\
159 \x8c\xbe>R\xa9\xe6K\xd6.%I\x89\xa61<\xcc\xce\x9dtw\xd7F\xe0h\xf7?k\xdc\x8fk\
160 \ny,\x03;C2\x19}n\x8e\xeb\xd7\x01\xf6\xee%\x12!\x1cF\x88\xaaE\xfc\xfe\xfb\
161 \xfa\xe2"\x81\x00\xbbw\x93J\xd5V\xbe\\m\xde\xb8\xc1\xf5\xebH\xc9\x9e=\x84\
162 \xc3D\xa3[\xcf\x1c\xe9& \x08\x07xc\xf0\xc3\xbfd~\x07I{\x01\xb8\x0b\xf0\x9e\t\
163 \x18\x1cL\x9f9\xa3\x7f\xf3\r@\xa9D\x7f\xbf\x1d\x87\xaa-\xe8\xf2e\x96\x97\xcb\
164 kqr\xb2\xa1\x80z\x9bv.\xb1Y\xb3\xa8\x04A\x81\x1e\x85Q\x15\x18\x85x%\x02n)\
165 \x94\x16M\x1b\x9d\xd9,\xd9,KK\xe5\x12Z=\xbf\xe5eVW)\x14(\x95\xbc\xdc\xef\xc4\
166 \xeb\xaf\xa7\xedep\xe3\x067n\xf0\xe0\x01\x86\x01\x0e\xf7\x0f\xa9\xec\x0e\xb3\
167 \xb0\xff\x00lE\xa7A\x04\xd2Mv\xd2d\x92\x9e\x1e\x8aE\x82A\xf7\xba\xb4\x9d\x00\
168 \xfd\xfd\xa4R.\xd9\xdc\x08==H\x89\xa2\xd4\xee\xcb\x15\xf7\xdb\x85-\xa7\xdf\
169 \xeb\x04lR\xaf_\t\xce]rj\n(W\xa7\xeb\xf7\xbb\x8f>\xd2\xe7\xe6(\x95H\xa5\x98\
170 \x9a\xa2\xbf\x9fP\xc8\x9d\xb1\xd3\xa6]\xf1\xcefI&\xd9\xbb\xb7\xbc\xeek\xdcoW\
171 \xb5\x9ch\xbc\x06\xdc\x82`\xbf\x9e\xdb\xfd\x81\xbe\xber\x7f \x95"\x14*\xffdY\
172 \xe4rd2\xec\xd9\x83\x94\xc4b\x0c\x0c\x90HxE\xa0\xc6f\xa1@4\xba5* \x08\t\xfa\
173 \x83\x8c\x87\x18\x0b\x11\x0f\xd4V\xa7\xeb\xce\x81j\xde\xb2A\xb7\xc9\xa3C\xe3\
174 \xac\xad{\xd7\xd3\x9b\xda|!NH0\x10d:\xcas\x1a\xd3\x91ry\xddYCi\xb2\x0b\x89\
175 \xb3\xee\x1a<\n\x10\xfek\x13\xde\x03+\xec\xa7\xa2\xcct1\x11&Q\xd7\x1c\xc0\
176 \xcfA&\xb6\xbd\xb5\xe7\x02\'\xfb\x83]LE\x1a\xb6\x98|\xed\x0eOX\x837\xfb\x9a\
177 \x1a\x9c\xdf\xab\xc4\x13\xd3\xe0\xdf\xf76Z\xb8\x0b=\x01\rB\x1c\xed\n0\xa42\
178 \xed\x8f=\xad^\xe6\xb6U\x83\x10\xc7 \xf5Y\xee\x8d\x99.\x9e\xd3\xdc\xd9\xd7\
179 \xd7p[\xbf\x8d\x9e\xed\xbc\x8c\xe3\xbd\x08q\x12&\xe0Y\xf8\xd5/cL\xfb\xf0\xbd\
180 \x8d6_h\xc4Y\xb0\x90\xbfoo\xf4\x16^I\xa0\x05\x98\x88\xf0Y\xeeY\xd8\r\xa30\
181 \xf8\xb3\xab\xf9\xd2\xcfc\x8a\xbf"m\x93\x83\xac9\xda\x95q*EL!"H\x04\x19\x0f\
182 \xf1\xf2\x7f\xae\xc0 \xc4!\x02\x8a\xeb\x7f\x90\xb9\xf6\x00\\\xde\xc8Z\xd6\
183 \x00X`@\x11\xf9\'\xaf\xa7\xde\x1c\x06P\x05\x89 \xa3!\x92\n\xe1\x00Z\x80gf\
184 \x17*\xd4+\x0f\xd7kp\x15\xd0\xa1\xaaD\x00\xc2\xa0"\xde\x03\x0bN\xe5 \x0fYX\
185 \x83\xaa~\xf2\x85\x89\xc3\x8a(w\xadw~\x9b\x03\xc5Q&\xf1B\xa3\x16L\x87"P\x0f\
186 \xbd\x04F\r{\x07|\x91v\x06\xa1\x15\x01<\xb6\x06\xbd\x93mO9#<:`\xdbP\x9d\xee(\
187 {\x9a\xf5\xef\x1a\x08h\x9bD\xa7\xd97\xc5\xff\x00n\xb9j)\xe8*\xac\xf1\x00\x00\
188 \x00\x00IEND\xaeB`\x82'
190 def getTest2Bitmap():
191 return BitmapFromImage(getTest2Image())
194 stream
= cStringIO
.StringIO(getTest2Data())
195 return ImageFromStream(stream
)
197 #----------------------------------------------------------------------
199 if __name__
== '__main__':