在linux下读取bmp文件头的完整代码。
呵呵,贴在这里记录一下。
- #include<stdio.h>
- #include<string.h>
- #include<sys/types.h>
- #include <iostream>
- #pragma pack(2)
- using namespace std;
- //下面两个结构是位图的结构
- typedef struct BITMAPFILEHEADER
- {
- u_int16_t bfType;
- u_int32_t bfSize;
- u_int16_t bfReserved1;
- u_int16_t bfReserved2;
- u_int32_t bfOffBits;
- }BITMAPFILEHEADER;
- typedef struct BITMAPINFOHEADER
- {
- u_int32_t biSize;
- u_int32_t biWidth;
- u_int32_t biHeight;
- u_int16_t biPlanes;
- u_int16_t biBitCount;
- u_int32_t biCompression;
- u_int32_t biSizeImage;
- u_int32_t biXPelsPerMeter;
- u_int32_t biYPelsPerMeter;
- u_int32_t biClrUsed;
- u_int32_t biClrImportant;
- }BITMAPINFODEADER;
- void showBmpHead(BITMAPFILEHEADER &pBmpHead){
- cout<<"位图文件头:"<<endl;
- cout<<"文件头类型:"<<pBmpHead.bfType<<endl;
- cout<<"文件大小:"<<pBmpHead.bfSize<<endl;
- cout<<"保留字_1:"<<pBmpHead.bfReserved1<<endl;
- cout<<"保留字_2:"<<pBmpHead.bfReserved2<<endl;
- cout<<"实际位图数据的偏移字节数:"<<pBmpHead.bfOffBits<<endl<<endl;
- }
- void showBmpInforHead(BITMAPINFODEADER &pBmpInforHead){
- cout<<"位图信息头:"<<endl;
- cout<<"结构体的长度:"<<pBmpInforHead.biSize<<endl;
- cout<<"位图宽:"<<pBmpInforHead.biWidth<<endl;
- cout<<"位图高:"<<pBmpInforHead.biHeight<<endl;
- cout<<"biPlanes平面数:"<<pBmpInforHead.biPlanes<<endl;
- cout<<"biBitCount采用颜色位数:"<<pBmpInforHead.biBitCount<<endl;
- cout<<"压缩方式:"<<pBmpInforHead.biCompression<<endl;
- cout<<"biSizeImage实际位图数据占用的字节数:"<<pBmpInforHead.biSizeImage<<endl;
- cout<<"X方向分辨率:"<<pBmpInforHead.biXPelsPerMeter<<endl;
- cout<<"Y方向分辨率:"<<pBmpInforHead.biYPelsPerMeter<<endl;
- cout<<"使用的颜色数:"<<pBmpInforHead.biClrUsed<<endl;
- cout<<"重要颜色数:"<<pBmpInforHead.biClrImportant<<endl;
- }
- int main( int argc, char **argv )
- {
- FILE *fp = fopen(argv[1], "rb");
- BITMAPFILEHEADER head;
- BITMAPINFODEADER info;
- fread(&head, 1, sizeof(BITMAPFILEHEADER), fp);
- fread(&info, 1, sizeof(BITMAPINFODEADER), fp);
- showBmpHead(head);
- showBmpInforHead(info);
- cout<<sizeof(BITMAPFILEHEADER)<<endl; cout<<sizeof(BITMAPINFODEADER)<<endl;
- fclose(fp);
- return 0;
- }
在linux下读取bmp文件头的完整代码。的更多相关文章
- go 读取BMP文件头二进制读取
BMP文件头定义: WORD 两个字节 16bit DWORD 四个字节 32bit package main import ( "encoding/binary" "f ...
- Arch Linux下Visual Stdio Code在格式化C代码时报错
libtinfo.so.5: cannot open shared object file: No such file or directory Arch Linux下Visual Stdio Cod ...
- Linux下获取本机IP地址的代码
Linux下获取本机IP地址的代码,返回值即为互联网标准点分格式的字符串. #define ETH_NAME "eth0" //获得本机IP地址 char* GetLocalAdd ...
- windows和linux下读取文件乱码的终极解决办法!
乱码是个很恶心的问题. windows和linux读取txt文件,一旦读取了,编码发生改变,就无法再还原了,只有重启项目. 网上有很多方法都是读取文件头,方法很好,但是亲测都不能用(右移8位判断0xf ...
- 在windows 、linux下读取目录下所有文件名
Windows要引入的头文件是<Windows.h> 主要是两个函数FindFirstFile.FindNextFile MSDN里是这么说的: FindFirstFile functio ...
- 在Firefox中发现一个在Linux下查看chm文档的插件
在Firefox浏览器插件中搜索插件chmfox插件,安装后就可以在linux下通过Firefox浏览器阅读chm文档了.
- Linux下查看目录文件数和文件大小
一.查看当前目录下文件个数 在linux下查看目录下有多少文件可以用:ls -l 命令查看,ls -lR 递归查看所有目录, 如果文件很多,则用wc命令 和 grep 命令进行过滤. wc命令显示输 ...
- Linux下部署多个Tomcat(完整)
Linux下部署多个Tomcat 1.环境:1.1.Centos 5.01.2.apache-tomcat-6.0.18 2.需要解决一下几个问题2.1.不同的tomcat启动和关闭监听不同的端口2. ...
- Linux下读取默认MAC地址
导读MAC(Media Access Control,介质访问控制)计算机通过它来定义并识别网络设备的位置.在嵌入式linux学习中不可避免也会遇到MAC,本文主要描述了如何通过操作OTP来读取嵌入式 ...
随机推荐
- 【转载】来自苹果的编程语言——Swift简介
本文转自Lucida的博客 (新浪微博.豆瓣) 这篇文章简要介绍了苹果于WWDC 2014发布的编程语言——Swift. 前言 在这里我认为有必要提一下Brec Victor的Invent ...
- eclipse 软件的背景颜色、字体设置
1.eclipse 背景色设置: Window->Preferences->General->Editors->Text Editors->Backgroud color ...
- 关于listener
View.OnKeyListener |_____onKey(View v, int keyCode, KeyEvent event) View.OnTouchListener |_____onTou ...
- Delph控制台(Console)程序添加图标和版权信息
Delphi创建控制台(Console)程序默认是无法添加图标和版权的.经过仔细的对比窗体程序与控制台程序源码,发现窗体程序的工程文中,在uses结束begin开始的地方有一句如下代码:{$R *.r ...
- POJ 2892 Tunnel Warfare (SBT + stack)
题意:给定了初始的状态:有n个村庄连成一条直线,现在有三种操作: 1.摧毁一个村庄 2.询问某个村庄,输出与该村庄相连的村庄数量(包括自己) 3.修复被摧毁的村庄,优先修复最近被摧毁的........ ...
- Chapter 1. Hello, Perl/Tk
Chapter 1. Hello, Perl/Tk 内容: Perl/Tk Concepts Some Perl/Tk History Getting Started with Perl/Tk Hel ...
- rails跑通第一个demo
rails -h 查看帮助 Usage: rails new APP_PATH [options] Options: -r, [--ruby=PATH] # Path to the Ruby bina ...
- 【DSA MOOC】起泡排序的原理及常数优化
根据学堂在线TsinghuaX: 30240184X 数据结构(2015秋)这门课的内容,对bubblesort做了一些总结. 1. bubblesort(起泡排序),原理来自这样一个观察规律:若序列 ...
- Another attempt about LSI
Last week I was here Natural Language Processing in NZ. Someone asked a question, is there any exist ...
- [分享]源代码&开发手记:SAE应用“车百科” (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, jobs)
[分享]源代码&开发手记:SAE应用"车百科" (Python + SAE + Bottle + Bootstrap) - Bottle - Python4cn(news, ...