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;

    }

  • 相关阅读:
    外贸视频教程[外贸人zencart自助建站视频教程]:第一课
    外贸视频教程[外贸人zencart自助建站视频教程]:第二课
    行sqlSQL*PLUS使用(三)
    消息函数windows 程序设计 第三章 (下)
    优化性能[置顶] Android应用性能优化方案
    自定义方法JSP自定义标签
    发票名称<iframe name=document.getElementById("cellFrame").src = "dyszAction!showFpDyMb.do?fpzldm=" + fpzldm;
    纹理寻址DirectX入门 (8) TextureAddressMode
    空间复杂度分段分段有序数组合并成有序(空间复杂度为O(1))
    数据库生成T4模版在代码生成中的应用心得
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/1960202.html
Copyright © 2011-2022 走看看