Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this code not accepting this png images transparency?
    primarykey
    data
    text
    <p>I've isolated the cause of the problem to be the image, since the code seems to work with other png images with transparency. However, it doesn't seem to work with the one image I need it to. This would be of great help seeing as I'm trying to make a nice shaped window. </p> <p>The image:</p> <p><a href="http://i32.tinypic.com/f1xlj7.png" rel="nofollow noreferrer">alt text http://i32.tinypic.com/f1xlj7.png</a></p> <p>The code:</p> <pre><code>import wx class PictureWindow(wx.Frame): def __init__(self, parent, id, title, pic_location): # For PNGs. Must be PNG-8 for transparency... self.bmp = wx.Image(pic_location, wx.BITMAP_TYPE_PNG).ConvertToBitmap() framesize = (self.bmp.GetWidth(), self.bmp.GetHeight()) # Launch a frame the size of our image. Note the position and style stuff... # (Set pos to (-1, -1) to let the OS place it. # This style wx.FRAME_SHAPED is a frameless plain window. wx.Frame.__init__(self, parent, id, title, size=framesize, pos = (50, 50), style = wx.FRAME_SHAPED) r = wx.RegionFromBitmap(self.bmp) self.SetShape(r) # Define the panel and place the pic panel = wx.Panel(self, -1) self.mainPic = wx.StaticBitmap(panel, -1, self.bmp) # Set an icon for the window if we'd like #icon1 = wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO) #self.SetIcon(icon1) self.Show() # The paint stuff is only necessary if doing a shaped window self.Bind(wx.EVT_PAINT, self.OnPaint) self.Main() def OnPaint(self, event): dc = wx.PaintDC(self) dc.DrawBitmap(self.bmp, 0, 0, True) def Main(self): sizer = wx.GridBagSizer() button = wx.Button(self,-1,label="Click me !") sizer.Add(button, (0,1)) # What pic are we opening? pic_location = r"C:\Users\user\Pictures\CPUBAR\A4.png" # PNG must be png-8 for transparency... app = wx.App(redirect=0) # the redirect parameter keeps stdout from opening a wx gui window PictureWindow(None, -1, 'Picture Viewer', pic_location) app.MainLoop() </code></pre> <p>This is in Windows 7, btw. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload