Code:
/*----------------------------------------------------------------
width*height schwarz-weiss bitmap in nokia 3310 daten wandeln
compiler: bcc32
OS: XP
robocat, 16.04.07
----------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <conio.h> // fuer getch()
// define glcd size here
unsigned int width=128;
unsigned int height=64;
int main()
{
FILE *pDatei;
unsigned int size,i,x,y,realwidth;
unsigned char buf[64],*file1,*file2;
long pos1,pos2;
realwidth=width/8;
while(realwidth%4!=0)realwidth++;
pDatei = fopen("J:\\test.bmp", "rb");
if(pDatei == NULL)
{
printf("Fehler beim Oeffnen der Quell-Datei!\n");
printf("Programm beendet.\n");
exit(1);
}
fseek(pDatei,0,SEEK_END);
pos2=ftell(pDatei);
fseek(pDatei,10,SEEK_SET);
fread(&pos1,4,1,pDatei);
fseek(pDatei,pos1,SEEK_SET);
size=pos2-pos1;
file1=malloc(size);
fread(file1,1,size,pDatei);
fclose(pDatei);
printf("size: %u (should be %u)\n",size,realwidth*height);
file2=(unsigned char*)malloc(width*height/8);
memset(file2,0,width*height/8);
for(x=0;x<width;x++)
{
for(y=0;y<height;y++)
{
if((*(file1+(y*realwidth*8+x)/8)>>(7-(x%8))&1)!=1)
{
*(file2+((height-y-1)/8)*width+x)|=1<<(7-(y%8));
}
}
}
pDatei = fopen("J:\\test.txt", "w");
if(pDatei == NULL)
{
printf("Fehler beim Oeffnen der Ziel-Datei!\n");
printf("Programm beendet.\n");
free(file1);
free(file2);
exit(1);
}
sprintf(buf,"unsigned char picture[]={");
fwrite (buf,strlen(buf),1,pDatei);
for(i=0;i<width*height/8;i++)
{
if(i%8==0)fwrite("\n",1,1,pDatei);
sprintf((char*)buf,"%u,",*(file2+i));
fwrite(buf,strlen(buf),1,pDatei);
}
fseek(pDatei,-1,SEEK_END);
fwrite ("};\n",3,1,pDatei);
fclose(pDatei);
free(file1);
free(file2);
printf("Programm erfolgreich beendet.\n");
getch();
return 0;
}
wäre toll, wenn du nochmal testen könntest, auch wenn du inzwischen eine andere lösung gefunden hast. es widerstrebt mir, hier code reinzustellen, der nicht tut was er soll.
Lesezeichen