您的位置:首页 > 其它

c bmp parse

2015-11-13 22:40 309 查看
#include <stdio.h>

#include <stdlib.h>

#define fileheadlen 14

#define BM 19778

void  IsBmpFile(FILE *fpbmp);

  long  GetBmpLength(FILE* fpbmp);

int GetBmpWidth(FILE *fpbmp);

int GetBmpHeight(FILE *fpbmp);

int GetColorBit(FILE* fpbmp);

int GetSizeImage(FILE* fp);

unsigned int Picoffset=0;

long width;

long height;

unsigned char r[3000][3000],out_r[3000][3000];

unsigned char g[3000][3000],out_g[3000][3000];

unsigned char b[3000][3000],out_b[3000][3000];

int main(int argc,char* argv[])

{

    unsigned char *fp_temp;

    FILE *fpbmp;

    FILE *fpout;

    fpbmp=fopen("33.bmp","rb");

    if(fpbmp==NULL)

    {

        printf("open bmp failed \n");

        return 1;

    }

    IsBmpFile(fpbmp);

printf("the bmp size is  %d \n",GetBmpLength(fpbmp));

printf("the bmp height is   %d\n",GetBmpHeight(fpbmp));

printf("ths bmp width is   %d\n",GetBmpWidth(fpbmp));

printf("the bmp color bit is   %d\n", GetColorBit(  fpbmp));

printf("the bmp size is   %d \n",GetSizeImage(fpbmp));

    return 0;

}

    void  IsBmpFile(FILE *fpbmp)

    {

        unsigned short bftype=0;

        fseek(fpbmp,0L,SEEK_SET); //0L  define 0 is long type

        fread(&bftype,sizeof(char),2,fpbmp);

        if(BM!=bftype)

        {

            printf("this file is not bmp file \n");

            exit(1);

        }

        else

        {

            printf("it is bmp file \n");

        }

    }

  long  GetBmpLength(FILE* fpbmp)

    {

        long len;

        fseek(fpbmp,2L,SEEK_SET);

        fread(&len,sizeof(char),4,fpbmp);

        return len ;

    }

int GetBmpWidth(FILE *fpbmp)

{

    int hgt=0;

    fseek(fpbmp,18L,SEEK_SET);

    fread(&hgt,sizeof(char),4,fpbmp);

    return hgt;

}

int GetBmpHeight(FILE *fpbmp)

{

    int height1=0;

    fseek(fpbmp,22L,SEEK_SET);

    fread(&height1,sizeof(char),4,fpbmp);

    return height1;

}

int GetColorBit(FILE* fpbmp)

{

    int colorbit=0;

    fseek(fpbmp,28L,SEEK_SET);

    fread(&colorbit,sizeof(char),2,fpbmp);

    return colorbit;

}

int GetSizeImage(FILE* fp)

{

    int picsize=0;

    fseek(fp,34L,SEEK_SET);

    fread(&picsize,sizeof(char),4,fp);

    return picsize;

}

long GetXPerMeter(FILE *fp)

{

    long xmeter=0;

    fseek(fp,38L,SEEK_SET);

    fread(&xmeter,sizeof(char),4,fp);

    return xmeter;

}

long GetYPerMeter(FILE *fp)

{

    long ymeter=0;

    fseek(fp,42L,SEEK_SET);

    fread(&ymeter,sizeof(char),4,fp);

    return ymeter;

}

long GetUesdColor(FILE *fp)

{

    long usecolor=0;

    fseek(fp,46L,SEEK_SET);

    fread(&usecolor,sizeof(char),4,fp);

    return usecolor ;

}

long GetImpCorNum(FILE *fp)

{

    long impcornum=0;

    fseek(fp,50L,SEEK_SET);

    fread(&impcornum,sizeof(char),4,fp));

    return impcornum;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: