显示 C 中的图像 Ubuntu
Showing an image in C Ubuntu
我是 Linux (Ubuntu) 的新手,我必须用 C 编写一段代码,该代码必须解压缩图像、打印图像的大小并显示图像。
我必须使用 zcat、wc (wc -c) 和 xview (xview stdin)。
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <errno.h>
int PID;
int PIPE1[2];
void zcat(char INPUT[])
{
dup2(PIPE1[1],STDOUT_FILENO);
close(PIPE1[0]);
close(PIPE1[1]);
execlp("zcat","zcat",INPUT,NULL);
perror("\nzcat malo\n");
exit(0);
}
void show_image()
{
dup2(PIPE1[0],STDIN_FILENO);
close(PIPE1[0]);
close(PIPE1[1]);
execlp("xview","xview","stdin",NULL);
perror("\nxview malo\n");
exit(0);
}
void image_size()
{
dup2(PIPE1[0], STDIN_FILENO);
close(PIPE1[0]);
close(PIPE1[1]);
execlp("wc","wc","-c",NULL);
perror("\nwc error\n");
exit(0);
}
void xview(char INPUT[])
{
if(pipe(PIPE1)==-1)
{
perror("\npipe1 malo\n");
exit(1);
}
if((PID=fork())==-1)
{
perror("\nfork1 error\n");
exit(1);
}
else if(PID==0) zcat(INPUT);
if((PID=fork())==-1)
{
perror("\nfork2 error\n");
exit(1);
}
else if(PID==0) show_image();
close(PIPE1[0]);
close(PIPE1[1]);
}
void wc(char INPUT[])
{
if(pipe(PIPE1)==-1)
{
perror("\npipe1 malo\n");
exit(1);
}
if((PID=fork())==-1)
{
perror("\nfork1 error\n");
exit(1);
}
else if(PID==0) zcat(INPUT);
if((PID=fork())==-1)
{
perror("\nfork2 error\n");
exit(1);
}
else if(PID==0) image_size();
close(PIPE1[0]);
close(PIPE1[1]);
}
void main()
{
char INPUT[20];
scanf("%s",INPUT);
xview(INPUT);
wc(INPUT);
}
在 INPUT 中,我必须输入包含图像的文件的名称 (image.png)。 imagelinux.png.gz
当我在终端中 运行 这个程序显示 "xview malo" : No such file or directory
并以字节为单位打印图像大小。
它不显示图像:C
帮助!
使用 sudo apt-get install xloadimage
安装 xview,您的程序将运行。
我是 Linux (Ubuntu) 的新手,我必须用 C 编写一段代码,该代码必须解压缩图像、打印图像的大小并显示图像。 我必须使用 zcat、wc (wc -c) 和 xview (xview stdin)。 这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <errno.h>
int PID;
int PIPE1[2];
void zcat(char INPUT[])
{
dup2(PIPE1[1],STDOUT_FILENO);
close(PIPE1[0]);
close(PIPE1[1]);
execlp("zcat","zcat",INPUT,NULL);
perror("\nzcat malo\n");
exit(0);
}
void show_image()
{
dup2(PIPE1[0],STDIN_FILENO);
close(PIPE1[0]);
close(PIPE1[1]);
execlp("xview","xview","stdin",NULL);
perror("\nxview malo\n");
exit(0);
}
void image_size()
{
dup2(PIPE1[0], STDIN_FILENO);
close(PIPE1[0]);
close(PIPE1[1]);
execlp("wc","wc","-c",NULL);
perror("\nwc error\n");
exit(0);
}
void xview(char INPUT[])
{
if(pipe(PIPE1)==-1)
{
perror("\npipe1 malo\n");
exit(1);
}
if((PID=fork())==-1)
{
perror("\nfork1 error\n");
exit(1);
}
else if(PID==0) zcat(INPUT);
if((PID=fork())==-1)
{
perror("\nfork2 error\n");
exit(1);
}
else if(PID==0) show_image();
close(PIPE1[0]);
close(PIPE1[1]);
}
void wc(char INPUT[])
{
if(pipe(PIPE1)==-1)
{
perror("\npipe1 malo\n");
exit(1);
}
if((PID=fork())==-1)
{
perror("\nfork1 error\n");
exit(1);
}
else if(PID==0) zcat(INPUT);
if((PID=fork())==-1)
{
perror("\nfork2 error\n");
exit(1);
}
else if(PID==0) image_size();
close(PIPE1[0]);
close(PIPE1[1]);
}
void main()
{
char INPUT[20];
scanf("%s",INPUT);
xview(INPUT);
wc(INPUT);
}
在 INPUT 中,我必须输入包含图像的文件的名称 (image.png)。 imagelinux.png.gz 当我在终端中 运行 这个程序显示 "xview malo" : No such file or directory 并以字节为单位打印图像大小。 它不显示图像:C 帮助!
使用 sudo apt-get install xloadimage
安装 xview,您的程序将运行。