S3C6410 FramBuffer编程(五) --- 读取bmp格式图片的一般步骤

1.打开文件

        fp = fopen("./wzk.bmp","rb");
if(fp == NULL)
{
goto CLOSE;
return -1;
}


2.读取文件头信息,并判断是否是bmp文件

        rc = fread(&FileHead,sizeof(BMPFILEHEADER),1,fp);
if(rc != 1)
{
printf("read file header error!\n");
goto CLOSE;
}


printf("type = %4x\n",FileHead.map_id);

if(memcmp(FileHead.map_id,"BM",2) != 0)
{
printf("it is not a bmp file \n");
fclose(fp);
return -3;
}


3.     读取图像信息头

         rc = fread(&InfoHead,sizeof(BMPINFOHEADER),1,fp);
if(rc != 1)
{
printf("read info header error!\n");
goto CLOSE;
}


fseek(fp,FileHead.offset,SEEK_SET);

BytesPerLine = InfoHead.width * InfoHead.bpp/8;


printf("width:%d,bpp:%d\n",InfoHead.width,InfoHead.bpp);


4. 读取每个点的像素值

        while(!feof(fp))
{
PIXEL pix;
unsigned short ret;


rc = fread(&pix,sizeof(PIXEL),1,fp);
if(rc != 1)
{
printf("read bmp file error!\n");
goto CLOSE;
}

          }


5. 关闭文件

    fclose(fp);

你可能感兴趣的:(编程,c,header,File,null,FP)