1、操作的设备为:/dev/fb
(显存设备)
2、完整代码如下:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
int main(int argc, char **argv)
{
int fd;
fd = open("/dev/fb0", O_RDWR);
if (-1 == fd)
{
perror("open fb");
return -1;
}
struct fb_fix_screeninfo fixInfo;
if (ioctl(fd, FBIOGET_FSCREENINFO, &fixInfo) == -1)
{
perror("get fscreeninfo");
close(fd);
return -2;
}
printf("id = %s\n", fixInfo.id);
printf("line length = %d\n", fixInfo.line_length);
struct fb_var_screeninfo varInfo;
if (ioctl(fd, FBIOGET_VSCREENINFO, &varInfo) == -1)
{
perror("get var screen failed\n");
close(fd);
return -3;
}
printf("xres = %d, yres = %d\n", varInfo.xres, varInfo.yres);
printf("bits_per_pixel = %d\n", varInfo.bits_per_pixel);
printf("red: offset = %d, length = %d\n", \
varInfo.red.offset, varInfo.red.length);
printf("green: offset = %d, length = %d\n", \
varInfo.green.offset, varInfo.green.length);
printf("blue: offset = %d, length = %d\n", \
varInfo.blue.offset, varInfo.blue.length);
printf("transp: offset = %d, length = %d\n", \
varInfo.transp.offset, varInfo.transp.length);
close(fd);
return 0;
}