利用系统IO读取磁盘上指定BMP图片的宽和高,以及BMP图片的大小, 并输出到终端,要求图片名称通过命令行传递
/*************************************************
*
* file name:GetBmpInfo.c
* author :momolyl@126.com
* date :2024/05/11
* brief :利用系统IO读取磁盘上指定BMP图片的宽和高,以及BMP图片的大小,
* 并输出到终端,要求图片名称通过命令行传递。
* note :None
*
* CopyRight (c) 2024 momolyl@126.com All Right Reseverd
*
**************************************************/
#include "BmpInfoStruct.c"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
/*************************************************
*
* func name :GetBmpInfo.c
* brief :
* func parameter:
*
*
* return :None
* note :None
* func author :momolyl@126.com
* date :2024/04/25
* version :V1.0
**************************************************/
int main(int argc, const char *argv[])
{
// 1.判断传入的参数是否有效
if (2 != argc)
{
printf("argment is invalid!\n");
return -1;
}
// 2.打开指定的bmp文件
int fb = open(argv[1], O_RDWR);
if (-1 == fb)
{
printf("open file is failed!\n");
return -1;
}
// 3.读取文件中需要的数据
BmpFileHeader_t Info1;
BmpInfoHeader_t Info2;
read(fb, &Info1, 14);
read(fb, &Info2, 40);
printf("bmp size =%d\n", Info1.bfSize);
printf("bmp width =%d\n", Info2.biWidth);
printf("bmp height =%d\n", Info2.biHeight);
return 0;
}
运行结果:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!