views:

181

answers:

1

Hello there,

It's been days for me trying to display a BMP image from memory in a wxWidgets dialog, but none of 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?

+1  A: 

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.

heavyd
I'm 100% sure the image is a valid 24-bit bitmap converted into byte array.
djzmo
**100%**?? In the error dialog you show the call to `dc.DrawBitmap` is asserting on `bmp.Ok()`, meaning whatever bitmap `dc.DrawBitmap` was asked to draw, is **not** OK.
heavyd
@djzmo: When in doubt, step through the wxWidgets code with a debugger. I have found many undocumented exceptions using this method (such as undocumented items in wxDbTable).
Thomas Matthews
Right - it may be a correct array, but notice how heavyd's code does NOT have the wxBITMAP_TYPE_BMP parameter? That parameter is when you are loading a bitmap from a file, but you have a memory chunk so you don't need it
RyanWilcox