Cannot create wx.Bitmap from an wx.Icon in wx 4.0.0a1

38 views
Skip to first unread message

Matt Kimberling

unread,
May 2, 2017, 11:24:07 PM5/2/17
to wxPython-users
In wxPython 3.0 I could extract the icon from a .exe and create a bitmap by calling wx.BitmapFromIcon:
resourceIcons = win32gui.ExtractIconEx( path, 0 )
hIcon = resourceIcons[1][0] if smallIcon else resourceIcons[0][0]
iconInfo = win32gui.GetIconInfo( hIcon )
bitmapInfo = win32gui.GetObject( iconInfo[4] )
ico = wx.Icon( path, wx.BITMAP_TYPE_ICO, bitmapInfo.bmWidth, bitmapInfo.bmHeight )
ico.SetHandle( hIcon )
bitmap = wx.BitmapFromIcon( ico )
for i in resourceIcons:
for h in i:
win32gui.DestroyIcon( h )
return bitmap

I've been unable to get this to work since upgrading to Phoenix.

The "Classic vs Phoenix" document says the equivalent of BitmapFromIcon is the wx.Bitmap constructor but I've been unable to get that to work.  The wx.Bitmap documentation implies that you could pass the filename to its constructor but I've been unable to get that to work.

Thanks for any help,
 Matt

Matt Kimberling

unread,
May 3, 2017, 2:08:13 PM5/3/17
to wxPython-users
I looked at the source code this morning and saw there is a member function for this that isn't (yet) in the docs:

bitmap = wx.Bitmap().CopyFromIcon( ico )

Robin Dunn

unread,
May 8, 2017, 6:09:13 PM5/8/17
to wxpytho...@googlegroups.com
Matt Kimberling wrote:
I looked at the source code this morning and saw there is a member function for this that isn't (yet) in the docs:

bitmap = wx.Bitmap().CopyFromIcon( ico )


Reply all
Reply to author
Forward
0 new messages