wxBitmap

From WxWiki
Jump to: navigation, search
Official Classes SmallBlocks.png Archive Containers Controls Data Structures Database Date & Time Debug Device Contexts Dialogs Document & Views Drag & Drop Events Filesystem Frames Graphics Grid Cell Help HTML Logging Miscellaneous Networking Printing Sizers Streams Threading Windows

This class encapsulates the concept of a platform-dependent bitmap, either monochrome or colour or colour with alpha channel support.

If you need direct access the bitmap data instead going through drawing to it using wxMemoryDC you need to use the wxPixelData class (either wxNativePixelData for RGB bitmaps or wxAlphaPixelData for bitmaps with an additionally alpha channel).

wxBitmap::SetWidth() cannot be used to resize a bitmap: is is only used by wx itself to construct a new Bitmap. You might want to use wxImage::Rescale() instead.

Working with bitmaps before the first wxApp object is created

It is said working with Bitmap objects before you've created your first wxApp object will cause segfaults on some systems.

In other words, don't use things like 'wxBitmap myBm("foo.bmp");' as globals. Instead, create them in the context of a member function (Frame or View level works fine, but not App).

This is because if the underlying code encounters an error, it tries to log it; the default place to log to (if you don't have a LogWindow up) is a MessageBox; if there's no Frame object in memory space yet, the MessageBox ctor fails, throwing; systems catches, and seg-faults.

Win32 bmp LoadFile() vs wxIcon

Note also that a Win32 .bmp will *not* correctly '.LoadFile()' into a wxBitmap ('unrecognized file format'), but *will* correctly load into a wxIcon (v 2.4.x). And, of course, that wxICON(xxx) only works on .xpm files.

Drawing transparent bitmaps to a DC

If you want to wxDC::DrawBitmap a bitmap with transparent pixels, remember to set the 4th argument ('transparent') to TRUE (the default is FALSE). Bitmaps suitable for alpha-blending during wxDC::DrawBitmap must be in RGBA format.

High-colour bitmaps

If you're using high-colour bitmaps, you'll need to call wxSystemOptions::SetOption(wxT("msw.remap"), 0); to switch off the remapping that wxWidgets does to make the tool colours match the current system colours. This remapping is only relevant for 16-colour tools, and messes up high-colour tools.

You'll need to include wx/sysopt.h to access wxSystemOptions.

can't find wxBITMAP_STD_COLOURS in .rc

If your compiler complains that it can't find wxBITMAP_STD_COLOURS in your .rc files, include wx/msw/wx.rc in your project. When using bakefiles, make sure you specify <win32-res> E.G. <win32-res>toolbar.rc</win32-res>

See Also