【发布时间】:2022-01-09 21:44:57
【问题描述】:
我使用 GIMP 创建了一个 C 源图像转储,如下所示:
/* GIMP RGBA C-Source image dump (example.c) */
static const struct {
guint width;
guint height;
guint bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
guint8 pixel_data[304 * 98 * 2 + 1];
} example= {
304, 98, 2,
"\206\061\206\061..... }
有没有办法在 GIMP 中再次读取它以取回原始图像?因为这似乎不可能。 或者它是否存在可以进行这种反向转换的工具?
已编辑
根据一些建议,我尝试编写一个简单的 C 程序,以使反向覆盖最终得到与在互联网上找到的另一个代码非常相似的东西,但两者都不起作用:
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "imgs_press.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
int main(int argc, char** argv) {
int fd;
char *name = "orignal_img.pnm";
fd = open(name, O_WRONLY | O_CREAT, 0644);
if (fd == -1) {
perror("open failed");
exit(1);
}
if (dup2(fd, 1) == -1) {
perror("dup2 failed");
exit(1);
}
// file descriptor 1, i.e. stdout, now points to the file
// "helloworld" which is open for writing
// You can now use printf which writes specifically to stdout
printf("P2\n");
printf("%d %d\n", press_high.width, press_high.height);
for(int x=0; x<press_high.width * press_high.height * 2; x++) {
printf("%d ", press_high.pixel_data[x]);
}
}
根据 n-1-8e9-wheres-my-share-m 的建议,也许我需要使用正确的解码来操作像素,但我不知道该怎么做,还有其他建议吗?
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: c++ c image-processing gimp