c++ - 如何使用 CImg 显示少量图像(每个图像在单独的窗口中)?

标签 c++ cimg

如何使用 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();

我必须关闭每个窗 Eloquent 能进入 nect 窗口,然后:

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

他们一个接一个地消失了。

最佳答案

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

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

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

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

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 ) 有一个打开两个窗口的示例,并展示了如何检查鼠标按钮点击和鼠标位置等内容。

关于c++ - 如何使用 CImg 显示少量图像(每个图像在单独的窗口中)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8723846/

相关文章:

c++ - 转发引用 : returning T when given T&& and T& when given T&

c++ - CImg 的编译错误

c++ - 尝试使用 CImg 保存图像时出错

c++ - 继承构造函数和大括号或等于初始值设定项

c++ - fopen 抛出无效参数错误

c++ - Qt qml应用增加内存使用

c++ - 在LLVM中插入指令

c++ - 将 exr/pfm 保存到位图 CImg

C++/CImg 不一致的结果

c++ - 如何将已存储在固定内存中的值分配给 cimg 对象