在wxWidgets中显示静态图像?

发布于 2024-09-01 17:20:40 字数 1176 浏览 2 评论 0原文

我已经尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言月老 2024-09-08 17:20:40

您的位图未正确加载。根据 wxWidgets 文档,您的 wxBitmap 构造函数想要使用具有以下签名:

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

所以你最终应该得到类似的结果:

wxBitmap(MyLogo, 200, 62, 3)

假设一个 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:

 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文