马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- #include <stdio.h>
- #include <dirent.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <signal.h>
- #include <stdlib.h>
- #include <string.h>
- #define BUFFER_SIZE 1024
- void open_and_display_file(const char *filepath, const char *dir)
- {
- unsigned char Decode = 0;
- static int image_id = 0;
- unsigned char imagePath[PATH_MAX] = {0};
- unsigned char buffer[BUFFER_SIZE] = {0};
- FILE *imageFp = NULL;
- FILE *file = NULL;
- int read_len = 0;
- int write_len = 0;
- sprintf(imagePath, "%s/%d.png", dir, image_id);
- image_id++;
- file = fopen(filepath, "r");
- if (file == NULL)
- {
- perror("无法打开文件:");
- return;
- }
- imageFp = fopen(imagePath, "wb+");
- if (imageFp == NULL)
- {
- perror("无法打开文件:");
- return;
- }
- ftruncate(fileno(imageFp), 0);
- fread(buffer, 1, 2, file);
- i
复制代码 |