c - 如何从 C 中的 WBC 文件中提取图片?

标签 c image extract

有人要我帮助他们从 Web Shots 图片集文件 (.WBC) 中提取图片。我试过 XnView 但它没有用。我如何在 C 中执行此操作?

最佳答案

来自 Mike :

I hacked together some code to do the job. Here it is. It's not production quality code, so if you do not understand it then do not run it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void save_image(const char* filename, FILE* in_fp)
{
   char buf[4096];
   size_t read;
   FILE *fp;

   fp = fopen(filename, "wb");
   if (!fp) {
      fprintf(stderr, "cannot open file.");
      exit(1);
   }
   do {
      read = fread(buf,1,sizeof(buf),in_fp);
      fwrite(buf, 1, read, fp);
   } while (read);
   fclose(fp);
}

int main(int argc, char* argv[])
{
   char buf[4096];
   unsigned int read, read_tot = 0;
   FILE *fp;
   int image_count = 1;
   char filename[255];
   unsigned int i;

   char pattern[] = "JFIF";
   int pi = 0;

   long int curpos;
   char pad[50];

   char src_filename[] = 
       "C:\\Documents and Settings\\mikeking\\Desktop\\WBC\\"
       "Custom - CATHYS WEDDING.wbc";
   char des_directory[] = "C:\\Documents and Settings\\mikeking\\Desktop\\F\\";

   fp = fopen(src_filename, "rb");
   if (!fp) {
      fprintf(stderr, "cannot open file.");
      exit(1);
   }

   do {
      read = fread(buf,1,sizeof(buf),fp);

      for(i=0; i<read; i++){
         if (buf[i] == pattern[pi]) {
            pi++;
            if (pi == sizeof(pattern)) {
               strcpy(filename, des_directory);
               itoa(image_count, pad, 10);
               image_count++;
               strcat(filename, pad);
               strcat(filename, ".jpg");
               curpos = ftell(fp);
               fseek(fp,read_tot+i-10,SEEK_SET);
               save_image(filename,fp);
               fseek(fp,curpos,SEEK_SET);
            }
         } else {
          pi = 0;
         }
      }
      read_tot += read;
   } while (read);

   fclose(fp);
   return 0;
}

关于c - 如何从 C 中的 WBC 文件中提取图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/893616/

相关文章:

zip - 使用 Ionic Zip 将 zip 中的文件夹解压到另一个目录的根目录(不包含 zip 中包含的文件夹)

CSV 解析函数无法识别空值

c++ - 如何确保函数在 C/C++ 中返回一致的浮点值?

html - 图像标题宽度与图像相同

css - 在同一 div 标签中叠加背景图像

linux - 我怎样才能从硬盘上制作一张没有任何痕迹的图像,这样即使是专家也无法发现发生了什么?

php - 使用 PHP 和 xPath 从 HTML 中提取数据

audio - 开源视频声音提取器

c - 在非 NULL 终止的文件中搜索以 NULL 终止的字符串

c - 在 C 中缩小 BMP 图像