📄 bmp.c.bak
字号:
#include "stdio.h"
int main(void)
{
FILE *fp,*fout;
unsigned short t,widthbmp,heightbmp; //bmp store width and height
unsigned char ch1,ch2,width,height,heightlcd;
unsigned char image[1024];
unsigned char temp[7168];
unsigned char lcd[896];
unsigned char screen[20];
int i,j,k;
printf("input the file name");
screen=scanf("c%",&c1);
if((fp=fopen("screen.bmp","rb"))==NULL)
{
printf("Can't open screen.bmp\n");
return 0;
}
if((fout=fopen("screen.h","wt"))==NULL)
{
printf("Can't open screen.h\n");
return 0;
}
ch1=fgetc(fp);
ch2=fgetc(fp);
if((ch1!='B')||(ch2!='M'))
{
printf("Not BMP file\n");
return 0;
}
fseek(fp,0x0e,0);
ch1=fgetc(fp);
if(ch1!=0x28)
{
printf("Not windows BMP\n");
return 0;
}
fseek(fp,0x12,0);
width=fgetc(fp);
if(width%8==0)
t=width/8;
else
t=width/8+1;
if(t%4==0)
widthbmp=t;
else
widthbmp=(t+4-(t%4));
fseek(fp,0x16,0);
height=fgetc(fp);
if(height%8==0)
{
heightbmp=height;
heightlcd=height/8;
}
else
{
heightbmp=(height/8+1)*8;
heightlcd=height/8+1;
}
fseek(fp,0x1c,0);
ch1=fgetc(fp);
if(ch1!=0x01)
{
printf("Not a Black-White image file\n");
return 0;
}
fseek(fp,0x0a,0);
ch1=fgetc(fp);
fseek(fp,ch1,0);
fread(image,1024,1,fp);
for(i=0;i<7168;i++) temp[i]=1;
for(j=0;j<height;j++)
for(i=0;i<t;i++)
for(k=0;k<8;k++)
temp[8*i+k+j*t*8]=(((image[i+j*widthbmp]<<k)&0x80)>>7);
for(i=0;i<7168;i++)
temp[i]=(temp[i]-1)&1;
for(j=0;j<heightlcd;j++)
for(i=0;i<width;i++)
{
lcd[j*width+i]=0;
for(k=0;k<8;k++)
lcd[j*width+i]=lcd[j*width+i]+(temp[i+k*t*8+j*8*t*8]<<k);
}
fprintf(fout,"//width=%d t=%d widthbmp=%d heightlcd=%d\n",width,t,widthbmp,heightlcd);
fprintf(fout,"const unsigned char screen[%d]={%d,%d,\n",width*heightlcd+2,width,heightlcd);
for(i=0;i<(heightlcd);i++)
{
for(j=0;j<width;j++)
fprintf(fout,"0x%x,",lcd[j+i*width]);
fprintf(fout,"\n");
}
fprintf(fout,"};\n");
printf("ok\n");
fclose(fp);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -