24位BMP转16位RGB565
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
24位BPM转16位BMP
有时我们需要用到16位的BMP文件,特别是在嵌入式的开发过程中。以下介绍如何用Photoshop将24位的BMP文件转变为16位的BMP文件。不常处理图片的朋友可以到xdowns上去下载一个精简的绿色版:/soft/31/93/2007/Soft_39369.html。
首先,打开需要转的BMP文件,当然,不是BMP的格式也没有问题,Photoshop支持的图档格式很全。
然后选择【文件】--【存储为】
出现保存文件的对话框,选择格式为BMP,设置好文件名和路径,点【保存】
此时出现文件格式选择的对话框,当然选择16位,然后点【高级模式】设置数据格式
我常用的是RGB565,点【保存】即可。
整个过程非常简单,但只能每次处理一张,如果遇到100张资源文件需要处理就麻烦了。BMP是最简单的图片格式了,没有采用任何压缩,24位就是每个点分别用3个字节记录RGB三色的数据,也就是RGB888,编个小工具处理成RGB565也非常简单,以下是网上搜罗的一个源码,供参考。有了这个小工具,配合批处理的FOR循环,就可以批量转换了。当然,你也可以在工具里遍历目录。
#include
//#include
#include
//#define uint8 unsigned char
typedef unsigned char uint8;
typedef char int8;
typedef unsigned short uint16; //32bit system
typedef short int16;
typedef unsigned int uint32;//32bit system
typedefint int32;
structbmp_filehead //14B
{
//2B 'BM'=0x424d;
uint16bmtype; //'BM',2B
uint32bmSize; //size,4B
uint32bmReserved;//0x00,4B
uint32bmOffBits;//4B, (54)
} head1;
structbmphead //40B
{
uint32bmpOffBits;//4B, (40)
uint32 bmp_wide;//4B,wide
uint32 bmp_high;//4B,high
uint16bmplans;//2B,0 or 1
uint16bitcount;//2B ,24
uint32bmpyasuo;//4B,0
uint32imagesize;//4B,w*h*3
uint32biXPelsPerMeter;
uint32biYPelsPerMeter;
uint32biClrUsed;
uint32biClrImportant;
} head2;
structBGR_data //40B
{
uint8 B_data;
uint8 G_data;
uint8 R_data;
} clr_data[1024*768]; //img size must less than 1024*768
int main()
{
FILE *fp,*out_fp;
int32k,q;
uint32 rec_cout,rec_cout2;
uint16 tp_16bit;
int8 tp_str[16];
//cout<<"test!"< printf("***************************************************\n"); printf("******24 bits bmp to 16 bits C file V1.0***********\n"); printf("**************huxuec 2011.1.11*********************\n"); printf("***************************************************\n"); //cout<<"8bit?="< //cout<<"16bit?="< //cout<<"32bit?="< //cout<<"head=?B:"< //cin>>k; while(1) { printf("Input bmp(24bit) full name: \n"); scanf("%s",&tp_str); //fopen("",); if((fp=fopen(tp_str,"r"))==NULL) { cout<<"open error!"< } else { //fread(); fseek(fp, 0, 0);//fseek(fp, offset, fromwhere); rec_cout=fread(&head1,sizeof(head1),1,fp); fseek(fp, 14, 0);//fseek(fp, offset, fromwhere); rec_cout2=fread(&head2,sizeof(head2),1,fp); fseek(fp, 54, 0);//fseek(fp, offset, fromwhere); rec_cout2=fread(&clr_data,3,(head2.bmp_wide*head2.bmp_high),fp); /* 从fp所指向文件的当前位置开始,一次读入size个字节,重复count次,