在wxWidgets中显示静态图像?

问题描述:

我试图在wxWidgets对话框中显示内存中的BMP图像,但我的尝试都没有成功。在wxWidgets中显示静态图像?

首先,我想在我的对话框创建wxStaticBitmap控制:

// 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)); 

我没有错误,但图像没有出现。

其次,我极力把对话框EVT_PAINT内的图像:

// 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); 
} 

现在,我得到这个调试警告: http://img266.imageshack.us/img266/9512/wxerror.jpg

和调试器停在这行:

// dc.h Ln 271 
{ DoDrawBitmap(bmp, x, y, useMask); } 

任何人请指出我?

您的位图未正确加载。根据你想要使用wxWidgets docswxBitmap构造具有以下特征:

wxBitmap(MyLogo, 200, 62, 3) 

假设一个RGB位图:

wxBitmap(const char bits[], int width, int height, int depth=1) 

所以,你应该喜欢的东西而告终。

+0

我100%确定图像是一个有效的24位位图转换成字节数组。 – 2010-05-19 06:37:42

+1

** 100%** ??在错误对话框中,显示调用'dc.DrawBitmap'在'bmp.Ok()'上声明,这意味着要求绘制任何位图'dc.DrawBitmap',而不是** OK。 – heavyd 2010-05-19 10:48:59

+1

@djzmo:如果有疑问,请使用调试器浏览wxWidgets代码。我发现了许多使用此方法的未记录异常(例如wxDbTable中的未记录项目)。 – 2010-05-19 16:21:03