zoukankan      html  css  js  c++  java
  • 如何读入位图(三)

    C语言读入信息头:

    int ReadInfoHeader(char *filepath,BITMAPINFOHEADER *bmih)

    {

           FILE *fp;

           //打开文件

           fp=fopen(filepath,"rb");

           if(!fp)

           {

                  printf("Can not open the file:%s\n",filepath);

                  return -1;

           }

           //使文件指针跳过文件头(14字节)

           fseek(fp,14,SEEK_SET);

           //读入biSize

           if(fread(&bmih->biSize,sizeof(DWORD),1,fp)!=1)

           {

                  printf("Can not read biSize in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biWidth

           if(fread(&bmih->biWidth,sizeof(LONG),1,fp)!=1)

           {

                  printf("Can not read biWidth in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biHeight

           if(fread(&bmih->biHeight,sizeof(LONG),1,fp)!=1)

           {

                  printf("Can not read biHeight in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biPlanes

           if(fread(&bmih->biPlanes,sizeof(WORD),1,fp)!=1)

           {

                  printf("Can not read biPlanes in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biBitCount

           if(fread(&bmih->biBitCount,sizeof(WORD),1,fp)!=1)

           {

                  printf("Can not read biBitCount in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biCompression

           if(fread(&bmih->biCompression,sizeof(DWORD),1,fp)!=1)

           {

                  printf("Can not read biCompression in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biSizeImage

           if(fread(&bmih->biSizeImage,sizeof(DWORD),1,fp)!=1)

           {

                  printf("Can not read biSizeImage in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biXPelsPerMeter

           if(fread(&bmih->biXPelsPerMeter,sizeof(LONG),1,fp)!=1)

           {

                  printf("Can not read biXPelsPerMeter in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biYPelsPerMeter

           if(fread(&bmih->biYPelsPerMeter,sizeof(LONG),1,fp)!=1)

           {

                  printf("Can not read biYPelsPerMeter in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biClrUsed

           if(fread(&bmih->biClrUsed,sizeof(DWORD),1,fp)!=1)

           {

                  printf("Can not read biClrUsed in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //读入biClrImportant

           if(fread(&bmih->biClrImportant,sizeof(DWORD),1,fp)!=1)

           {

                  printf("Can not read biClrImportant in the info header.\n");

                  fclose(fp);

                  return -1;

           }

           //关闭文件

           fclose(fp);

     

           return 0;

    }

  • 相关阅读:
    多重平行中介(Mplus)
    小米手机,发短信出现闪退
    宇宙是有边还是没边?
    如何查一篇文章的引用文章
    卡方检验
    函数的形参与实参(二维数组)
    输出矩阵四周的数字的平均数(C)
    关于amos 的自由度
    Sql server case when then
    Sql Server中两个表之间数据备份和导入
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/1960202.html
Copyright © 2011-2022 走看看