我使用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程序来进行反向转换,但最终与在Internet上找到的另一个代码非常相似,但两者都无法正常运行:
#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所建议,也许我需要使用正确的解码来操作像素,但是我不知道如何做到这一点,请问是否有其他建议?
我得到的图像确实失真了:
![enter image description here](https://istack.dev59.com/kmfiv.webp)