linux 显示bmp文件大小,Linux 下查看bmp图片的基本信息

#include const char filePath[]={"路径"};

typedef struct tagBmpFileHeader //文件头

{

//unsigned short bfType; //标识该文件为bmp文件,判断文件是否为bmp文件,即用该值与"0x4d42"比较是否相等即可,0x4d42 = 19778

unsigned long bfSize; //文件大小

unsigned short bfReserved1; //预保留位

unsigned short bfReserved2; //预保留位

unsigned long bfOffBits; //图像数据区的起始位置

}BmpFileHeader;//14字节

typedef struct tagBmpInfoHeader //信息头

{

unsigned long biSize; //图像数据块大小

long biWidth; //宽度

long biHeight; //高度

unsigned short biPlanes;//为1

unsigned short biBitCount; //像素位数,8-灰度图;24-真彩色

unsigned long biCompression;//压缩方式

unsigned long biSizeImage; //图像区数据大小

long biXPelsPerMeter; //水平分辨率,像素每米

long biYPelsPerMeter;

unsigned long biClrUsed; //位图实际用到的颜色数

unsigned short biClrImportant;//位图显示过程,重要的颜色数;0--所有都重要

}BmpInfoHeader;//40字节

void main()

{

int fp=-1;

unsigned short bfType;

BmpFileHeader file_head;

BmpInfoHeader info_head;

fp=open(filePath,O_RDWR,0777);

if(-1 == fp)

{

printf("%s open failure!!\n",filePath);

}

printf("%s open success!\n",filePath);

read(fp,&bfType,sizeof(bfType));

read(fp,&file_head,sizeof(file_head));

read(fp,&info_head,sizeof(info_head));

printf("file head:\n");

printf("bfType=%x bfSize=%lu ",bfType,file_head.bfSize);

printf("bfReserved1=%u bfReserved2=%u ",file_head.bfReserved1,file_head.bfReserved2);

printf("bfOffBits=%lu\n",file_head.bfOffBits);

printf("info head:\n");

printf("biSize=%lu biWidth=%ld biHeight=%ld ",info_head.biSize,info_head.biWidth,info_head.biHeight);

printf("biPlanes=%u biBitCount=%u ",info_head.biPlanes,info_head.biBitCount);

printf("biCompression=%lu biSizeImage=%lu ",info_head.biCompression,info_head.biSizeImage);

printf("biXPelsPerMeter=%ld biYPelsPerMeter=%ld ",info_head.biXPelsPerMeter,info_head.biYPelsPerMeter);

printf("biClrUsed=%lu biClrImportant=%u\n",info_head.biClrUsed,info_head.biClrImportant);

close(fp);

}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值