简体   繁体   English

在wxWidgets中显示静态图像?

[英]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 of my tries succeed. 我试图在wxWidgets对话框中显示内存中的BMP图像已经好几天了,但我的尝试都没有成功。

First, I tried to create a wxStaticBitmap control in my dialog: 首先,我尝试在对话框中创建一个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));

I got no error, but the image didn't appear. 我没有错误,但图像没有出现。

Second, I tried to draw the image inside the EVT_PAINT of the dialog: 其次,我试图在对话框的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);
}

Now I got this debug alert: http://img266.imageshack.us/img266/9512/wxerror.jpg 现在我得到了这个调试警报: 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: 根据wxWidgets文档 ,您想要使用的wxBitmap构造函数具有以下签名:

 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. 假设一个RGB位图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM