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;

    }

  • 相关阅读:
    PCB电路板元器件布局的一般原则*(转)
    PCB Layout初学者必会知识总结(转)
    数字器件和模拟器件?
    同一原理图中怎么区分数字电路和模拟电路
    oracle 11g R2执行INSERT语句,数据库把一个汉字看做3个汉字
    SQL存储过程与函数的区别
    用户自定义函数——Oracle 11g R2
    提高使用SQL Developer进行PL/SQL编程的效率——Oracle 11g R2
    Oracle查看用户使用的表
    JAVA-Eclipse快捷键
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/1960202.html
Copyright © 2011-2022 走看看