获取任意bmp图片的参数函数设计

/*
 * @Author: Eon eon4051@163.com
 * @Date: 2024-05-08 14:24:52
 * @LastEditors: Eon eon4051@163.com
 * @LastEditTime: 2024-05-11 18:57:02
 * @FilePath: \数据结构text\text,.c
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#pragma pack(1)//取消字节对齐

//14字节
typedef  struct  tagBITMAPFILEHEADER
{ 
	unsigned short int  bfType;       //位图文件的类型,必须为BM 
	unsigned int       bfSize;       //文件大小,以字节为单位
	unsigned short int  bfReserverd1; //位图文件保留字,必须为0 
	unsigned short int  bfReserverd2; //位图文件保留字,必须为0 
	unsigned int       bfbfOffBits;  //位图文件头到数据的偏移量,以字节为单位
}BITMAPFILEHEADER;

//40字节
typedef  struct  tagBITMAPINFOHEADER 
{ 
	int biSize;                        //该结构大小,字节为单位 4
	int  biWidth;                     //图形宽度以象素为单位 4
	int  biHeight;                     //图形高度以象素为单位 4
	short int  biPlanes;               //目标设备的级别,必须为1  2
	short int  biBitcount;             //颜色深度,每个象素所需要的位数 2
	int  biCompression;        //位图的压缩类型 4
	int  biSizeImage;              //位图的大小,以字节为单位 4
	int  biXPelsPermeter;       //位图水平分辨率,每米像素数 4
	int  biYPelsPermeter;       //位图垂直分辨率,每米像素数 4
	int  biClrUsed;            //位图实际使用的颜色表中的颜色数 4
	int  biClrImportant;       //位图显示过程中重要的颜色数 4 
}BITMAPINFOHEADER;

#pragma pack()
//取消字节对齐
//显示任意大小的BMP图片
//x,y:显示的坐标
//w,h:图片的宽高
int main(int argc,char const *argv[])
{
	if(2!=argc)
    {
        printf("argument is invaild\n");
        return -1;
    }
	//1.打开BMP图片文件
	int bmp_fd = open(argv[1], O_RDONLY);
	if(bmp_fd == -1)
	{
		perror("BMP图片文件打开失败!");
		return -1;
	}
	struct tagBITMAPFILEHEADER s1;
	struct tagBITMAPINFOHEADER s2;

	read(bmp_fd,&s1,14);
	read(bmp_fd,&s2,40);

	printf("size=%d\nwighet=%d\nhighet=%d\n",s1.bfSize,s2.biWidth,s2.biHeight);
    
	//关闭BMP图片文件
	close(bmp_fd);
	
	return 0;
}
posted @   藍桉未遇釋槐鳥  阅读(13)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示