bmp转十六进制hex样例_bmp图片转成hex-程序员宅基地

技术标签: 图像处理  

// $  xxd -i logo.bmp logo.h


#include <stdio.h>

//TO_DO ++++++++

unsigned char logo_bmp[] = {
	  0x42, 0x4d, 0xde, 0xc9, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00,
	  0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x22, 0x01,
	  0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	  0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0x00, 0x00,
	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	...
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned int logo_bmp_len = 117214;


//bmp width, height
int bytes_per_bpp = 3;
int bmp_width = 134;
int bmp_height = 290;
unsigned int file_len = 117214;
unsigned char *bmp_file_data = logo_bmp;
#define REVERT_BMP  1   //revert the bmp: 1, don't revert: 0
//TO_DO  --------


/*bmp文件的前部是文件头信息,aboot中画图不需要这些
 * 1 删除文件头信息,
 * 
 * 以 24bit bmp: 134X290 为例
 * 图片每一行134个像素,每个像素3个字节,所以每一行是134*3 == 402个字节,
 * bmp会在每一行的最后添加两个字节对齐。
 * aboot中要用这个图片的话,
 * 2.要把每行最后的两个对齐字节删除
 * 
 * 每行最后的两个字节删除以后
 * 因为bmp本身的图片是倒的,
 * 3.反转整张图
 * 
 * 反转整张图以后,R和B也互换了,导致颜色不对
 * R、G、B各占一个字节,
 * 4.这里是使其中的R 和 B互换。
 * 
 * 所以,如果把拿到手的图片先在windows上做一下180度的旋转,
 * 应该可以省略步骤3和4,把上面的 REVERT_BMP 设定为0 即可。
 */
int main()
{
	unsigned int i = 0;
	unsigned int j = 0;
	unsigned int bmp_info_len = 0;
	unsigned int temp = 0;
	unsigned int actual_data_len = 0;
	unsigned char result_arry[file_len];
	unsigned char result_arry2[file_len];
	unsigned int data_bytes_per_row = (bmp_width*bytes_per_bpp);
	unsigned int total_bytes_per_row = 0;
	unsigned int null_bytes_per_row = 0;
	unsigned int array_len = 0; 
	if(data_bytes_per_row%4 != 0)
	{
		null_bytes_per_row = 4-data_bytes_per_row%4;
	}

	total_bytes_per_row = data_bytes_per_row + null_bytes_per_row;//total bytes per row
	bmp_info_len = file_len - total_bytes_per_row*bmp_height;//bmp file info len,or len to delete
	printf("file_len:---------------> %d \n",file_len);
	printf("bmp_info_len:-----------> %d \nnull_bytes_per_row:-----> %d\n",bmp_info_len,null_bytes_per_row);


	//1 删除文件头信息,
	for(i=bmp_info_len,j=0;i<file_len;i++,j++)
	{
		result_arry2[j] = bmp_file_data[i];
	}
	array_len = j;
	printf("step 1 over.\n");
	printf("data total_bytes:-------> %d \n",file_len-bmp_info_len);
	printf("total_bytes_per_row:----> %d \n",total_bytes_per_row);

	//in data <-- bmp_file_data[..]
	//2.删除每行最后的若干个字节,存于result_arry2
	for(i=1,j=0;i<=array_len;i++)
	{
		//delete null data at the end of row 
		result_arry[j] = result_arry2[i-1];
		j++;
		if(i%total_bytes_per_row==0)
		{
			j -= null_bytes_per_row;
		}

	}// out data to -->result_arry[..]
	printf("step 2 over.\n");

	array_len = j;

#if REVERT_BMP
	//3.这里是反转整张图
	for(i=0,j=0;i<array_len;i++,j++)
	{
		result_arry2[j] = result_arry[array_len-i-1];
	}
	printf("step 3 over.\n");
	//in data <-- result_arry[..]
	//4. R、G、B各占一个字节,这里是使其中的R 和 B互换。
	for(i=0,j=0;i<array_len;)
	{
		result_arry[j] = result_arry2[i+2];
		result_arry[j+1] = result_arry2[i+1];
		result_arry[j+2] = result_arry2[i];
		i += 3;
		j += 3;
	}
	printf("step 4 over.\n");
#endif
	printf("actual data array_len:---> %d \n",array_len);

	FILE* fout = fopen("resutfile.h","w+");
	if (fout == NULL) {
		printf("Failed to open\n");
		return;
	}
	for (i=0;i<array_len;)
	{
		fprintf(fout,"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, \n",
				result_arry[i],result_arry[i+1],result_arry[i+2],result_arry[i+3],
				result_arry[i+4],result_arry[i+5],result_arry[i+6],result_arry[i+7],
				result_arry[i+8],result_arry[i+9],result_arry[i+10],result_arry[i+11]);
		i +=12;
	}

	if (fclose(fout) != 0) {
		printf("Failed to close \n");
		return;
	}


}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/fightingTony/article/details/52345524

智能推荐

【C1N短网址】微信分享卡片来了-程序员宅基地

文章浏览阅读59次。按如下格式发送消息到公众号,公众号自动回复微信卡片,然后就可以分享啦。关注微信公众号“C1N短网址服务”免费薅。如果你需要自己指定图片,则可以增加第四行。

谭浩强c++第七章题1 定义一个结构体变量(包括年、月、日),编写程序,要求输入年、月、日,程序能计算并输出该日在本年中是第几天。注意闰年问题。_定义一个结构体变量,编写程序,用户输入年月日,计算机给出该日在本年的第几天。注-程序员宅基地

文章浏览阅读3.5k次,点赞3次,收藏15次。#include <iostream>#include <cstring>using namespace std;struct datea{ int year; int month; int day;};int main(){ int print(datea &); int days; datea d; cout<<..._定义一个结构体变量,编写程序,用户输入年月日,计算机给出该日在本年的第几天。注

android sql插入数据,Android:插入/更新多个记录到SQL数据库-程序员宅基地

文章浏览阅读533次。好吧,也许我完全错过了一些东西,但我刚刚开始使用SQL和Android,并且从我所看到的更新和插入到数据库需要单独处理?我可以检索包含多个记录的游标,但是如果我想将更新应用于游标中的每个记录,我只能看到如何单独使用ContentValues和Update(),然后光标需要重装?Android:插入/更新多个记录到SQL数据库同样如果我想创建多个新记录,这些似乎需要单独插入?我可以不创建列表和批量插..._android从数据库加载几万条记录到数据库

elasticsearch实现博客搜索_博客文章通过3种方式添加全文模糊搜索-程序员宅基地

文章浏览阅读561次。背景介绍 最近在给博客做SEO,顺便也学学怎么与搜索引擎打交道 发现自己站内没有一个像样的搜索功能 于是全文搜索便是第一步给博客文章添加全文搜索,摸索着尝试了3种方案 可以根据具体项目选择 数据库:Mysql 1.SQL Like 查询 ~初级方案~使用作为最简单的方式,直接使用like条件在ttitle和content中查询 select 优势1.简单 2.简单 3.简单劣势1.效率低下,查询..._博客搜索功能实现

hive on spark hql 插入数据报错 Failed to create Spark client for Spark session Error code 30041_rg.apache.hadoop.hive.ql.exec.spark.sparktask. fai-程序员宅基地

文章浏览阅读6.1k次,点赞13次,收藏25次。Failed to execute spark task, with exception 'org.apache.hadoop.hive.ql.metadata.HiveException(Failed to create Spark client for Spark session 50cec71c-2636-4d99-8de2-a580ae3f1c58)'FAILED: Execution Error, return code 30041 from org.apache.hadoop.hive.ql._rg.apache.hadoop.hive.ql.exec.spark.sparktask. failed to create spark client

官方安装文档解读SAP S4 HANA架构_s4 hana architecture-程序员宅基地

文章浏览阅读2.5k次。官方安装文档解读SAP S4 HANA架构SAP HANA原生备份与恢复自己攒一台SAP S4 HANA服务器硬件配置参考BASIS模块管理为什么SAP ECC的系统,数据库总是和SAP的应用安装在一起SAP PI服务器,版本731 SYBASE数据库运维故障解决2粒ERP-SAP服务器集群架构技术沿革IBM小型机厉害的高级功能AIX下 SYBASE 数据库无法启动..._s4 hana architecture

随便推点

el-table格式化el-table-column内容_el-table-column 格式化-程序员宅基地

文章浏览阅读1.2k次。对于格式化,有三种方法:template scope、formatter一、template scope + v-if判断<el-table-column prop="sex" label="性别"> <template slot-scope="scope"> <span v-if="scope.row.sex== 0">男</span> <span v-if="scope.row.sex== 1">女_el-table-column 格式化

Qt知识点汇总——来自网络-程序员宅基地

文章浏览阅读1.3k次。为什么80%的码农都做不了架构师?>>> ..._toutf8和fromutf8

pycharm远程连接linux服务器上的jupyter-程序员宅基地

文章浏览阅读173次。首先得确保linux上安装了jupyter,并能启动服务,在linux命令行输入: jupyter notebook启动后效果。

iOS开发 --- 添加一个全局悬浮按钮_ios开发 悬浮-程序员宅基地

文章浏览阅读6.8k次。背景介绍 :在普通的iOS开发组中,一般测试机都不止一台,但是我们在开发的时候,不可能每台测试机时刻保持最新的代码,这就出现了一个问题,当测试测出问题的时候,(或者产品突然拿去点点看的时候出了问题)如果不知道当前的版本,可能不确定是什么时候出的问题。解决方案:如果当前环境是测试服的时候,展示一个全局浮动标签,这样不仅看到此标志就告诉测试(包括我们自己)当前的环境,当出现问题的时候,通过标签,可以快..._ios开发 悬浮

eclipse可以start模式可以启动项目但debug模式不能启动_eclipse tomcat debug就报错-程序员宅基地

文章浏览阅读577次。去掉所有断点即可解决问题。原因可能eclipse和tomcat的交互而产生的,在以debug模式启动tomcat时,发生了读取文件错误,eclipse自动设置了断点,导致tomcat不能正常启动。解决方法如下:以debug模式启动tomcat,打开breakpoints veiw,右键-> Remove all,重启下tomcat就OK了。_eclipse tomcat debug就报错

FreeMarker教程-程序员宅基地

文章浏览阅读330次。一、什么是模板引擎,为什么要用模板引擎在B/S程式设计中,常常有美工和程序员二个角色,他们具有不同专业技能:美工专注于表现——创建页面、风格、布局、效果等等可视元素;而程序员则忙于创建程式的商业流程,生成设计页面要显示的数据等等。很多时候,要显示的资料在设计的时候并不存在,它们一般是在运行时由程式产生的,比如执行“价格不高于800NT的USB Disk”查询的返回结果。这种技术需求产生了J..._freemarker教程