http://blog.csdn.net/morixinguan/article/details/50719472

关于BMP图的介绍之前已经说过了,最近要用到,又要重新开始学习。

现在实现一个让bmp左转的效果:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

#define  RGB(r,g,b)    		((r<<16)|(g<<8)|b)

typedef  unsigned char  U8 ;
typedef  unsigned short U16 ;
typedef  unsigned int   U32 ; 

#pragma  pack(1)
struct bmp_header
{
	//bmp header
	U8  Signatue[2] ;   // B  M
	U32 FileSize ;     //文件大小
	U16 Reserv1 ;
	U16 Reserv2 ;
	U32 FileOffset ;   //文件头偏移量

	//DIB header
	U32 DIBHeaderSize ; //DIB头大小
	U32 ImageWidth   ;  //文件宽度
	U32 ImageHight   ;  //文件高度
	U16 Planes       ;
	U16 BPP          ;  //每个相素点的位数
	U32 Compression  ;
	U32 ImageSize    ;  //图文件大小
	U32 XPPM ;
	U32 YPPM ;
	U32 CCT ;
	U32 ICC ;
};
#pragma  pack()

int main(int argc , char **argv)
{
	if(argc != 3)
		return -1 ; 

	int fd ;
	int dest_fd ;
	fd = open(argv[1] , O_RDONLY);
	if(-1 == fd)
	{
		perror("open bmp file fail");
		return -2 ;
	}

	dest_fd = open( argv[2] , O_RDWR | O_CREAT|O_TRUNC , 0777);
	if(dest_fd < 0 )
	{
		perror("open rgb565 fail");
		return -3 ;
	}

	struct bmp_header  header ; 

	int ret ; 

	ret = read(fd , &header , sizeof(struct bmp_header));

	printf(" Signatue[0]      : %c  \n " , header.Signatue[0]  );
	printf(" Signatue[1]      : %c  \n " , header.Signatue[1]  );
	printf(" FileSize         : %d  \n " , header.FileSize     );
	printf(" Reserv1          : %d  \n " , header.Reserv1      );
	printf(" Reserv2          : %d  \n " , header.Reserv2      );
	printf(" FileOffset       : %d  \n " , header.FileOffset   );
	printf(" DIBHeaderSize    : %d  \n " , header.DIBHeaderSize);
	printf(" ImageWidth       : %d  \n " , header.ImageWidth   );
	printf(" ImageHight       : %d  \n " , header.ImageHight   );
	printf(" Planes           : %d  \n " , header.Planes       );
	printf(" BPP              : %d  \n " , header.BPP          );
	printf(" Compression      : %d  \n " , header.Compression  );
	printf(" ImageSize        : %d  \n " , header.ImageSize    );
	printf(" XPPM             : %d  \n " , header.XPPM         );
	printf(" YPPM             : %d  \n " , header.YPPM         );
	printf(" CCT              : %d  \n " , header.CCT          );
	printf(" ICC              : %d  \n " , header.ICC          );

	char buffer[header.ImageSize] ; 

	read(fd , buffer , header.ImageSize);

	close(fd);

	//改变地方
	header.ImageWidth = 480;
	header.ImageHight = 800 ; 

	write(dest_fd , &header , sizeof(struct bmp_header));

	int row , col ;
	char *p = NULL ; 

	for(col = 0 ; col < 800; col++)
	{
		for(row = 480-1 ; row >= 0; row--)
		{
			p =( buffer+(row*800 + col)*3);
		//	data = RGB((unsigned char)(*(p+2)) , (unsigned char)(*(p+1)) ,
		//	(unsigned char )(*(p)));
			write(dest_fd , p , 3);
		}
	}

	close(dest_fd);

	return 0 ;
}

最新文章

  1. MySQL+Amoeba实现数据库主从复制和读写分离
  2. NSDate用法整理总结
  3. 二十六、【开源框架】EFW框架Winform前端开发之Grid++Report报表、条形码、Excel导出、图表控件
  4. 释放用完的Excel COM组件
  5. Codeforces Round #306 (Div. 2) B. Preparing Olympiad dfs
  6. C#数据上传方法
  7. GCDTimer
  8. WebService调用1(.Net)
  9. windows迁移linux问题集锦[ZZ]
  10. jquery结合Highcharts插件实现动态数据仪表盘图形化显示效果
  11. 导出csv文件代码示例
  12. InvalidateRect只是增加重绘区域,在下次WM_PAINT的时候才生效
  13. JQuery实现两侧浮动广告
  14. AOP执行增强-Spring 源码系列(5)
  15. 快速排序算法的C语言实现
  16. Java Client/Server 基础知识
  17. 【转】HTTP请求中的form data和request payload的区别
  18. java并发中的Semaphore
  19. web请求流程
  20. PHP导出CVS格式文件

热门文章

  1. ●BZOJ 4556 [Tjoi2016&amp;Heoi2016]字符串
  2. [2017.4.7校内训练赛by hzwer]
  3. [51nod1238]最小公倍数之和V3
  4. 为什么Unix只允许对非目录文件实行勾链?
  5. BI之SSIS入门最新版Visual Studio调试技巧
  6. idea热部署
  7. SQL Server 2016 非域Aways On环境搭建
  8. python学习之路基础篇(三)
  9. sa账号无法登陆sqlserver2008
  10. CRM客户关系管理系统(四)