GTK图像突然不会刷新任何错误或警告
gtk image suddenly do not refresh without any errors or warnings
我开发了一种工具来从相机捕获图像,并在窗口中显示捕获的图像。GUI窗口基于GTK 2.4。首先,该工具正在校正,并从相机捕获图像,并实时显示在窗口上。过了一会儿,图像突然不在窗户上刷新,但仍然是从相机捕获的。没有错误或警告。有人曾经遇到过这样的案子吗?谢谢。
Ubuntu 18.04,GTK 2.4
// loop to call the following code to refresh the image on the window
pixbuf_ = Gdk::Pixbuf::create_from_data(
final_img_buf_.data, Gdk::COLORSPACE_RGB, false, 8, final_img_buf_.cols,
final_img_buf_.rows, static_cast<int>(final_img_buf_.step));
gtk_image_.set(pixbuf_);
编辑在2019-02-27感谢你的回复。我已将GTK升级到GTK 3,但这仍然出现。
// loop to call the following code to refresh the image on the window
pixbuf_ = Gdk::Pixbuf::create_from_data(
final_img_buf_.data, Gdk::COLORSPACE_RGB, false, 8, final_img_buf_.cols,
final_img_buf_.rows, static_cast<int>(final_img_buf_.step));
// ensure the image is normally updating
//std::this_thread::sleep_for (std::chrono::milliseconds(30));
gtk_image_.set(pixbuf_);
Glib::RefPtr<Gdk::Pixbuf> pixbuf = gtk_image_.get_pixbuf();
std::string filename = std::string("./debug/") + std::to_string(CurTimestampMicrosecond()) + std::string(".jpg");
pixbuf->save(filename, "jpeg");
afther运行一段时间,窗口不再刷新图像,但是该图像仍然可以纠正。
编辑2019-02-28
// The initialization code
gtk_main_.reset(new Gtk::Main(argc, argv));
ctrl_window_.reset(new CtrlWindow(screen, ctrl_rect)); // inherited from Gtk::Window
thread_ = std::thread([this]() {
Gtk::Main::run(*ctrl_window_);
}
看起来g_timeout_add
和可能由于其他事件源的处理而可能会延迟g_idle_add
,因此在需要精确时机的上下文中并不是最佳的,例如在帧之前将图像绘制到屏幕上更新。我注意到在2D图形上下文中使用g_timeout_add
,如果应用程序无法在指定的FPS处加载帧,则完全冻结了该应用程序。
gtk_widget_add_callback()
可能更适合您的需求,因为它会尽快绘制缓冲区,而无需挂起,基本上为您进行了混乱的同步。
相关文章:
- 类和构造函数中的函数根本不起作用,并且不返回任何错误
- boost::p rogram_options 在指定意外的位置参数时不报告任何错误
- Antlr cpp 运行时 任何错误的指针转换?
- 我可以使用 try catch 语句来捕获任何错误而不是具体错误吗?
- 为什么 C++ 中的分号在插入代码开头时不显示任何错误?
- 如何修复任何错误
- 为什么<<低;和 cout<<v.begin;单独给出错误,但 cout <<(lower.begin());没有给出任何错误,并使代码易于编译
- 我是否需要处理以下代码中的任何错误情况?
- 我的代码在构建时没有任何错误,但无法正常工作
- 由于错误,c ++代码无法在Visual Studios上运行,但不显示任何错误
- ROS2 COLCON构建未在Windows中显示任何错误消息
- 如何调试 gRPC 服务器崩溃而没有任何错误
- 尝试使用类,但未打印任何内容.不会生成任何错误.我错过了什么吗?
- 代码没有任何错误,但什么也不在命令提示中
- GTK图像突然不会刷新任何错误或警告
- STL 中是否有任何错误代码异常
- 用“ strcpy”在2D数组中删除(字符)的一行(字符)时是否存在任何错误
- Oracle ODBC 插入失败,没有任何错误诊断
- 检查输入的文件是否有任何错误
- 带有绝对路径的LoadLibrary返回不正确的HMODULE,没有任何错误