【问题标题】:How can I extract pictures from a WBC file in C?如何从 C 中的 WBC 文件中提取图片?
【发布时间】:2009-05-21 15:44:38
【问题描述】:

有人请我帮助他们从 Web Shots 图像收集文件 (.WBC) 中提取图片。我试过 XnView 但它没有用。我如何在 C 中做到这一点?

【问题讨论】:

  • 那么问题是什么?对我来说,这更像是一个答案而不是一个问题。
  • 我回答了这个问题。希望如果有人“谷歌”这个问题,那么他们会得到这个答案。
  • @Mike - 我已经移动了答案。如果您将其复制到您自己的答案中,我将删除我的。

标签: c image extraction


【解决方案1】:

来自Mike

我编写了一些代码来完成这项工作。这里是。它不是生产质量代码,所以如果你不理解它,请不要运行它。

#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;
}

【讨论】:

    猜你喜欢
    • 2010-10-04
    • 2012-03-19
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    相关资源
    最近更新 更多