最后是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
int main(int agrc, char **agrv)
{
int fd,bmpfd;
int x=0, y=0, k=0;
char buf;
int *buffer = NULL;
//char bmp[800*480*3];
char bmp[640*480*3];
fd = open("/dev/fb0", O_RDWR);
if(fd < 0)
{
perror("error!can't open /dev/fb0");
exit(-1);
}
bmpfd = open("./image.bmp", O_RDWR);
if(bmpfd < 0)
{
perror("error!can't open image");
exit(-1);
}
buffer = (int *)mmap(NULL, 640*480*4, PROT_READ|PROT_WRITE, MAP_SHARED,fd, 0);
//for(x=0; x<480; x++)
// for(y=0; y<800;y++)
// buffer[x*640+y] = 0x00ff0000;
// lseek(bmpfd, 54, SEEK_CUR);
read(bmpfd,bmp,640*480*3);
for(x=480-1; x>=0; x--)
for(y=0; y<640;y++)
{
buffer[x*640+y] = bmp[2+k*3]<<16|bmp[1+3*k]<<8|bmp[0+k*3];
k++;
}
//if(!strcasecmp(agrv[1], "on"))
buf = 0x00;
//else
// buf = 0x01;
write(fd,&buf,1);
close(fd);
return 0;
}