簡體   English   中英

如何從C中的WBC文件中提取圖片?

[英]How can I extract pictures from a WBC file in C?

有人要求我幫助他們從Web Shots圖像收集文件(.WBC)中提取圖片。 我嘗試了XnView,但是沒有用。 我該如何用C語言做到這一點?

來自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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM