如何在打开另一个图像时关闭图像 - linux c ++
How to close an image at the opening of another - linux c ++
如果一切都不完美,我深表歉意;( 我正在用c ++做一个程序,当它收到传感器信息时,会显示一张全屏显示图片。 问题是,当我想从一个图像转到另一个图像时,它会打开一个新的feh,直到计算机崩溃的那一刻,因为它占用了所有内存......
如何使图像的打开关闭前一个图像?
这是我当前的命令行:
system("feh -F ressources/icon_communication.png&");
我必须指定我也触发声音,但没有问题,因为程序在声音结束时自动关闭:
system("paplay /home/pi/demo_ecran_interactif/ressources/swip.wav&");
尝试将其作为测试并有效!谢谢@paul-桑德斯!
#include <iostream>
#include <chrono>
#include <thread>
#include <unistd.h>
#include <signal.h>
using namespace std;
pid_t display_image_file (const char *image_file)
{
pid_t pid = fork ();
if (pid == -1)
{
std::cout << "Could not fork, error: " << errno << "n";
return -1;
}
if (pid != 0) // parent
return pid;
// child
execlp ("feh", "-F", image_file, NULL); // only returns on failure
std::cout << "Couldn't exec feh for image file " << image_file << ", error: " << errno << "n";
return -1;
}
int main()
{
pid_t pid = display_image_file ("nav.png");
if (pid != -1)
{
std::this_thread::sleep_for (std::chrono::milliseconds (2000));
kill (pid, SIGKILL);
}
pid_t pid2 = display_image_file ("sms2.png");
}
因此,这里的目标(就您的测试程序而言(似乎是:
- 以
feh
显示nav.png
- 等待 2 秒
- 关闭(该实例(
feh
- 以
feh
显示sms2.png
如果你能让测试程序做到这一点,那么你就会走上正轨(我不会担心我漂亮的小脑袋关于你的声音问题(因为今天这里是 30+ 度(,但是一旦你让测试程序运行正确,那么你可能就能弄清楚如何自己解决这个问题(。
因此,我在这里的代码中看到的两个问题:
- 您没有努力关闭"FEH"的第一个实例
execlp()
并没有像你认为的那样做(具体来说,它永远不会返回,除非它由于某种原因失败(。
所以我认为你需要做的是这样的(代码未经测试,甚至可能无法编译,你需要找出正确的头文件来 #include,但它至少应该让你开始(:
pid_t display_image_file (const char *image_file)
{
pid_t pid = fork ();
if (pid == -1)
{
std::cout << "Could not fork, error: " << errno << "n";
return -1;
}
if (pid != 0) // parent
return pid;
// child
execlp ("feh", "-F", image_file, NULL); // only returns on failure
std::cout << "Couldn't exec feh for image file " << image_file << ", error: " << errno << "n";
return -1;
}
int main()
{
pid_t pid = display_image_file ("nav.png");
if (pid != -1)
{
std::this_thread::sleep_for (std::chrono::milliseconds (2000));
kill (pid, SIGKILL);
}
pid_t pid = display_image_file ("sms2.png");
// ...
}
这有帮助吗?
相关文章:
- 在C++/Linux中设置单调时钟的一些技巧
- Linux的Cpp上的计时器
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux中哪里可以找到互斥、未来等的源代码
- 如何在linux终端中同时编译和运行c++代码
- 如何在打开另一个图像时关闭图像 - linux c ++
- C++/openCV - 为什么显示图像会产生 Linux 分割错误?(打开CV错误?
- 在没有任何外部库的情况下,是否可以在c++/linux的窗口中显示bmp图像
- 访问linux的OpenCV-2.4.3的OPENCV图像处理库
- 如何在linux上对图像进行egl屏幕外渲染
- 使用没有GUI的OpenCV捕获图像(在控制台Linux上)
- Mac 和 Linux 上的 SDL IMG_Load() 为同一图像返回不同的 BitsPerPixel
- Linux 不会为我的游戏加载我的图像
- 无法在Qt 5.0.2(Linux)中使用QCamera获取相机支持的分辨率以进行图像捕获
- Linux CGI Web API -如何在c++下输出二进制JPEG图像
- USB网络摄像头图像捕获在没有openCV(LINUX)的C++中
- 简单的库,用于在 Linux 上以C++显示 2D 图像
- (c++,Qt,Linux)将游戏地图线转换为图像线
- 用linux操作内存中的位图图像