c bmp parse

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Farmwang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值