在wxWidgets中显示静态图像?
我已经尝试在 wxWidgets 对话框中从内存中显示 BMP 图像已经好几天了,但我的尝试都没有成功。
首先,我尝试在对话框中创建一个 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); }
有人请指出我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的位图未正确加载。根据 wxWidgets 文档,您的
wxBitmap
构造函数想要使用具有以下签名:所以你最终应该得到类似的结果:
假设一个 RGB 位图。
Your bitmap is not being loaded correctly. According to the wxWidgets docs the
wxBitmap
constructor you're wanting to use has the following signature:So you should end up with something like:
Assuming an RGB bitmap.