69,373
社区成员
发帖
与我相关
我的任务
分享
for(i=0;i<220;i++)
{
for(j=0;j<176;j++)
buffer[i][j]=0;
}
for(i=0;i<220;i++)
{
for(j=0;j<176;j++)
buffer[i][j]=0;
}
for(i=0;i<height;i++)
{
for(j=0;j<widthbyte;j+=3)
{
temp0=image[i*widthbyte+j]>>3;
temp1=image[i*widthbyte+j+1]>>2;
temp2=image[i*widthbyte+j+2]>>3;
buffer[i][j/3]=temp2;
buffer[i][j/3]+=temp1<<5;
buffer[i][j/3]+=temp0<<11;
}
}
#include "stdio.h"
int main()
{
FILE *fp,*fout;
int i,j;
unsigned short width,height,widthbyte;
unsigned short temp0,temp1,temp2;
unsigned char ch1,ch2;
unsigned char image[116160];
unsigned short buffer[220][172];
if((fp=fopen("1.bmp","rb"))==NULL)
{
printf("Can't open BMP file!");
}
ch1=fgetc(fp);
ch2=fgetc(fp);
if((ch1!='B')||(ch2!='M'))
{
printf("It's Not BMP file! ");
}
fseek(fp,0x1c,0);
ch1=fgetc(fp);
if(ch1!=0x18)
{
printf("It's Not 24bit true color BMP file! ");
}
if((fout=fopen("1.h","wt"))==NULL)
{
printf("Can't create tiger.h file ");
}
fseek(fp,0x12,0);
fread(&width,1,4,fp);
fseek(fp,0x16,0);
fread(&height,1,4,fp);
if((width>0xB0)||(height>0xDC))
{
printf("The size of BMP is too big! ");
}
if((width*3%4)==0)
{
widthbyte=width*3;
}
else
{
widthbyte=(width*3/4)*4+4;
}
fseek(fp,0x0a,0);
ch1=fgetc(fp);
fseek(fp,ch1,0);
fread(image,1,116160,fp);
for(i=0;i<220;i++)
{
for(j=0;j<176;j++)
{
buffer[i][j]=0;
}
}
for(i=0;i<height;i++)
{
for(j=0;j<widthbyte;j+=3)
{
temp0=image[i*widthbyte+j]>>3;
temp1=image[i*widthbyte+j+1]>>2;
temp2=image[i*widthbyte+j+2]>>3;
buffer[i][j/3]=temp2;
buffer[i][j/3]+=temp1<<5;
buffer[i][j/3]+=temp0<<11;
}
}
fprintf(fout,"/**//*The info of BMPDATA:width=%d height=%d*/ ",width,height);
fprintf(fout,"const unsigned short lcdbuffer[%d][%d]={...}{ ",width,height);
for(i=0;i<height;i++)
{
fprintf(fout,"{");
for(j=0;j<width;j++)
{
fprintf(fout,"0x%x,",buffer[i][j]);
if((j+1)%8==0)
{
fprintf(fout," ");
}
}
fprintf(fout,"} ");
}
fprintf(fout,"}; ");
fclose(fp);
fclose(fout);
system("pause");
return 0;
}
for(i=0;i<220;i++)
{
for(j=0;j<176;j++)
buffer[i][j]=0;
}
for(i=0;i<height;i++)
{
for(j=0;j<widthbyte;j+=3)
{
temp0=image[i*widthbyte+j]>>3;//对每个像素的第一个值右移3位
temp1=image[i*widthbyte+j+1]>>2;
temp2=image[i*widthbyte+j+2]>>3;
buffer[i][j/3]=temp2;//将三个像素的每一位做位移后相加成为一个矩阵单元的值,结果为220*176
buffer[i][j/3]+=temp1<<5;
buffer[i][j/3]+=temp0<<11;
}
}
//总体为对每一个像素的R G B量做相应运算后,在合成一个像素点还原。