打开bmp文件的方式

来源:互联网 发布:网狐源码 编辑:程序博客网 时间:2024/05/16 12:48
int ii=55;
FILE *fp;
unsigned int flen,datalen;
char buf[80];
        sprintf(buf, "D:\\light_test\\t2\\%d.bmp", ii);
        fp=fopen(buf,"r");
fseek(fp,0L,SEEK_END);
flen=ftell(fp);
//datalen=flen-(14+40+256*4);
datalen=flen-1078;
fseek(fp,1078,SEEK_SET);

unsigned char *buffer = new unsigned char[datalen];

fread(buffer,1,datalen,fp);

fclose(fp);

灰度图的灰度值就在buffer中了

int I1[width][length];
    int I2[width][length];
    for(int i=0;i<width;i++)
{
for(int j=0;j<length;j++)
{
I[i][j]=*(buffer+i*j+j);
}
}
   delete buffer;

以上将buffer中的数据保存在二维数组中了