#include <linux/fb.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <string.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h>//int close(int fd); struct fb_dev { int fb; void *fb_mem; int fb_width, fb_height, fb_line_len, fb_size; int fb_bpp; } fbdev; int fb_stat(int fd) { struct fb_fix_screeninfo fb_finfo; struct fb_var_screeninfo fb_vinfo; if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_finfo)) { perror(__func__); return (-1); } if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_vinfo)) { perror(__func__); return (-1); } fbdev.fb_width = fb_vinfo.xres; fbdev.fb_height = fb_vinfo.yres; fbdev.fb_bpp = fb_vinfo.bits_per_pixel; fbdev.fb_line_len = fb_finfo.line_length; //fbdev.fb_size = fb_finfo.smem_len; fbdev.fb_size = fb_vinfo.xres * fb_vinfo.yres * fb_vinfo.bits_per_pixel / 8; return (0); } int main(int argc, char **argv) { int fb; if ((fb = open("/dev/fb0", O_RDWR)) < 0) { perror(__func__); return (-1); } fb_stat(fb); fbdev.fb_mem = mmap (NULL, fbdev.fb_size, PROT_READ|PROT_WRITE, MAP_SHARED, fb, 0); fbdev.fb = fb; unsigned char *dst = ((unsigned char *) fbdev.fb_mem); memset(dst, 0x7f, fbdev.fb_size); sleep(1); munmap(fbdev.fb_mem,fbdev.fb_size); close(fb); return 0; }
以上代码仅供参考。