获取bmp图片信息

/*******************************************************************
*
*	file name:	get_bmp_info.c
*	author	 :  lzj
*	date	 :  2024/05/11
*	function :  获取bmp图片信息
* 	note	 :  None
*
*	CopyRight (c)  2023-2024   jjh6lzj@163.com   All Right Reseverd 
*
* *****************************************************************/
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#pragma pack(1)    //取消字节对齐
typedef struct BITMAPFILEHEADER /* size: 40 */
{
   char bfType[2];	// 文件的类型,该值必需是0x4D42,也就是字符'BM'。
   unsigned int  bfSize;	// 位图文件的大小,用字节为单位
   unsigned short bfReserved1;// 保留,必须设置为0
   unsigned short bfReserved2;// 保留,必须设置为0
   unsigned int  bfOffBits;// 位图数据距离文件开头偏移量,用字节为单位
} BITMAPFILEHEADER;
typedef struct WINBMPINFOHEADER  /* size: 40 */
{
   unsigned int  biSize;		// BITMAPINFOHEADER结构所需要的字数
   unsigned int  biWidth;		// 图像宽度,单位为像素
   unsigned int  biHeight;		// 图像高度,单位为像素,负数,则说明图像是正向的
   unsigned short biPlanes;		// 为目标设备说明位面数,其值将总是被设为1
   unsigned short biBitCount;	// 一个像素占用的bit位,值位1、4、8、16、24、32
   unsigned int  biCompression;// 压缩类型
   unsigned int  biSizeImage;	// 位图数据的大小,以字节为单位
   unsigned int  biXPelsPerMeter;// 水平分辨率,单位 像素/米
   unsigned int  biYPelsPerMeter;// 垂直分辨率,单位 像素/米
   unsigned int  biClrUsed;	// 
   unsigned int  biClrImportant;// 
} WINBMPINFOHEADER;
#pragma pack()  //恢复字节对齐
int main(int argc, char const *argv[])
{
    BITMAPFILEHEADER BMP_head;
    WINBMPINFOHEADER BPP_head;
    if (2!=argc)
    {
        return -1;
    }
    int bmp_flag=open(argv[1],O_RDWR);
    if (bmp_flag==-1)
    {
        printf("bmp open faile");
    }
    read(bmp_flag,&BMP_head,14);
    read(bmp_flag,&BPP_head,40);
    printf("图像大小: %d ,宽 : %d,高 : %d \n",BMP_head.bfSize,BPP_head.biWidth,BPP_head.biHeight);
    close(bmp_flag);
    return 0;
}




posted @   夏雪呦  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示