// 下面是样例代码 sample hifb.c
#include <stdio.h>
#include <fcntl.h>
#include <sys ioctl.h="">
#include <linux fb.h="">

#define DEVNAME "/dev/fb0"

int main(void) {
    int fd;
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    long int screensize;
    char *fbp = 0;
    int x, y;
    long int location;

    /* 打开设备文件 */
    fd = open(DEVNAME, O_RDWR);
    if (fd == -1) {
        perror("Error: cannot open framebuffer device");
        return 1;
    }
    printf("The framebuffer device was opened successfully.\n");

    /* 获取变量信息 */
    if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) {
        perror("Error: failed to get variable screen information");
        return 1;
    }

    /* 获取固定信息 */
    if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) {
        perror("Error: failed to get fixed screen information");
        return 1;
    }

    /* 计算屏幕大小 */
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

    /* 映射内存 */
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if ((int)fbp == -1) {
        perror("Error: failed to map framebuffer device to memory");
        return 1;
    }
    printf("The framebuffer device was mapped to memory successfully.\n");

    /* 在屏幕上绘制一些图形 */
    for (y = 0; y < vinfo.yres; y++) {
        for (x = 0; x < vinfo.xres; x++) {
            location = (x + vinfo.xoffset) * (vinfo.bits_per_pixel / 8) +
                       (y + vinfo.yoffset) * finfo.line_length;
            if (vinfo.bits_per_pixel == 32) {
                *(fbp + location) = 100;        // 红色
                *(fbp + location + 1) = 15;     // 绿色
                *(fbp + location + 2) = 200;    // 蓝色
                *(fbp + location + 3) = 0;      // 透明度
            } else { // 少于32位的像素格式
                *(fbp + location) = 1;
            }
        }
    }

    /* 解除映射 */
    munmap(fbp, screensize);

    /* 关闭设备文件 */
    close(fd);

    return 0;
}
</linux></sys></fcntl.h></stdio.h>