DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

呵呵,贴在这里记录一下。

  1. #include<stdio.h>  
  2. #include<string.h>  
  3. #include<sys/types.h>  
  4.   
  5. #include <iostream>  
  6.   
  7. #pragma pack(2)  
  8.   
  9. using namespace std;  
  10.   
  11. //下面两个结构是位图的结构  
  12. typedef struct BITMAPFILEHEADER  
  13. {   
  14.     u_int16_t bfType;   
  15.     u_int32_t bfSize;   
  16.     u_int16_t bfReserved1;   
  17.     u_int16_t bfReserved2;   
  18.     u_int32_t bfOffBits;   
  19. }BITMAPFILEHEADER;   
  20.   
  21. typedef struct BITMAPINFOHEADER  
  22. {   
  23.     u_int32_t biSize;   
  24.     u_int32_t biWidth;   
  25.     u_int32_t biHeight;   
  26.     u_int16_t biPlanes;   
  27.     u_int16_t biBitCount;   
  28.     u_int32_t biCompression;   
  29.     u_int32_t biSizeImage;   
  30.     u_int32_t biXPelsPerMeter;   
  31.     u_int32_t biYPelsPerMeter;   
  32.     u_int32_t biClrUsed;   
  33.     u_int32_t biClrImportant;   
  34. }BITMAPINFODEADER;  
  35.   
  36. void showBmpHead(BITMAPFILEHEADER &pBmpHead){    
  37.     cout<<"位图文件头:"<<endl;    
  38.     cout<<"文件头类型:"<<pBmpHead.bfType<<endl;    
  39.     cout<<"文件大小:"<<pBmpHead.bfSize<<endl;    
  40.     cout<<"保留字_1:"<<pBmpHead.bfReserved1<<endl;    
  41.     cout<<"保留字_2:"<<pBmpHead.bfReserved2<<endl;    
  42.     cout<<"实际位图数据的偏移字节数:"<<pBmpHead.bfOffBits<<endl<<endl;    
  43. }    
  44.     
  45. void showBmpInforHead(BITMAPINFODEADER &pBmpInforHead){    
  46.     cout<<"位图信息头:"<<endl;    
  47.     cout<<"结构体的长度:"<<pBmpInforHead.biSize<<endl;    
  48.     cout<<"位图宽:"<<pBmpInforHead.biWidth<<endl;    
  49.     cout<<"位图高:"<<pBmpInforHead.biHeight<<endl;    
  50.     cout<<"biPlanes平面数:"<<pBmpInforHead.biPlanes<<endl;    
  51.     cout<<"biBitCount采用颜色位数:"<<pBmpInforHead.biBitCount<<endl;    
  52.     cout<<"压缩方式:"<<pBmpInforHead.biCompression<<endl;    
  53.     cout<<"biSizeImage实际位图数据占用的字节数:"<<pBmpInforHead.biSizeImage<<endl;    
  54.     cout<<"X方向分辨率:"<<pBmpInforHead.biXPelsPerMeter<<endl;    
  55.     cout<<"Y方向分辨率:"<<pBmpInforHead.biYPelsPerMeter<<endl;    
  56.     cout<<"使用的颜色数:"<<pBmpInforHead.biClrUsed<<endl;    
  57.     cout<<"重要颜色数:"<<pBmpInforHead.biClrImportant<<endl;    
  58. }   
  59.   
  60. int main( int argc, char **argv )  
  61. {  
  62.     FILE *fp = fopen(argv[1], "rb");  
  63.   
  64.     BITMAPFILEHEADER head;  
  65.     BITMAPINFODEADER info;  
  66.   
  67.     fread(&head, 1, sizeof(BITMAPFILEHEADER), fp);  
  68.     fread(&info, 1, sizeof(BITMAPINFODEADER), fp);  
  69.   
  70.     showBmpHead(head);  
  71.     showBmpInforHead(info);  
  72.   
  73.     cout<<sizeof(BITMAPFILEHEADER)<<endl; cout<<sizeof(BITMAPINFODEADER)<<endl;   
  74.   
  75.     fclose(fp);  
  76.   
  77.     return 0;  
  78. }  

posted on   DoubleLi  阅读(6479)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示