【摘要】 介绍bmp图片上下翻转、添加水印、通过学习bmp图片结构学习文件编程。
bmp图片练习文件操作(专题练习) 1. bmp图片数据取模,模拟图片取模软件。(选择16位或者24位取模方式)
16位。
2. bmp图片放大缩小,根据输入的尺寸放大缩小图片。
3. 实现图片4种翻转效果: 上、下、左、右。
4. 给图片的指定位置添加水印
要求: 在图片的任意位置,添加任意的文字水印。
比如: xxx路口 20181008 11:04
将字库加入: ascii和中文gbk字库
目录作业: 拷贝目录下所有文件(指定后缀的文件)到指定目录下,考虑一层目录。
多层目录拷贝。
makefile作业: 使用makefile建立工程,只需要写一个makefile文件。
(1)bmp图片上下翻转实现#include #include #include #include /* 必须在结构体定义之前使用,这是为了让结构体中各成员按1字节对齐 */#pragma pack(1)/*需要文件信息头:14个字节 */struct tagbitmap_file_header{ unsigned short bftype; //保存图片类似。 'bm' -- 0x4d42 unsigned int bfsize; //图片的大小 unsigned short bfreserved1; unsigned short bfreserved2; unsigned int bfoffbits; //rgb数据偏移地址};/* 位图参数信息 */struct tagbitmap_info_header { unsigned long bisize; //结构体大小 unsigned long biwidth; //宽度 unsigned long biheight; //高度 unsigned short biplanes; unsigned short bibitcount; //颜色位数 unsigned long bicompression; unsigned long bisizeimage; unsigned long bixpelspermeter; unsigned long biypelspermeter; unsigned long biclrused; unsigned long biclrimportant;};/*函数功能: bmp图片翻转函数参数: char *src_bmpfile :bmp图片源文件 char *new_bmpfile :新文件返回值 :0表示成功,其他值失败*/int bmpoverturn(char *src_bmpfile,char *new_bmpfile){ /*1. 打开源文件*/ int err=0; file *bmp_file=fopen(src_bmpfile,rb); if(bmp_file==null) { err=1; goto error; } /*2. 图片参数获取*/ struct tagbitmap_file_header src_head; //bmp文件头 memset(&src_head,0,sizeof(struct tagbitmap_file_header)); if(fread(&src_head,1,sizeof(struct tagbitmap_file_header),bmp_file)!=sizeof(struct tagbitmap_file_header)) { err=2; goto error; } if(src_head.bftype!=0x4d42) //判断类型 { err=3; goto error; } struct tagbitmap_info_header src_info; //bmp图像参数 memset(&src_info,0,sizeof(struct tagbitmap_info_header)); if(fread(&src_info,1,sizeof(struct tagbitmap_info_header),bmp_file)!=sizeof(struct tagbitmap_info_header)) { err=4; goto error; } if(src_info.bibitcount!=24) //判断颜色位数 { err=5; goto error; } /*3. 创建新图片*/ file *new_file=fopen(new_bmpfile,wb); if(new_file==null) { err=6; goto error; } /*3.1 创建bmp文件头*/ fwrite(&src_head,1,sizeof(struct tagbitmap_file_header),new_file); /*3.2 创建bmp图像参数*/ fwrite(&src_info,1,sizeof(struct tagbitmap_info_header),new_file); /*3.3 实现图片上下翻转*/ int i; int linebyte=src_info.biwidth*3; //一行总字节数量 if(linebyte%4)linebyte++; int offset=linebyte*(src_info.biheight-1)+src_head.bfoffbits; char *data_p=malloc(linebyte); if(data_p==null) { err=7; goto error; } for(i=0;i;i++)> (2)bmp图片水印添加#include #include #include #include /* 必须在结构体定义之前使用,这是为了让结构体中各成员按1字节对齐 */#pragma pack(1)/*需要文件信息头:14个字节 */struct tagbitmap_file_header{ unsigned short bftype; //保存图片类似。 'bm' -- 0x4d42 unsigned int bfsize; //图片的大小 unsigned short bfreserved1; unsigned short bfreserved2; unsigned int bfoffbits; //rgb数据偏移地址};/* 位图参数信息 */struct tagbitmap_info_header { unsigned long bisize; //结构体大小 unsigned long biwidth; //宽度 unsigned long biheight; //高度 unsigned short biplanes; unsigned short bibitcount; //颜色位数 unsigned long bicompression; unsigned long bisizeimage; unsigned long bixpelspermeter; unsigned long biypelspermeter; unsigned long biclrused; unsigned long biclrimportant;};/*-- 文字: 水 --*//*-- 宋体42; 此字体下对应的点阵为:宽x高=56x56 --*/const unsigned char font0[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x0c,0x00,0x00,0x00,0x00,0x7c,0x00,0x0e,0x00,0x00,0x00,0x00,0x7e,0x00,0x1f,0x00,0x00,0x00,0x00,0x7e,0x00,0x3f,0x80,0x00,0x00,0x00,0x7e,0x00,0x7f,0xc0,0x00,0x00,0x18,0x7e,0x00,0xfe,0x00,0x00,0x00,0x3c,0x7f,0x00,0xf8,0x00,0x1f,0xff,0xfe,0x7f,0x03,0xf0,0x00,0x0f,0xff,0xff,0x7f,0x87,0xc0,0x00,0x07,0x80,0x7e,0x7f,0x8f,0x80,0x00,0x00,0x00,0x7c,0x7f,0x9f,0x00,0x00,0x00,0x00,0x7c,0x7f,0xfc,0x00,0x00,0x00,0x00,0xf8,0x7d,0xf8,0x00,0x00,0x00,0x00,0xf8,0x7d,0xe0,0x00,0x00,0x00,0x00,0xf8,0x7c,0xe0,0x00,0x00,0x00,0x01,0xf0,0x7c,0xf0,0x00,0x00,0x00,0x01,0xf0,0x7c,0xf0,0x00,0x00,0x00,0x01,0xf0,0x7c,0x78,0x00,0x00,0x00,0x03,0xe0,0x7c,0x7c,0x00,0x00,0x00,0x03,0xe0,0x7c,0x3c,0x00,0x00,0x00,0x07,0xc0,0x7c,0x3e,0x00,0x00,0x00,0x07,0xc0,0x7c,0x1e,0x00,0x00,0x00,0x0f,0x80,0x7c,0x1f,0x00,0x00,0x00,0x0f,0x80,0x7c,0x0f,0x80,0x00,0x00,0x1f,0x00,0x7c,0x0f,0xc0,0x00,0x00,0x1e,0x00,0x7c,0x07,0xe0,0x00,0x00,0x3e,0x00,0x7c,0x03,0xe0,0x00,0x00,0x3c,0x00,0x7c,0x03,0xf0,0x00,0x00,0x78,0x00,0x7c,0x01,0xfc,0x00,0x00,0xf8,0x00,0x7c,0x00,0xfe,0x00,0x00,0xf0,0x00,0x7c,0x00,0xff,0x00,0x01,0xe0,0x00,0x7c,0x00,0x7f,0xc0,0x03,0xc0,0x00,0x7c,0x00,0x3f,0xe0,0x07,0x80,0x00,0x7c,0x00,0x1f,0xfc,0x0f,0x00,0x00,0x7c,0x00,0x0f,0xfc,0x1e,0x00,0x00,0x7c,0x00,0x07,0xe0,0x1c,0x00,0x00,0x7c,0x00,0x03,0xc0,0x38,0x00,0x7f,0xfc,0x00,0x01,0x80,0x00,0x00,0x7f,0xfc,0x00,0x00,0x00,0x00,0x00,0x0f,0xfc,0x00,0x00,0x00,0x00,0x00,0x03,0xf8,0x00,0x00,0x00,0x00,0x00,0x01,0xf0,0x00,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*-- 文字: 印 --*//*-- 宋体42; 此字体下对应的点阵为:宽x高=56x56 --*/const unsigned char font1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xe0,0x00,0x00,0x00,0x00,0x00,0x0f,0xf0,0x00,0x00,0x00,0x00,0x00,0x3f,0xf0,0x00,0x00,0x00,0x00,0x00,0xff,0xe0,0x00,0x03,0x00,0x01,0x87,0xf8,0x03,0x80,0x03,0xc0,0x01,0xff,0xc0,0x03,0xff,0xff,0xe0,0x01,0xfc,0x00,0x03,0xff,0xff,0xe0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x03,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x07,0x83,0xc0,0x07,0xc0,0x01,0xff,0xff,0xc3,0xc0,0x07,0xc0,0x01,0xff,0xff,0xe3,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x03,0xc0,0x07,0xc0,0x01,0xe0,0x00,0x73,0xc0,0x07,0xc0,0x01,0xe0,0x03,0xf3,0xc0,0x07,0xc0,0x01,0xe0,0x3f,0x83,0xc0,0x07,0xc0,0x01,0xe1,0xfe,0x03,0xc7,0xff,0xc0,0x01,0xff,0xf0,0x03,0xc1,0xff,0xc0,0x03,0xff,0xc0,0x03,0xc0,0x7f,0x80,0x03,0xff,0x00,0x03,0xc0,0x1f,0x00,0x01,0xfc,0x00,0x03,0xc0,0x0e,0x00,0x01,0xf0,0x00,0x03,0xc0,0x00,0x00,0x00,0xe0,0x00,0x03,0xc0,0x00,0x00,0x00,0x40,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0xc0,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*函数功能: 针对bmp图片实现的画点函数函数参数: char *bmp_mem :表示bmp图片rgb颜色数据的首地址 int x int y int color :画点的颜色值 bmp_drawpoint(bmp_mem,100,100,0);*/unsigned int bmp_width; //保存bmp图片的宽度void bmp_drawpoint(unsigned char *bmp_mem,int x,int y,int color){ unsigned char *rgb=(unsigned char *)(bmp_mem+y*bmp_width*3+x*3); *rgb=color>>0&0xff; *(rgb+1)=color>>8&0xff; *(rgb+2)=color>>16&0xff;}/*函数功能: 在bmp图片的指定位置添加字符串说明: 传入的取模字体必须是8的倍数(宽度和高度是相等)*/void bmp_showstring(unsigned char *bmp_mem,unsigned char *font,int x,int y,int size,int color){ int i,j; int x0=x; unsigned char data; for(i=0;i 学习makefile 1. 学习什么是目标文件: 该如何定义
2. 学习什么是目标依赖文件:该如何定义
3. makefile本身推导规则: 如何根据目标和目标依赖文件去进行编译生成目标。
4. 学习特殊变量的定义和功能使用: vpath\ cc\ cflags
5. 条件判断语句、常用的几个函数 $(shell ls)。
6. 自动化编译的符号: $@ $
小米空调性价比优势不强,难破空调市场格局
人民的名义火了!但里面手机关机了为什么还能定位呢?详细剖析sim以及手机定位的原理
INTEL 研祥助力中国高校EIP(嵌入式)
GFS、AFS分布式文件系统
废弃PCB板的回收处理方法解析
Linux开发_介绍BMP图片上下翻转、添加水印
全球范围内 人工智能领域的专利申请量总体上呈逐年上升趋势
雨天直接人工操作 无人驾驶汽车离真正的投入使用还有很长的路要走
第三方机构对亚马逊和微软的人脸识别程序进行测试
盘点OPPOFindX小欧的那些黑科技
PCB抄板之PROTEL到ALLEGRO的转换技术2
PCI Express交换机实测系统数据传输性能
5G时代,网速和覆盖范围更快更广
TI宣布9亿美元收购美光12寸晶圆厂
滚珠丝杆高效测量方案:SJ5780双向轮廓测量仪
另辟蹊径,奇虎360开发柔性屏智能音箱冲击高端市场
合封芯片开发就找宇凡微,提供合封芯片技术支持与资讯
布里斯托大学采用赛灵思技术为的 SDN 控制 5G互联测试平台
用SSL加密增强FTP服务器安全性
TCL 华星推出搭载 In-Cell 主动笔技术的 10.95”屏幕,支持倾斜感应 / 悬浮触控