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