当前,在我的项目中,我们使用的是gtkmm pixbuf create_from_file create_from_date ,它们在高分辨率图像的情况下会挂起整个GUI 1-2秒,并且在为屏幕加载多个图像时会变得非常慢。对于上述两个功能,是否可以在gtkmm中异步加载图像?我可以在gtk中找到用于异步加载图像的方法,但不能在gtkmm中找到。一个示例将很有帮助,因为我找不到与之相关的任何内容。

  if(!imageName.empty())
  {
    //Load image in pixbuf
    picPixBuff = Gdk::Pixbuf::create_from_file(imageName);

    picPixBuff = picPixBuff->scale_simple(150,35,Gdk::INTERP_BILINEAR);

   }

我经历了这个。
相关问题-How to load a widget as a different thread in gtk? (vala)

最佳答案

docs。该示例完全符合您的要求。
这些是神奇的功能。这个例子很容易理解。

// notify() is called from ExampleWorker::do_work(). It is executed in the worker
// thread. It triggers a call to on_notification_from_worker_thread(), which is
// executed in the GUI thread.
void ExampleWindow::notify()
{
  m_Dispatcher.emit();
}

void ExampleWindow::on_notification_from_worker_thread()
{
  if (m_WorkerThread && m_Worker.has_stopped())
  {
    // Work is done.
    if (m_WorkerThread->joinable())
      m_WorkerThread->join();
    delete m_WorkerThread;
    m_WorkerThread = nullptr;
    update_start_stop_buttons();
  }
  update_widgets();
}

关于c++ - gtkmm中的图像异步加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62428251/

10-11 22:47
查看更多