#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <strings.h>#include <sys/mman.h>int show_bmp(char path){ char bmp_buf[8004803] = {0}; int lcd_buf[800480] = {0}; bzero(bmp_buf,sizeof(bmp_buf)); bzero(lcd_buf,sizeof(lcd_buf)); //1、打开LCD int lcd_fd = open("/dev/fb0",O_RDWR); if(lcd_fd < 0) { perror(“open LCD”); return -1; } //2、打开图片 int bmp_fd = open(path,O_RDONLY); if(bmp_fd < 0) { perror(“open BMP”); return -2; }
//3、去掉不是像素的字节 54 int ret = lseek(bmp_fd,54,SEEK_SET); if(ret < 0) { perror(“lseek”); return -3; } //4、获取图片像素 :RGB int retval = read(bmp_fd,bmp_buf,sizeof(bmp_buf)); if(retval < 0) { perror(“read”); return -4; } //5、关闭图片 close(bmp_fd); //6、RGB —> ARGB int i; for(i=0; i<800480; i++) { lcd_buf[i] = bmp_buf[i3]<<0 | bmp_buf[i3+1]<<8 | bmp_buf[i3+2]<<16; } //7、显示(内存映射) int fd_mmap; fd_mmap = mmap(NULL, 8004804, PROT_READ|PROT_WRITE, MAP_SHARED, lcd_fd, 0); //8、图片翻转 for(int y=0; y<480; y++) { for(int x=0; x<800; x++) { (fd_mmap+(479-y)800+x) = lcd_buf[800y+x]; } }
//9、解除映射 munmap(fd_mmap,8004804); //10、关闭LCD close(lcd_fd); } void main(){ show_bmp("./01.bmp"); sleep(1); show_bmp("./02.bmp"); sleep(1); show_bmp("./03.bmp"); sleep(1); }