python - Drawing a semi-transparent rectangle on a jpeg file with wx.Bitmap -


i need load jpeg->draw semi-transparent rectangle->save jpeg file using wx.bitmap of python wx package. rectangle appears opaque.

i'm using windows 7 32bpp. checked , try "docs , demos\demo\alphadrawing.py" wx demo, , works well. draws correctly on wx.panel semi-transparent rectangle.

i checked on internet solution problem, none of solutions worked.

i created more simple example, minimize possibilities of error, , still didn't work. load jpg->draw semi-transparent rectangle->save jpg file

wimg = wx.image(r"n:\images\wallpapers\processed\a.jpg", wx.bitmap_type_jpeg) print wimg.hasalpha() wimg.initalpha() print wimg.hasalpha() bmp = wimg.converttobitmap() print bmp.hasalpha() dc = wx.memorydc(bmp) r, g, b = (34,  34,  34) dc.setpen(wx.pen(wx.colour(r, g, b, wx.alpha_opaque))) dc.setbrush(wx.brush(wx.colour(r, g, b, 128))) dc.drawrectangle(100, 300, 200, 200) bmp.savefile(r"n:\images\wallpapers\processed\b.jpg", wx.bitmap_type_jpeg) 

the print results are: false/true/true , still output it's opaque rectangle

i known jpeg doesn't has alpha channels, don't want 32bpp jpeg. output show rectangle blended background.

bitmap files have no alpha channel. must load png file use transparency.

"unlike rgb data, not images have alpha channel , before using getalpha should check if image contains alpha channel hasalpha. note images loaded png files transparency information have alpha channel."

http://www.wxpython.org/docs/api/wx.image-class.html


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -