如何显示几个图像(每个在单独的窗口)与CImg? [英] How to display few images (each in separate window) with CImg ?

查看:424
本文介绍了如何显示几个图像(每个在单独的窗口)与CImg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一个窗口中显示几个图像 - 使用CImg?

How can one display several images - each in one window - with the use of CImg ?

当我尝试这样的东西时

        cimg_library::CImg<unsigned char> image(s.c_str());
        cimg_library::CImgDisplay main_disp(image, s.c_str()  );
        while (!main_disp.is_closed() ) 
            main_disp.wait();

我必须关闭每个窗口才能访问nect 1:

I have to close each window to get to the nect one and with this :

        cimg_library::CImg<unsigned char> image(s.c_str());
        cimg_library::CImgDisplay main_disp(image, s.c_str()  )

推荐答案

CImg打开的窗口意味着显示在事件循环内部。上述代码片段中的事件循环是while语句中的块。

The windows opened by CImg are meant be displayed inside of an event loop. The event loop in the code snippet above is the block inside the while statement.

while (!main_disp.is_closed() ) 
            main_disp.wait();

post中的代码将窗口绘制为构造函数的一部分,然后代码进入事件循环并调用wait()。调用wait()使应用程序暂停,直到发生事件为止。事件是某种输入。它可以是鼠标点击,鼠标移动,从键盘敲击,或甚至从操作系统的重绘请求。当接收到事件时,应用程序再次开始执行。

The code in the post draws the window as part of the constructor, then the code enters the event loop and calls wait(). The call to wait() makes the application to pause until an "event" occurs. The event is some kind of input. It could be a mouse click, mouse movement, a keystroke from the keyboard, or even a redraw request from the operating system. When an event is received, the application starts executing again.

我没有时间尝试代码,但此代码应同时显示两个窗口:

I haven't had time to try the code, but this code should show two windows at the same time:

cimg_library::CImg<unsigned char> image1(f1.c_str());
cimg_library::CImgDisplay disp1(image1, f1.c_str()  );
cimg_library::CImg<unsigned char> image2(f2.c_str());
cimg_library::CImgDisplay disp2(image1, f2.c_str()  );

//start event loop
while(true) {
     //All the interactive code is inside the event loop
     cimg_library::CImgDisplay::wait(disp1, disp2);
}

教程 http://cimg.eu/reference/group__cimg__tutorial.html )有两个窗口打开的示例,显示如何检查例如鼠标按钮点击和鼠标位置。

The tutorial (http://cimg.eu/reference/group__cimg__tutorial.html) has an example of two windows open and shows how to check for things like mouse button clicks and mouse position.

这篇关于如何显示几个图像(每个在单独的窗口)与CImg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆