wxWidgets 通过刷新绘制图像

标签 wxwidgets

我有一个从相机接收图像的应用程序。该应用程序是使用 wxWidgets 编写的,我尝试通过创建绘制事件来显示图像。每次获得新图像时,我都会在面板上调用“刷新”。

大约半分钟到一分钟后,它停止响应绘画事件。我一直在查看 wxWidgets Wiki,但我似乎找不到它为什么这样做(我相信我允许 GUI 事件循环运行)。

当我更改窗口大小时,它会正常刷新图像(因此不会阻止所有绘制事件)。

知道为什么会发生这种情况吗?

我不确定这会有多大帮助,但这是绘制事件的代码。

void ImageViewer::onPaint(wxPaintEvent &event)
{
    wxBufferedPaintDC dc(this);

    cv::Mat buffer;
    static int count = 0;
    std::cout << "drawing " << ++count << std::endl;
    {
        // doing stuff in a lock
    }
    // it doesn't ever seem to get stuck in the lock
    std::cout << "finished" << std::endl;

    // buffer is an object with the image data buffered
    wxImage img(buffer.rows,
                buffer.cols,
                buffer.data, true);

    wxBitmap bmp(img);
    dc.DrawBitmap(bmp, 0, 0);
}

每次获取新图像并更改缓冲区时,我都会调用刷新(更改缓冲区是在锁内完成的)。

最佳答案

可以尝试以下方法:在调用 Refresh() 后立即调用 Update()。

刷新会使窗口无效并使绘制请求排队。更新强制立即重新绘制任何无效的矩形。

关于wxWidgets 通过刷新绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5986638/

相关文章:

python - 避免在笔记本中单击退出 wxPython TreeCtrl

c++ - 没有来自 wxWidget 应用程序的 cout,但是使用 Eclipse 它工作正常

c++ - 如何制作一个可以在 C 库中用作回调的 wxWidget 方法?

c++ - 如何使用wxThread的概念在wxListCtrl中显示大数据

c++ - 从辅助线程启动可执行文件

c++ - wxWidgets 在调用 wxApp::OnInit 之前退出

python - 如何撤消 wx.grid.Grid.SetColAttr?

python - 使用 python 2.7.10 的 matplotlib.pyplot 和 wx 导入问题

python - 在二郎 : How do I expand wxNotebook in a panel?

c++ - 如何单击 wxWidgets 处理程序 OnClose 中的按钮?