如何用C语言从WBC文件中提取图片?

发布于 2024-07-21 01:34:12 字数 84 浏览 2 评论 0原文

有人要求我帮助他们从 Web Shots 图像集合文件 (.WBC) 中提取图片。 我尝试了 XnView 但没有成功。 我怎样才能在C中做到这一点?

Someone ask me to help them extract their pictures from a Web Shots image collection file (.WBC). I tried XnView but it did not work. How can I do this in C?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彻夜缠绵 2024-07-28 01:34:12

来自迈克

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

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

From 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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文