Display static image in wxWidgets?
It's been days for me trying to display a BMP image from memory in a wxWidgets dialog, but none o开发者_高级运维f my tries succeed.
First, I tried to create a wxStaticBitmap control in my dialog:
// in class declaration inside header file
wxStaticBitmap *ibitmap;
// in wxDialog constructor
// MyLogo is an array of `unsigned char`
// contains the bitmap file (Yes, the bitmap file, with BMP header)
ibitmap = new wxStaticBitmap(mainPanel, 4000, wxBitmap(MyLogo, wxBITMAP_TYPE_BMP, 200, 62), wxPoint(10, 10), wxSize(200, 62));
I got no error, but the image didn't appear.
Second, I tried to draw the image inside the EVT_PAINT of the dialog:
// in the class declaration inside header file
wxBitmap *ibitmap;
// in the events declaration
EVT_PAINT(OnPaint)
// in wxDialog constructor
ibitmap = new wxBitmap(MyLogo, wxBITMAP_TYPE_BMP, 200, 62);
// event method implementation
void MyDialog::OnPaint(wxPaintEvent &event)
{
wxPaintDC dc(this);
dc.DrawBitmap(*ibitmap, 10, 10);
}
Now I got this debug alert: http://img266.imageshack.us/img266/9512/wxerror.jpg
and the debugger stopped at this line:
// dc.h Ln 271
{ DoDrawBitmap(bmp, x, y, useMask); }
Anyone please point me out?
Your bitmap is not being loaded correctly. According to the wxWidgets docs the wxBitmap
constructor you're wanting to use has the following signature:
wxBitmap(const char bits[], int width, int height, int depth=1)
So you should end up with something like:
wxBitmap(MyLogo, 200, 62, 3)
Assuming an RGB bitmap.
精彩评论